"use strict";
// Usage: `node generate-test-wrappers.js js-filename1.js [js-filename2.js ...]` will generate:
// - js-filename1.https.html
// - js-filename1.sharedworker.html
// - js-filename1.dedicatedworker.html
// - js-filename1.serviceworker.html
// (for each passed filename)
//
// It will turn any importScripts inside the .js file into `)
.join('\n');
const basename = path.basename(jsFilename);
const noExtension = path.basename(jsFilename, '.js');
const outputs = {
'.html': `
${basename} browser context wrapper file
${importedScriptTags}
`,
'.dedicatedworker.html': `
${basename} dedicated worker wrapper file
`,
'.sharedworker.html': `
${basename} shared worker wrapper file
`,
'.serviceworker.https.html': `
${basename} service worker wrapper file
`
};
for (const [key, value] of Object.entries(outputs)) {
const destFilename = path.resolve(path.dirname(jsFilename), `${noExtension}${key}`);
fs.writeFileSync(destFilename, value, { encoding: 'utf-8' });
}
}
function findImportedScriptFilenames(inputFilename) {
const scriptContents = fs.readFileSync(inputFilename, { encoding: 'utf-8' });
const regExp = /self\.importScripts\('([^']+)'\);/g;
let result = [];
let match;
while (match = regExp.exec(scriptContents)) {
result.push(match[1]);
}
return result.filter(x => x !== '/resources/testharness.js');
}