Give tests the ability to inject non-module scripts into the test page

This commit is contained in:
Timothy Farrell 2018-06-30 14:09:19 -05:00
parent 7f1a3faa54
commit 10dd03a48c

View File

@ -40,15 +40,22 @@ runTestsInChrome();
// ----------------------
function writeSpecRunner() {
if (items.indexOf(SPEC_DIR) === -1) {
let settings = {};
try {
settings = JSON.parse(fs.readFileSync(path.join(packageRoot, 'test.json'), 'utf8'));
} catch (e) {}
const spec_dir = settings.spec_dir || SPEC_DIR;
if (items.indexOf(spec_dir) === -1) {
console.log(`ERROR: ${packageRoot} does not contain a "${SPEC_DIR}" folder.`);
process.exit(-1);
}
const scripts = settings.lib_files || [];
const specFilenames = fs
.readdirSync(path.join(packageRoot, SPEC_DIR))
.readdirSync(path.join(packageRoot, spec_dir))
.filter(fn => fn.endsWith('.spec.js'))
.map(fn => path.join(SPEC_DIR, fn));
.map(fn => path.join(spec_dir, fn));
runnerText = `<!DOCTYPE html>
<html>
@ -64,9 +71,10 @@ function writeSpecRunner() {
<script defer src="/${JASMINE_DIR}/boot.js"></script>
<!-- normally include source files here, but now we rely on ES6 test modules to load them. -->
${scripts.map(s => `<script src="${s}"></script>`).join('\n\t ')}
<!-- include spec files here... -->
${specFilenames.map(fn => `<script type="module" src="${fn}"></script>`).join('\n ')}
${specFilenames.map(fn => `<script type="module" src="${fn}"></script>`).join('\n\t ')}
</head><body></body>
</html>`;