UNPKG

satie

Version:

A sheet music renderer for the web

122 lines (121 loc) 5.16 kB
/** * This file is part of Satie music engraver <https://github.com/jnetterf/satie>. * Copyright (C) Joshua Netterfield <joshua.ca> 2015 - present. * * Satie is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * Satie is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Satie. If not, see <http://www.gnu.org/licenses/>. */ "use strict"; /** * @file part of Satie test suite */ var lodash_1 = require("lodash"); var child_process = require("child_process"); var fs = require("fs"); var engine_songImpl_1 = require("../engine_songImpl"); function readFile(file, onEnd) { fs.readFile(file, "utf8", function (err, data) { if (err) { throw err; } onEnd(data); }); } function mkdirp(path) { try { fs.mkdirSync(path); } catch (e) { if (e.code !== "EEXIST") { throw e; } } } describe("Import/export tests", function () { var lilyRoot = "vendor/lilypond-regression"; var lilyFiles = fs.readdirSync(lilyRoot); // needs to be setup before leaving 'describe' lodash_1.forEach(lilyFiles, function (file) { if (file.match(/[0-9]..\.xml$/)) { testFile(lilyRoot, file); } }); var satieRoot = "vendor/satie-regression"; var satieFiles = fs.readdirSync(satieRoot); // needs to be setup before leaving 'describe' lodash_1.forEach(satieFiles, function (file) { if (file.match(/\.xml$/)) { testFile(satieRoot, file); } }); mkdirp("rendertest"); mkdirp("rendertest/out"); function testFile(root, file) { var outname = (root.replace("/", "_").replace("-", "_") + "_" + file.replace("-", "_")) .replace(".xml", ".svg"); it(file, function (done) { readFile(root + "/" + file, function (musicXML) { var song = new engine_songImpl_1.default({ baseSrc: musicXML, onError: done, onLoaded: function () { try { // HACK: Overwrite encoding date to always be the same, so test results don't change overnight. // Note: this is not the correct way of modifying a document -- use patches! song.header.identification.encoding.encodingDate = { day: 1, month: 1, year: 2016, }; // HACK: overwrite UUIDs, so test results don't change every time. // Note: this is not the correct way of modifying a document -- use patches! song.getDocument(null).measures.forEach(function (measure, idx) { measure.uuid = 42 + idx; }); var page1Svg = song.toSVG(); fs.writeFile("rendertest/out/" + outname, page1Svg); if (!process.env.SKIP_DTD_VALIDATION) { var mxmlOut = song.toMusicXML(); var stdout = void 0; var stderr = void 0; var error = void 0; var env = Object.create(process.env); env.XML_CATALOG_FILES = "./vendor/musicxml-dtd/catalog.xml"; fs.writeFile("rendertest/out/" + outname + ".xml", mxmlOut); var proc = child_process.spawnSync("xmllint", ["--valid", "--noout", "--nonet", "-"], { input: mxmlOut, env: env }); stdout = String(proc.stdout); stderr = String(proc.stderr); error = "" + proc.error; if (stdout || stderr) { done(new Error(stderr || stdout || error)); } else { done(); } } else { done(); } } catch (err) { done(err); return; } }, }); song.run(); }); }); } });