Skip to content

Commit

Permalink
Accidental Tests.
Browse files Browse the repository at this point in the history
Move QUMock object into generate_png_images.js to avoid import ordering issue.
Use BoundingBox getters.
  • Loading branch information
ronyeh committed Aug 30, 2021
1 parent 1202c05 commit b01d464
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 65 deletions.
25 changes: 12 additions & 13 deletions tests/accidental_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
//
// Accidental Tests

/* eslint-disable */
// @ts-nocheck

import { VexFlowTests, TestOptions } from './vexflow_test_helpers';
import { Flow } from 'flow';
import { Accidental } from 'accidental';
import { Beam } from 'beam';
import { Factory } from 'factory';
import { Formatter } from 'formatter';
import { Modifier } from 'modifier';
import { ModifierContext } from 'modifiercontext';
import { Stave } from 'stave';
import { StaveNote } from 'stavenote';
import { StaveNote, StaveNoteStruct } from 'stavenote';
import { Stem } from 'stem';
import { Tickable } from 'tickable';
import { TickContext } from 'tickcontext';
import { TimeSigNote } from 'timesignote';
import { RenderContext } from 'types/common';
import { Voice } from 'voice';

const AccidentalTests = {
Expand Down Expand Up @@ -436,7 +435,7 @@ const AccidentalTests = {
notes.forEach(function (note, index) {
VexFlowTests.plotNoteWidth(f.getContext(), note, 140);
ok(note.getAccidentals().length > 0, 'Note ' + index + ' has accidentals');
note.getAccidentals().forEach(function (accid: any, index: any): void {
note.getAccidentals().forEach((accid: Accidental, index: number) => {
ok(accid.getWidth() > 0, 'Accidental ' + index + ' has set width');
});
});
Expand All @@ -447,7 +446,7 @@ const AccidentalTests = {
ok(true, 'Microtonal Accidental');
},

microtonal_iranian(options: TestOptions) {
microtonal_iranian(options: TestOptions): void {
const f = VexFlowTests.makeFactory(options, 700, 240);
const newAccid = makeNewAccid(f);
const ctx = f.getContext();
Expand Down Expand Up @@ -500,7 +499,7 @@ const AccidentalTests = {
notes.forEach(function (note, index) {
VexFlowTests.plotNoteWidth(f.getContext(), note, 140);
ok(note.getAccidentals().length > 0, 'Note ' + index + ' has accidentals');
note.getAccidentals().forEach(function (accid: any, index: any) {
note.getAccidentals().forEach((accid: Accidental, index: number) => {
ok(accid.getWidth() > 0, 'Accidental ' + index + ' has set width');
});
});
Expand Down Expand Up @@ -601,7 +600,7 @@ const AccidentalTests = {
notes.forEach(function (note, index) {
VexFlowTests.plotNoteWidth(f.getContext(), note, 140);
ok(note.getAccidentals().length > 0, 'Note ' + index + ' has accidentals');
note.getAccidentals().forEach(function (accid: any, index: any) {
note.getAccidentals().forEach((accid: Accidental, index: number) => {
ok(accid.getWidth() > 0, 'Accidental ' + index + ' has set width');
});
});
Expand All @@ -616,7 +615,7 @@ const AccidentalTests = {
const f = VexFlowTests.makeFactory(options, 700, 200);
const stave = f.Stave();

const notes: any[] = [
const notes: StaveNote[] = [
{ keys: ['c/4', 'c/5'], duration: '4' },
{ keys: ['c#/4', 'c#/5'], duration: '4' },
{ keys: ['c#/4', 'c#/5'], duration: '4' },
Expand Down Expand Up @@ -838,7 +837,7 @@ const AccidentalTests = {
},

autoAccidentalWorking(): void {
function makeNote(noteStruct: any) {
function makeNote(noteStruct: StaveNoteStruct) {
return new StaveNote(noteStruct);
}

Expand Down Expand Up @@ -928,7 +927,7 @@ const AccidentalTests = {
const f = VexFlowTests.makeFactory(options, 700, 240);
f.Stave({ x: 10, y: 10, width: 550 });

function newAcc(type: any) {
function newAcc(type: string) {
return f.Accidental({ type: type });
}

Expand Down Expand Up @@ -972,7 +971,7 @@ const AccidentalTests = {

notes.forEach(function (n, i) {
ok(n.getAccidentals().length > 0, 'Note ' + i + ' has accidentals');
n.getAccidentals().forEach(function (accid: any, i: any) {
n.getAccidentals().forEach((accid: Accidental, i: number) => {
ok(accid.getWidth() > 0, 'Accidental ' + i + ' has set width');
});
});
Expand All @@ -989,7 +988,7 @@ function hasAccidental(note: StaveNote) {

const makeNewAccid = (factory: any) => (accidType: any) => factory.Accidental({ type: accidType });

function showNotes(note1: any, note2: any, stave: any, ctx: any, x: any): void {
function showNotes(note1: StaveNote, note2: StaveNote, stave: Stave, ctx: RenderContext, x: number): void {
const modifierContext = new ModifierContext();
note1.addToModifierContext(modifierContext);
note2.addToModifierContext(modifierContext);
Expand Down
7 changes: 2 additions & 5 deletions tests/boundingboxcomputation_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
//
// BoundingBoxComputation Tests

/* eslint-disable */
// @ts-nocheck

import { VexFlowTests, TestOptions } from './vexflow_test_helpers';
import { BoundingBoxComputation } from 'boundingboxcomputation';
import { Glyph, OutlineCode } from 'glyph';
Expand Down Expand Up @@ -160,7 +157,7 @@ const BoundingBoxComputationTests = {
// this time using the Glyph.getOutlineBoundingBox code path.
const o = [OutlineCode.MOVE, x0, -y0, OutlineCode.QUADRATIC, x2, -y2, x1, -y1];
const bbox = Glyph.getOutlineBoundingBox(o, 1, 0, 0);
rect(ctx, '#fa0', 1, bbox.x, bbox.y, bbox.w, bbox.h);
rect(ctx, '#fa0', 1, bbox.getX(), bbox.getY(), bbox.getW(), bbox.getH());

// Draw curve.
ctx.setLineWidth(1);
Expand Down Expand Up @@ -210,7 +207,7 @@ const BoundingBoxComputationTests = {
// this time using the Glyph.getOutlineBoundingBox code path.
const o = [OutlineCode.MOVE, x0, -y0, OutlineCode.BEZIER, x3, -y3, x1, -y1, x2, -y2];
const bbox = Glyph.getOutlineBoundingBox(o, 1, 0, 0);
rect(ctx, '#fa0', 1, bbox.x, bbox.y, bbox.w, bbox.h);
rect(ctx, '#fa0', 1, bbox.getX(), bbox.getY(), bbox.getW(), bbox.getH());

// Draw curve.
ctx.setLineWidth(1);
Expand Down
45 changes: 1 addition & 44 deletions tests/vexflow_test_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Font, Fonts } from 'font';
import { Note } from 'note';

/* eslint-disable */
declare var global: any;
declare const global: any;
declare var $: any;
/* eslint-enable */

Expand Down Expand Up @@ -81,49 +81,6 @@ if (!global.$) {
};
}

// When generating PNG images for the visual regression tests,
// we mock out the QUnit methods (since we don't care about assertions).
if (!global.QUnit) {
// eslint-disable-next-line
const QUMock: any = {
assertions: {
ok: () => true,
equal: () => true,
deepEqual: () => true,
expect: () => true,
throws: () => true,
notOk: () => true,
notEqual: () => true,
notDeepEqual: () => true,
strictEqual: () => true,
notStrictEqual: () => true,
propEqual: () => true,
},

module(name: string): void {
QUMock.current_module = name;
},

// See: https://api.qunitjs.com/QUnit/test/
test(name: number, callback: (assert: Assert) => void): void {
QUMock.current_test = name;
QUMock.assertions.test.module.name = name;
VexFlowTests.shims.process.stdout.write(' \u001B[0G' + QUMock.current_module + ' :: ' + name + '\u001B[0K');
callback(QUMock.assertions);
},
};

global.QUnit = QUMock;
for (const k in QUMock.assertions) {
// Make all methods & properties of QUMock.assertions global.
global[k] = QUMock.assertions[k];
}
global.test = QUMock.test;
// Enable us to pass the name of the module around.
// See: QUMock.test(...) and VexFlowTests.runWithParams(...)
QUMock.assertions.test = { module: { name: '' } };
}

export type TestFunction = (options: TestOptions, contextBuilder: ContextBuilder) => void;

/** Allow `name` to be used inside file names. */
Expand Down
48 changes: 45 additions & 3 deletions tools/generate_png_images.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

const { JSDOM } = require('jsdom');
const fs = require('fs');
const { RuntimeError } = require('util');

const dom = new JSDOM(`<!DOCTYPE html><body><div id="vexflow_testoutput"></div></body>`);
global.window = dom.window;
Expand All @@ -28,18 +27,61 @@ if (process.argv.length >= 5) {
}
}

// When generating PNG images for the visual regression tests,
// we mock out the QUnit methods (since we don't care about assertions).
if (!global.QUnit) {
const QUMock = {
assertions: {
ok: () => true,
equal: () => true,
deepEqual: () => true,
expect: () => true,
throws: () => true,
notOk: () => true,
notEqual: () => true,
notDeepEqual: () => true,
strictEqual: () => true,
notStrictEqual: () => true,
propEqual: () => true,
},

module(name) {
QUMock.current_module = name;
},

// See: https://api.qunitjs.com/QUnit/test/
test(name, callback) {
QUMock.current_test = name;
QUMock.assertions.test.module.name = name;
// Print out the progress and keep it on a single line.
process.stdout.write(`\u001B[0G${QUMock.current_module} :: ${name}\u001B[0K`);
callback(QUMock.assertions);
},
};

global.QUnit = QUMock;
for (const k in QUMock.assertions) {
// Make all methods & properties of QUMock.assertions global.
global[k] = QUMock.assertions[k];
}
global.test = QUMock.test;
// Enable us to pass the name of the module around.
// See: QUMock.test(...) and VexFlowTests.runWithParams(...)
QUMock.assertions.test = { module: { name: '' } };
}

if (scriptDir.includes('releases')) {
// THE OLD WAY loads two JS files.
// TODO: Remove this block lines 31-37, after the new version has been moved to 'releases/'
global.Vex = require(`${scriptDir}/vexflow-debug.js`);
require(`${scriptDir}/vexflow-tests.js`);
global.Vex.Flow.shims = { fs, process };
global.Vex.Flow.shims = { fs };
} else {
// THE NEW WAY loads a single JS file.
// See: https://github.com/0xfe/vexflow/pull/1074
// Load from the build/ or reference/ folder.
global.Vex = require(`${scriptDir}/vexflow-tests.js`);
global.Vex.Flow.Test.shims = { fs, process };
global.Vex.Flow.Test.shims = { fs };
}

// Tell VexFlow that we're outside the browser. Just run the Node tests.
Expand Down

0 comments on commit b01d464

Please sign in to comment.