mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-27 03:53:07 +00:00
reorganising testing directory
This commit is contained in:
parent
3068ab1cc8
commit
472afc7d1d
12 changed files with 21 additions and 251 deletions
16
package.json
16
package.json
|
@ -15,26 +15,22 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm run increment-ts && rm -rf build && npm run ts:build && npm run webpack:build",
|
"build": "npm run increment-ts && rm -rf build && npm run ts:build && npm run webpack:build",
|
||||||
"codecov": "codecov",
|
"codecov": "codecov",
|
||||||
"collect": "npm run collect:deps",
|
|
||||||
"collect:deps": "node scripts/collect_deps.js",
|
|
||||||
"collect:tests": "cross-var node scripts/collect_tests.js --file $npm_config_file --dir $npm_config_dir",
|
|
||||||
"docs": "node scripts/generate_docs.js",
|
"docs": "node scripts/generate_docs.js",
|
||||||
"docs:json": "cross-var typedoc --options \"./scripts/typedoc.json\" --json \"$npm_config_docs_json\"",
|
"docs:json": "cross-var typedoc --options \"./scripts/typedoc.json\" --json \"$npm_config_docs_json\"",
|
||||||
"increment": "node scripts/increment_version.js",
|
"increment": "node scripts/increment_version.js",
|
||||||
"increment-ts": "node scripts/increment_version_ts.js",
|
"increment-ts": "node scripts/increment_version_ts.js",
|
||||||
"karma": "cross-var karma start scripts/karma.conf.js --single-run --file $npm_config_file --dir $npm_config_dir",
|
"karma": "cross-var karma start ./test/karma.conf.js --single-run --file $npm_config_file --dir $npm_config_dir",
|
||||||
"karma:browser": "cross-var karma start scripts/karma.conf.js --auto-watch --browsers OnlineChrome --file $npm_config_file --dir $npm_config_dir",
|
"karma:browser": "cross-var karma start ./test/karma.conf.js --auto-watch --browsers OnlineChrome --file $npm_config_file --dir $npm_config_dir",
|
||||||
"karma:watch": "cross-var karma start scripts/karma.conf.js --auto-watch --file $npm_config_file --dir $npm_config_dir",
|
"karma:watch": "cross-var karma start ./test/karma.conf.js --auto-watch --file $npm_config_file --dir $npm_config_dir",
|
||||||
"lint": "eslint --ignore-pattern ./Tone/**/*.test.ts --ext ts ./Tone",
|
"lint": "eslint --ignore-pattern ./Tone/**/*.test.ts --ext ts ./Tone",
|
||||||
"lint:fix": "eslint --ext ts --fix ./Tone",
|
"lint:fix": "eslint --ext ts --fix ./Tone",
|
||||||
"scratch": "webpack -w --env.scratch --mode=development",
|
"scratch": "webpack -w --env.scratch --mode=development",
|
||||||
"test": "npm run karma",
|
"test": "npm run karma",
|
||||||
"test:watch": "npm run collect:tests && npm run karma:watch",
|
|
||||||
"test:browser": "npm run karma:browser",
|
"test:browser": "npm run karma:browser",
|
||||||
|
"test:examples": "node ./test/scripts/test_examples",
|
||||||
|
"test:node": "node ./test/scripts/node_test.js",
|
||||||
"test:travis": "npm run build && npm run lint && npm run test",
|
"test:travis": "npm run build && npm run lint && npm run test",
|
||||||
"test:examples": "node scripts/test_examples",
|
"test:watch": "npm run collect:tests && npm run karma:watch",
|
||||||
"test:html": "mocha ./test/html/testHTML.js --timeout 30000",
|
|
||||||
"test:node": "node ./test/html/node_test.js",
|
|
||||||
"ts:build": "tsc --project ./scripts/tsconfig.build.json",
|
"ts:build": "tsc --project ./scripts/tsconfig.build.json",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"webpack:watch": "webpack -w --env.production --mode=development",
|
"webpack:watch": "webpack -w --env.production --mode=development",
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
const glob = require("glob");
|
|
||||||
const { posix } = require("path");
|
|
||||||
const fs = require("fs");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* COLLECT DEPENDENCIES
|
|
||||||
*/
|
|
||||||
function collectDependencies(){
|
|
||||||
const files = glob.sync(posix.resolve(__dirname, "../Tone/!(shim)/!(Tone).js"));
|
|
||||||
const modules = files.map(f => f.slice(0, -3));
|
|
||||||
let reqString = modules.map(r => {
|
|
||||||
const relativePath = posix.relative(posix.resolve(__dirname, "../Tone"), r);
|
|
||||||
// const exportName = r.split("/")[r.split("/").length - 1];
|
|
||||||
// return `export { default as ${exportName} } from "./${relativePath}";`;
|
|
||||||
// return `import "./${relativePath}";`;
|
|
||||||
return `require("./${relativePath}");`;
|
|
||||||
}).join("\n");
|
|
||||||
// reqString += "\nexport { default } from \"./core/Tone\";\n";
|
|
||||||
reqString += "\nmodule.exports = require(\"./core/Tone\").default;\n";
|
|
||||||
fs.writeFileSync(posix.resolve(__dirname, "../Tone/index.js"), reqString);
|
|
||||||
}
|
|
||||||
|
|
||||||
collectDependencies();
|
|
|
@ -1,24 +0,0 @@
|
||||||
const glob = require("glob");
|
|
||||||
const fs = require("fs");
|
|
||||||
const { posix } = require("path");
|
|
||||||
const argv = require("yargs")
|
|
||||||
.alias("i", "file")
|
|
||||||
.alias("d", "dir")
|
|
||||||
.argv;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* COLLECT TESTS
|
|
||||||
*/
|
|
||||||
function collectTests(){
|
|
||||||
var tests = "../test/!(helper|deps|examples|html)/*.js";
|
|
||||||
if (typeof argv.file === "string"){
|
|
||||||
tests = `../test/*/${argv.file}.js`;
|
|
||||||
} else if (typeof argv.dir === "string"){
|
|
||||||
tests = `../test/${argv.dir}/*.js`;
|
|
||||||
}
|
|
||||||
const files = glob.sync(posix.resolve(__dirname, tests));
|
|
||||||
var reqString = files.map(r => `import "${r}";`).join("\n");
|
|
||||||
fs.writeFileSync(posix.resolve(__dirname, "../test/test.js"), reqString);
|
|
||||||
}
|
|
||||||
|
|
||||||
collectTests();
|
|
|
@ -1,36 +0,0 @@
|
||||||
const fs = require("fs");
|
|
||||||
const semver = require("semver");
|
|
||||||
const { resolve } = require("path");
|
|
||||||
const child_process = require("child_process");
|
|
||||||
|
|
||||||
const devVersion = child_process.execSync("npm show tone@next version").toString();
|
|
||||||
const masterVersion = child_process.execSync("npm show tone version").toString();
|
|
||||||
|
|
||||||
//go with whichever is the latest version
|
|
||||||
let version = masterVersion;
|
|
||||||
if (semver.gt(devVersion, masterVersion)){
|
|
||||||
version = devVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
//increment the patch
|
|
||||||
version = semver.inc(version, "patch");
|
|
||||||
|
|
||||||
//write it to the package.json
|
|
||||||
const packageFile = resolve(__dirname, "../package.json");
|
|
||||||
const packageObj = JSON.parse(fs.readFileSync(packageFile, "utf-8"));
|
|
||||||
|
|
||||||
//if the package version if the latest, go with that one
|
|
||||||
if (semver.gt(packageObj.version, version)){
|
|
||||||
version = packageObj.version;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`incrementing to version ${version}`);
|
|
||||||
packageObj.version = version;
|
|
||||||
//only if it's travis, update the package.json
|
|
||||||
if (process.env.TRAVIS){
|
|
||||||
fs.writeFileSync(packageFile, JSON.stringify(packageObj, undefined, " "));
|
|
||||||
|
|
||||||
//write a version file
|
|
||||||
var versionFile = `export default ${JSON.stringify(version)};\n`;
|
|
||||||
fs.writeFileSync(resolve(__dirname, "../Tone/version.js"), versionFile);
|
|
||||||
}
|
|
|
@ -1,37 +1,39 @@
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const semver = require("semver");
|
const semver = require("semver");
|
||||||
const { resolve } = require("path");
|
const { resolve } = require("path");
|
||||||
const child_process = require("child_process");
|
const { execSync } = require("child_process");
|
||||||
|
|
||||||
const tsVersion = child_process.execSync("npm show tone@typescript version").toString();
|
const tsVersion = execSync("npm show tone@typescript version").toString();
|
||||||
const masterVersion = child_process.execSync("npm show tone version").toString();
|
const masterVersion = execSync("npm show tone version").toString();
|
||||||
|
|
||||||
//go with whichever is the latest version
|
// go with whichever is the latest version
|
||||||
let version = masterVersion;
|
let version = masterVersion;
|
||||||
if (tsVersion && semver.gt(tsVersion, masterVersion)){
|
if (tsVersion && semver.gt(tsVersion, masterVersion)) {
|
||||||
version = tsVersion;
|
version = tsVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
//increment the patch
|
// increment the patch
|
||||||
version = semver.inc(version, "patch");
|
version = semver.inc(version, "patch");
|
||||||
|
|
||||||
//write it to the package.json
|
// write it to the package.json
|
||||||
const packageFile = resolve(__dirname, "../package.json");
|
const packageFile = resolve(__dirname, "../package.json");
|
||||||
const packageObj = JSON.parse(fs.readFileSync(packageFile, "utf-8"));
|
const packageObj = JSON.parse(fs.readFileSync(packageFile, "utf-8"));
|
||||||
|
|
||||||
//if the package version if the latest, go with that one
|
// if the package version if the latest, go with that one
|
||||||
if (semver.gt(packageObj.version, version)){
|
if (semver.gt(packageObj.version, version)) {
|
||||||
version = packageObj.version;
|
version = packageObj.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`incrementing to version ${version}`);
|
console.log(`incrementing to version ${version}`);
|
||||||
packageObj.version = version;
|
packageObj.version = version;
|
||||||
//only if it's travis, update the package.json
|
// only if it's travis, update the package.json
|
||||||
if (process.env.TRAVIS){
|
if (process.env.TRAVIS) {
|
||||||
fs.writeFileSync(packageFile, JSON.stringify(packageObj, undefined, " "));
|
fs.writeFileSync(packageFile, JSON.stringify(packageObj, undefined, " "));
|
||||||
|
|
||||||
//write a version file
|
// write a version file
|
||||||
var versionFile = `export const version: string = ${JSON.stringify(version)};\n`;
|
let versionFile = `export const version: string = ${JSON.stringify(version)};\n`;
|
||||||
fs.writeFileSync(resolve(__dirname, "../Tone/version.ts"), versionFile);
|
fs.writeFileSync(resolve(__dirname, "../Tone/version.ts"), versionFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>TWO CONTEXTS RUNNING AT ONCE</title>
|
|
||||||
<script src="../../build/Tone.js"></script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
|
|
||||||
function assert(statement, error){
|
|
||||||
if (!statement){
|
|
||||||
throw new Error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Tone && Tone.context){
|
|
||||||
Tone.context.thisisthesamecontext = true;
|
|
||||||
assert(window.TONE_AUDIO_CONTEXT.thisisthesamecontext, "Did not assign global TONE_AUDIO_CONTEXT");
|
|
||||||
} else {
|
|
||||||
throw new Error("NO TONE!");
|
|
||||||
}
|
|
||||||
|
|
||||||
var instanceOne = Tone;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script src="../../build/Tone.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
if (Tone && Tone.context){
|
|
||||||
assert(window.TONE_AUDIO_CONTEXT === Tone.context, "Did not assign global TONE_AUDIO_CONTEXT 2");
|
|
||||||
assert(Tone.context.thisisthesamecontext, "Not the same AudioContext");
|
|
||||||
} else {
|
|
||||||
throw new Error("NO TONE 2!");
|
|
||||||
}
|
|
||||||
|
|
||||||
var instanceTwo = Tone;
|
|
||||||
|
|
||||||
//additional checks
|
|
||||||
assert(instanceOne !== instanceTwo, "Did not create two instances");
|
|
||||||
assert(instanceOne.context === instanceTwo.context, "Instances don't share the same Tone.Context");
|
|
||||||
assert(instanceOne.context.rawContext === instanceTwo.context.rawContext, "Instances don't share the same AudioContext");
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,26 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>SAME TRANSPORT</title>
|
|
||||||
<script src="../../build/Tone.js"></script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script>
|
|
||||||
|
|
||||||
function assert(statement, error){
|
|
||||||
if (!statement){
|
|
||||||
throw new Error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Tone){
|
|
||||||
var Transport = Tone.Transport;
|
|
||||||
Tone.Offline(function(){}, 0.1).then(function(){});
|
|
||||||
assert(Tone.Transport === Transport, "Different Transports!");
|
|
||||||
} else {
|
|
||||||
throw new Error("NO TONE!");
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,57 +0,0 @@
|
||||||
const puppeteer = require("puppeteer");
|
|
||||||
const { resolve } = require("path");
|
|
||||||
const fs = require("fs");
|
|
||||||
const { spawn } = require("child_process");
|
|
||||||
|
|
||||||
function runPage(name){
|
|
||||||
return new Promise(async (done, error) => {
|
|
||||||
const browser = await puppeteer.launch({ args : ["--no-sandbox"] });
|
|
||||||
const page = await browser.newPage();
|
|
||||||
page.on("pageerror", e => error(e));
|
|
||||||
await page.goto(`http://localhost:9999/examples/${name}`, { waitFor : "networkidle0" });
|
|
||||||
await browser.close();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("TEST", () => {
|
|
||||||
|
|
||||||
let serverProcess = null;
|
|
||||||
|
|
||||||
before((done) => {
|
|
||||||
const serverCommand = resolve(__dirname, "../../node_modules/.bin/http-server");
|
|
||||||
serverProcess = spawn(serverCommand, ["-p", "9999"]);
|
|
||||||
//give it a second for the server to start
|
|
||||||
setTimeout(() => done(), 1000);
|
|
||||||
});
|
|
||||||
|
|
||||||
after(() => {
|
|
||||||
serverProcess.kill();
|
|
||||||
});
|
|
||||||
|
|
||||||
context("HTML Tests", () => {
|
|
||||||
|
|
||||||
it("can run multiple contexts at once", () => {
|
|
||||||
return runPage("../test/html/multiple_instances.html");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("has the same transport after offline test", () => {
|
|
||||||
return runPage("../test/html/same_transport.html");
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
context("Examples", () => {
|
|
||||||
|
|
||||||
const exampleDir = resolve(__dirname, "../../examples/");
|
|
||||||
|
|
||||||
const files = fs.readdirSync(exampleDir).filter(f => f.endsWith(".html"));
|
|
||||||
|
|
||||||
files.forEach(f => {
|
|
||||||
it(`can run example ${f}`, () => {
|
|
||||||
return runPage(f);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>TESTS</title>
|
|
||||||
<script src="../node_modules/mocha/mocha.js"></script>
|
|
||||||
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="mocha"></div>
|
|
||||||
<script type="text/javascript">
|
|
||||||
setTimeout(() => {
|
|
||||||
mocha.run()
|
|
||||||
}, 100)
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
Reference in a new issue