mirror of
https://github.com/Tonejs/Tone.js
synced 2025-01-13 20:39:06 +00:00
testing all of the scripts in the readme
This commit is contained in:
parent
23d5d83476
commit
ebd84be80b
4 changed files with 158 additions and 0 deletions
|
@ -52,6 +52,7 @@ jobs:
|
|||
script:
|
||||
- npm run build
|
||||
- npm run test:html
|
||||
- npm run test:readme
|
||||
env : TEST_HTML=1
|
||||
- stage: deploy
|
||||
os: linux
|
||||
|
|
97
package-lock.json
generated
97
package-lock.json
generated
|
@ -9674,6 +9674,103 @@
|
|||
"rechoir": "^0.6.2"
|
||||
}
|
||||
},
|
||||
"showdown": {
|
||||
"version": "1.9.1",
|
||||
"resolved": "https://registry.npmjs.org/showdown/-/showdown-1.9.1.tgz",
|
||||
"integrity": "sha512-9cGuS382HcvExtf5AHk7Cb4pAeQQ+h0eTr33V1mu+crYWV4KvWAw6el92bDrqGEk5d46Ai/fhbEUwqJ/mTCNEA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"yargs": "^14.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"ansi-regex": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz",
|
||||
"integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==",
|
||||
"dev": true
|
||||
},
|
||||
"ansi-styles": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
|
||||
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"color-convert": "^1.9.0"
|
||||
}
|
||||
},
|
||||
"cliui": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz",
|
||||
"integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"string-width": "^3.1.0",
|
||||
"strip-ansi": "^5.2.0",
|
||||
"wrap-ansi": "^5.1.0"
|
||||
}
|
||||
},
|
||||
"string-width": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz",
|
||||
"integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"emoji-regex": "^7.0.1",
|
||||
"is-fullwidth-code-point": "^2.0.0",
|
||||
"strip-ansi": "^5.1.0"
|
||||
}
|
||||
},
|
||||
"strip-ansi": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz",
|
||||
"integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ansi-regex": "^4.1.0"
|
||||
}
|
||||
},
|
||||
"wrap-ansi": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz",
|
||||
"integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ansi-styles": "^3.2.0",
|
||||
"string-width": "^3.0.0",
|
||||
"strip-ansi": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"yargs": {
|
||||
"version": "14.2.3",
|
||||
"resolved": "https://registry.npmjs.org/yargs/-/yargs-14.2.3.tgz",
|
||||
"integrity": "sha512-ZbotRWhF+lkjijC/VhmOT9wSgyBQ7+zr13+YLkhfsSiTriYsMzkTUFP18pFhWwBeMa5gUc1MzbhrO6/VB7c9Xg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"cliui": "^5.0.0",
|
||||
"decamelize": "^1.2.0",
|
||||
"find-up": "^3.0.0",
|
||||
"get-caller-file": "^2.0.1",
|
||||
"require-directory": "^2.1.1",
|
||||
"require-main-filename": "^2.0.0",
|
||||
"set-blocking": "^2.0.0",
|
||||
"string-width": "^3.0.0",
|
||||
"which-module": "^2.0.0",
|
||||
"y18n": "^4.0.0",
|
||||
"yargs-parser": "^15.0.1"
|
||||
}
|
||||
},
|
||||
"yargs-parser": {
|
||||
"version": "15.0.1",
|
||||
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-15.0.1.tgz",
|
||||
"integrity": "sha512-0OAMV2mAZQrs3FkNpDQcBk1x5HXb8X4twADss4S0Iuk+2dGnLOE/fRHrsYm542GduMveyA77OF4wrNJuanRCWw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"camelcase": "^5.0.0",
|
||||
"decamelize": "^1.2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"signal-exit": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
"test:examples": "node ./test/scripts/test_examples",
|
||||
"test:html": "node ./test/scripts/test_html",
|
||||
"test:node": "node ./test/scripts/node_test.js",
|
||||
"test:readme": "node ./test/scripts/test_readme.js",
|
||||
"test:travis": "npm run build && npm run lint && npm run test",
|
||||
"test:watch": "npm run collect:tests && npm run karma:watch",
|
||||
"ts:build": "tsc --project ./scripts/tsconfig.build.json",
|
||||
|
@ -88,6 +89,7 @@
|
|||
"karma-typescript": "^5.0.0",
|
||||
"mocha": "^7.1.1",
|
||||
"semver": "^5.5.0",
|
||||
"showdown": "^1.9.1",
|
||||
"teoria": "^2.5.0",
|
||||
"tmp-promise": "^2.0.2",
|
||||
"ts-loader": "^7.0.1",
|
||||
|
|
58
test/scripts/test_readme.js
Normal file
58
test/scripts/test_readme.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* eslint-disable no-console */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const { JSDOM } = require("jsdom");
|
||||
const { resolve } = require("path");
|
||||
const { readFile, writeFile } = require("fs-extra");
|
||||
const { exec } = require("child_process");
|
||||
const { file } = require("tmp-promise");
|
||||
const { Converter } = require("showdown");
|
||||
|
||||
/**
|
||||
* A promise version of exec
|
||||
*/
|
||||
function execPromise(cmd) {
|
||||
return new Promise((done, error) => {
|
||||
exec(cmd, (e, output) => {
|
||||
if (e) {
|
||||
error(output);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function testExampleString(str) {
|
||||
// str = str.replace("from \"tone\"", `from "${resolve(__dirname, "../../")}"`);
|
||||
str = `
|
||||
import * as Tone from "${resolve(__dirname, "../../")}"
|
||||
${str}
|
||||
`;
|
||||
const { path, cleanup } = await file({ postfix: ".ts" });
|
||||
// work with file here in fd
|
||||
await writeFile(path, str);
|
||||
try {
|
||||
await execPromise(`tsc --noEmit --target es5 --lib dom,ES2015 ${path}`);
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const readme = (await readFile(resolve(__dirname, "../../README.md"))).toString();
|
||||
const html = new Converter().makeHtml(readme);
|
||||
const dom = new JSDOM(html);
|
||||
const scripts = dom.window.document.querySelectorAll("code.javascript");
|
||||
for (let i = 0; i < scripts.length; i++) {
|
||||
try {
|
||||
await testExampleString(scripts[i].textContent);
|
||||
process.stdout.write(".");
|
||||
} catch (e) {
|
||||
console.log("\nfailed", scripts[i].textContent);
|
||||
console.log(e);
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
console.log("\n");
|
||||
}
|
||||
main();
|
Loading…
Reference in a new issue