Skip to content

Commit

Permalink
Generage PNG images will include both JS files if the src path is
Browse files Browse the repository at this point in the history
releases/ or reference/. It will do it the new way (single JS file)
if the src path is build/.
  • Loading branch information
ronyeh committed Jul 27, 2021
1 parent 367fa05 commit eafd796
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion tests/rests_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ const RestsTests = {
const beam2_1 = new VF.Beam(notes2.slice(0, 4));
const beam2_2 = new VF.Beam(notes2.slice(4, 8));

// Note: we need to draw voice2 first, since voice2 generates ledger lines.
// Important Note: we need to draw voice2 first, since voice2 generates ledger lines.
// Otherwise, the ledger lines will be drawn on top of middle C notes in voice1.
voice2.draw(ctx);
voice1.draw(ctx);
Expand Down
6 changes: 6 additions & 0 deletions tests/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ import { BachDemoTests } from './bach_tests';
import { GlyphNoteTests } from './glyphnote_tests';

VexFlowTests.run = function () {
/*
AccidentalTests.Start();
StaveNoteTests.Start();
VoiceTests.Start();
*/
// NoteHeadTests.Start();
// TabNoteTests.Start();
// TickContextTests.Start();
Expand Down Expand Up @@ -108,8 +110,10 @@ VexFlowTests.run = function () {
// BoundingBoxTests.Start();
// StrokesTests.Start();
StringNumberTests.Start();
/*
RestsTests.Start();
ThreeVoicesTests.Start();
*/
// CurveTests.Start();
// TextNoteTests.Start();
// StaveLineTests.Start();
Expand All @@ -120,10 +124,12 @@ VexFlowTests.run = function () {
// GhostNoteTests.Start();
// StyleTests.Start();
// FactoryTests.Start();
/*
ParserTests.Start();
EasyScoreTests.Start();
RegistryTests.Start();
BachDemoTests.Start();
*/
// GlyphNoteTests.Start();
};

Expand Down
4 changes: 3 additions & 1 deletion tests/stringnumber_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ const StringNumberTests = (function () {
// Position string number 6 beneath the strum arrow: left (15) and down (18)
notes2[4].addModifier(vf.StringNumber({ number: '6', position: 'left' }).setOffsetX(15).setOffsetY(18), 0);

const voices = [notes1, notes2].map(score.voice.bind(score));
// Important Note: notes2 must come first, otherwise ledger lines from notes2 will be drawn on top of notes from notes1!
// BUG: VexFlow draws TWO ledger lines for middle C, because both notes1 and notes2 require the middle C ledger line.
const voices = [notes2, notes1].map(score.voice.bind(score));

vf.Formatter().joinVoices(voices).formatToStave(voices, stave);

Expand Down
40 changes: 20 additions & 20 deletions tools/generate_png_images.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
`tools/visual_regression.sh`.
*/
const { JSDOM } = require('jsdom');
const fs = require('fs');

const dom = new JSDOM(`<!DOCTYPE html><body><div id="vexflow_testoutput"></div></body>`);
window = dom.window;
document = dom.window.document;
global.window = dom.window;
global.document = dom.window.document;

const fs = require('fs');
const [scriptDir, imageDir] = process.argv.slice(2, 4);

// Optional: 3rd argument specifies which font stacks to test. Defaults to all.
Expand All @@ -27,30 +28,29 @@ if (process.argv.length >= 5) {
}
}

// TODO: Need a flag to determine whether to load BOTH JS files, or only one JS file.

// THE OLD WAY
// global['Vex'] = require(`${scriptDir}/vexflow-debug.js`);
// require(`${scriptDir}/vexflow-tests.js`);

// THE NEW WAY
global['Vex'] = require(`${scriptDir}/vexflow-tests.js`);
if (scriptDir.includes('build')) {
// THE NEW WAY loads a single JS file.
global.Vex = require(`${scriptDir}/vexflow-tests.js`);
} else {
// THE OLD WAY loads two JS files.
global.Vex = require(`${scriptDir}/vexflow-debug.js`);
require(`${scriptDir}/vexflow-tests.js`);
}

const VF = Vex.Flow;
VF.shims = {
Vex.Flow.shims = {
fs,
process,
};

// Tell VexFlow that we're outside the browser. Just run the Node tests.
VF.Test.RUN_CANVAS_TESTS = false;
VF.Test.RUN_SVG_TESTS = false;
VF.Test.RUN_NODE_TESTS = true;
VF.Test.NODE_IMAGEDIR = imageDir;
VF.Test.NODE_FONT_STACKS = fontStacksToTest;
Vex.Flow.Test.RUN_CANVAS_TESTS = false;
Vex.Flow.Test.RUN_SVG_TESTS = false;
Vex.Flow.Test.RUN_NODE_TESTS = true;
Vex.Flow.Test.NODE_IMAGEDIR = imageDir;
Vex.Flow.Test.NODE_FONT_STACKS = fontStacksToTest;

// Create the image directory if it doesn't exist.
fs.mkdirSync(VF.Test.NODE_IMAGEDIR, { recursive: true });
fs.mkdirSync(Vex.Flow.Test.NODE_IMAGEDIR, { recursive: true });

// Run all tests.
VF.Test.run();
Vex.Flow.Test.run();

0 comments on commit eafd796

Please sign in to comment.