Skip to content

Commit

Permalink
Command line QUnit test uses flow-headless-browser.html instead (it's
Browse files Browse the repository at this point in the history
much simpler).
  • Loading branch information
ronyeh committed Oct 3, 2021
1 parent d76e52a commit d4eaea6
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 91 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ module.exports = (grunt) => {
options: { fix: true },
},
qunit: {
files: ['tests/flow.html'],
files: ['tests/flow-headless-browser.html'],
},
copy: {
release: {
Expand Down
20 changes: 8 additions & 12 deletions src/fonts/legacy/glyphs.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
}

a {
color: #green;
color: green;
text-decoration: none;
border-bottom: dotted 2px;
}

a.button {
color: #green;
color: green;
background: #bfb;
text-decoration: none;
padding: 5px;
Expand Down Expand Up @@ -105,15 +105,11 @@
</head>

<body>
<center>
<h1>Gonville Glyphs</h1>
<p>
<i>Cross indicates render coordinates.</i>
</p>

<canvas id="glyphs" width="800" height="1600"> HTML5 Canvas not supported on this browser. </canvas>

<p>For more information visit <a href="http://0xfe.blogspot.com">0xfe.blogspot.com</a>.</p>
</center>
<h1>Gonville Glyphs</h1>
<p>
<i>Cross indicates render coordinates.</i>
</p>
<canvas id="glyphs" width="800" height="1600"></canvas>
<p>For more information visit <a href="http://0xfe.blogspot.com">0xfe.blogspot.com</a>.</p>
</body>
</html>
12 changes: 12 additions & 0 deletions tests/flow-headless-browser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<body>
<div id="vexflow_testoutput"></div>
<script src="support/qunit.js"></script>
<script src="../build/vexflow-tests.js"></script>
<script>
QUnit.config.noglobals = true;
Vex.Flow.Test.run();
</script>
</body>
</html>
156 changes: 78 additions & 78 deletions tests/flow.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,27 @@
<title>VexFlow - JavaScript Music Notation and Guitar Tab</title>
<link rel="stylesheet" href="flow.css" type="text/css" media="screen" />
<link rel="stylesheet" href="support/qunit.css" type="text/css" media="screen" />
<script src="support/jquery.js"></script>
</head>

<body>
<div style="text-align: center">
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<div>
<h2>[ <a href="http://vexflow.com">Home</a> ] [ <a href="http://github.com/0xfe/vexflow">GitHub</a> ]</h2>
<h3>
See the: <a id="vex-src" target="_blank"></a>. Don't forget to run the
<a href="https://github.com/0xfe/vexflow/wiki/Visual-Regression-Tests">Visual Regression Tests</a>!
</h3>
</div>
<p>&nbsp;</p>
<div id="vexflow_testoutput"></div>
<p>&nbsp;</p>
<p class="vf-footer">
[ <a href="http://vexflow.com">home</a> ] [ <a href="http://github.com/0xfe/vexflow">github</a> ] [
<a href="http://0xfe.muthanna.com">0xfe</a> ]
</p>
</div>
<script>
function loadScript(url) {
return new Promise((resolve, reject) => {
Expand All @@ -19,90 +39,70 @@
});
}

$(function () {
// Support a query param to choose which VexFlow version to load.
// ver=(build|reference|releases|etc...)
// If omitted, ver defaults to 'build'.
var params = new URLSearchParams(window.location.search);
var param_ver = params.get('ver');
// Support a query param to choose which VexFlow version to load.
// ver=(build|reference|releases|etc...)
// If omitted, ver defaults to 'build'.
var params = new URLSearchParams(window.location.search);
var param_ver = params.get('ver');

var vexURL;
var testsURL;
var isCurrentBuild = false;
var vexURL;
var testsURL;
var isCurrentBuild = false;

// ver can also specify a version hosted on unpkg.com:
// [email protected] or [email protected]
// https://unpkg.com/[email protected]/releases/vexflow-debug.js
if (param_ver && param_ver.includes('unpkg')) {
var version = param_ver.split('@')[1];
vexURL = `https://unpkg.com/vexflow@${version}/releases/vexflow-debug.js`;
testsURL = `https://unpkg.com/vexflow@${version}/releases/vexflow-tests.js`;
} else {
var path = param_ver || 'build';
if (path === 'build') {
isCurrentBuild = true;
}
vexURL = '../' + path + '/vexflow-debug.js';
testsURL = '../' + path + '/vexflow-tests.js';
// `ver` can also specify a version hosted on unpkg.com:
// [email protected] or [email protected]
// https://unpkg.com/[email protected]/releases/vexflow-debug.js
if (param_ver && param_ver.includes('unpkg')) {
var version = param_ver.split('@')[1];
vexURL = `https://unpkg.com/vexflow@${version}/releases/vexflow-debug.js`;
testsURL = `https://unpkg.com/vexflow@${version}/releases/vexflow-tests.js`;
} else {
var path = param_ver || 'build';
if (path === 'build') {
isCurrentBuild = true;
}
vexURL = '../' + path + '/vexflow-debug.js';
testsURL = '../' + path + '/vexflow-tests.js';
}

// Display which VexFlow version we loaded, if the `ver` param was specified.
var info = param_ver !== null ? ` [${param_ver}]` : '';
$('#vex-src')
.attr('href', vexURL)
.text('VexFlow Source' + info);
// Display which VexFlow version we loaded, if the `ver` param was specified.
var info = param_ver !== null ? ` [${param_ver}]` : '';
const srcLink = document.getElementById('vex-src');
srcLink.href = vexURL;
srcLink.innerText = 'VexFlow Source' + info;

// When loading the current version, only load vexflow-tests.js
// When loading old versions, load both vexflow-debug.js and vexflow-tests.js
let loadVexFlowTests;
if (isCurrentBuild) {
loadVexFlowTests = () => loadScript(testsURL);
} else {
loadVexFlowTests = () => loadScript(vexURL).then(() => loadScript(testsURL));
}
let loadVexFlow;
if (isCurrentBuild) {
// When loading version >= 4.0.0, only load vexflow-tests.js
loadVexFlow = () => loadScript(testsURL);
} else {
// When loading versions <= 3.0.9, load both vexflow-debug.js and vexflow-tests.js
loadVexFlow = () => loadScript(vexURL).then(() => loadScript(testsURL));
}

const fontServer = 'https://unpkg.com/[email protected]/';
const getFontURLs = (pathToWoff) =>
`url(${fontServer}${pathToWoff}2) format('woff2'), url(${fontServer}${pathToWoff}) format('woff')`;
const robotoFont = new FontFace('Roboto Slab', getFontURLs('robotoslab/RobotoSlab-Medium_2.001.woff'));
const petalumaFont = new FontFace('PetalumaScript', getFontURLs('petaluma/PetalumaScript_1.10.woff'));
// Load web fonts before running the tests.
const host = 'https://unpkg.com/[email protected]/';
const srcURLs = (path) => `url(${host}${path}2) format('woff2'), url(${host}${path}) format('woff')`;
const robotoFont = new FontFace('Roboto Slab', srcURLs('robotoslab/RobotoSlab-Medium_2.001.woff'));
const petalumaFont = new FontFace('PetalumaScript', srcURLs('petaluma/PetalumaScript_1.10.woff'));

loadVexFlowTests()
.then(() => robotoFont.load())
.then(() => petalumaFont.load())
.then(() => {
document.fonts.add(robotoFont);
document.fonts.add(petalumaFont);
})
.then(() => loadScript('support/qunit.js'))
.then(() => {
// Show only failed tests.
QUnit.config.hidepassed = true;
QUnit.config.noglobals = true;
Vex.Flow.Test.run();
});
});
loadVexFlow()
.then(() => robotoFont.load())
.then(() => petalumaFont.load())
.then(() => {
document.fonts.add(robotoFont);
document.fonts.add(petalumaFont);
})
// Load qunit.js as late as possible to avoid a race condition
// where the QUnit module drop down box doesn't appear if
// Vex.Flow.Test.run() happens too late,
.then(() => loadScript('support/qunit.js'))
.then(() => {
// Show only failed tests.
QUnit.config.hidepassed = true;
QUnit.config.noglobals = true;
Vex.Flow.Test.run();
});
</script>
</head>

<body>
<div style="text-align: center">
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<div>
<h2>[ <a href="http://vexflow.com">Home</a> ] [ <a href="http://github.com/0xfe/vexflow">GitHub</a> ]</h2>
<h3>
See the: <a id="vex-src" target="_blank"></a>. Don't forget to run the
<a href="https://github.com/0xfe/vexflow/wiki/Visual-Regression-Tests">Visual Regression Tests</a>!
</h3>
</div>
<p>&nbsp;</p>
<div id="vexflow_testoutput"></div>
<p>&nbsp;</p>
<p class="vf-footer">
[ <a href="http://vexflow.com">home</a> ] [ <a href="http://github.com/0xfe/vexflow">github</a> ] [
<a href="http://0xfe.muthanna.com">0xfe</a> ]
</p>
</div>
</body>
</html>

0 comments on commit d4eaea6

Please sign in to comment.