-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathvexml.test.ts
More file actions
116 lines (102 loc) · 4.23 KB
/
vexml.test.ts
File metadata and controls
116 lines (102 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { Page } from 'puppeteer';
import * as path from 'path';
import * as fs from 'fs';
import { setup, getSnapshotIdentifier } from './helpers';
import * as vexml from '@/index';
type TestCase = {
filename: string;
width: number;
};
type ContinuationCase = {
filename: string;
/** Score WIDTH config (must be set; PanoramicFormatter does not support continuation). */
width: number;
continuationThreshold: number | null;
};
const DATA_DIR = path.resolve(__dirname, '..', '__data__', 'vexml');
describe('vexml', () => {
let page: Page;
beforeAll(async () => {
page = await (globalThis as any).__BROWSER_GLOBAL__.newPage();
});
afterAll(async () => {
await page.close();
});
it.each<TestCase>([
{ filename: 'multi_system_spanners.musicxml', width: 400 },
{ filename: 'multi_stave_single_part_formatting.musicxml', width: 900 },
{ filename: 'multi_part_formatting.musicxml', width: 900 },
{ filename: 'complex_formatting.musicxml', width: 900 },
{ filename: 'prelude_no_1_snippet.musicxml', width: 900 },
{ filename: 'tabs_basic.musicxml', width: 900 },
{ filename: 'tabs_with_stave.musicxml', width: 900 },
{ filename: 'tabs_slurs.musicxml', width: 900 },
{ filename: 'tabs_natural_harmonics.musicxml', width: 900 },
{ filename: 'tabs_slides.musicxml', width: 900 },
{ filename: 'tabs_taps.musicxml', width: 900 },
{ filename: 'tabs_dead_notes.musicxml', width: 900 },
{ filename: 'tabs_multi_voice.musicxml', width: 900 },
{ filename: 'tabs_grace_notes.musicxml', width: 900 },
{ filename: 'tabs_stroke_direction.musicxml', width: 900 },
{ filename: 'tabs_ties.musicxml', width: 900 },
{ filename: 'tabs_vibrato.musicxml', width: 900 },
{ filename: 'tabs_bends.musicxml', width: 900 },
{ filename: 'chord_symbols.musicxml', width: 900 },
{ filename: 'empty_first_measure.musicxml', width: 900 },
])(`$filename ($width px)`, async (t) => {
const { document, vexmlDiv, screenshotElementSelector } = setup();
const buffer = fs.readFileSync(path.join(DATA_DIR, t.filename));
const musicXML = buffer.toString();
vexml.renderMusicXML(musicXML, vexmlDiv, { config: { WIDTH: t.width } });
await page.setViewport({
width: t.width,
// height doesn't matter since we screenshot the element, not the page.
height: 0,
});
await page.setContent(document.documentElement.outerHTML);
const element = await page.$(screenshotElementSelector);
const screenshot = Buffer.from((await element!.screenshot()) as any);
expect(screenshot).toMatchImageSnapshot({
customSnapshotIdentifier: getSnapshotIdentifier({ filename: t.filename, width: t.width }),
});
});
it.each<ContinuationCase>([
// Baseline: feature disabled — should match the un-fragmented rendering.
{
filename: 'continuation_measures_basic.musicxml',
width: 1200,
continuationThreshold: null,
},
// Narrow system width → eligible measures fragment across multiple systems.
{
filename: 'continuation_measures_basic.musicxml',
width: 400,
continuationThreshold: 250,
},
// Very narrow viewport → a single wide measure spans more than 2 systems (>=3 pieces).
{
filename: 'continuation_measures_basic.musicxml',
width: 300,
continuationThreshold: 120,
},
])(`continuation: $filename (width=$width, threshold=$continuationThreshold)`, async (t) => {
const { document, vexmlDiv, screenshotElementSelector } = setup();
const buffer = fs.readFileSync(path.join(DATA_DIR, t.filename));
const musicXML = buffer.toString();
vexml.renderMusicXML(musicXML, vexmlDiv, {
config: {
WIDTH: t.width,
CONTINUATION_MEASURE_WIDTH_THRESHOLD: t.continuationThreshold,
},
});
await page.setViewport({ width: t.width, height: 0 });
await page.setContent(document.documentElement.outerHTML);
const element = await page.$(screenshotElementSelector);
const screenshot = Buffer.from((await element!.screenshot()) as any);
expect(screenshot).toMatchImageSnapshot({
customSnapshotIdentifier: `continuation_${path.basename(t.filename, path.extname(t.filename))}_w${t.width}_t${
t.continuationThreshold ?? 'null'
}`,
});
});
});