diff --git a/lib/commands/run.js b/lib/commands/run.js index b9e734f..d0f94b0 100644 --- a/lib/commands/run.js +++ b/lib/commands/run.js @@ -16,7 +16,6 @@ const __dirname = dirname(fileURLToPath(import.meta.url)); export default async function(config) { if (config.browser) { - let htmlBuffers = await Promise.all(config.htmlPaths.map((htmlPath) => fs.readFile(htmlPath))); // TODO: remove this and read it from the fsTree, should be cached? let cachedContent = await buildCachedContentTree(config, config.htmlPaths); let [connections, _] = await Promise.all([ @@ -51,6 +50,7 @@ export default async function(config) { } async function buildCachedContentTree(config, htmlPaths) { + let htmlBuffers = await Promise.all(config.htmlPaths.map((htmlPath) => fs.readFile(htmlPath))); // TODO: remove this and read it from the fsTree, should be cached? let cachedContent = htmlPaths.reduce((result, htmlPath, index) => { let filePath = config.htmlPaths[index]; let html = htmlBuffers[index].toString(); @@ -80,13 +80,6 @@ async function buildCachedContentTree(config, htmlPaths) { dynamicContentHTMLs: {} }); - await Promise.all(cachedContent.htmlPathsToRunTests.map(async (dynamicHTMLPath) => { - let targetPath = `${config.projectRoot}/${config.output}${dynamicHTMLPath}`; - - await fs.rm(targetPath, { force: true }); - await fs.mkdir(targetPath.split('/').slice(0, -1).join('/'), { recursive: true }); // NOTE: this can be done earlier - })); - if (cachedContent.htmlPathsToRunTests.length === 0) { cachedContent.htmlPathsToRunTests = ['/']; } diff --git a/lib/commands/run/tests-in-browser.js b/lib/commands/run/tests-in-browser.js index efbec20..37456bd 100644 --- a/lib/commands/run/tests-in-browser.js +++ b/lib/commands/run/tests-in-browser.js @@ -31,17 +31,25 @@ export default async function runTestsInBrowser( }, config); try { - await esbuild.build({ - stdin: { - contents: Object.keys(fsTree).reduce((result, fileAbsolutePath) => { - return result + `import "${fileAbsolutePath}";` - }, ''), - resolveDir: process.cwd() - }, - bundle: true, - logLevel: 'error', - outfile: `${projectRoot}/${output}/tests.js` - }); // NOTE: This prevents file cache most likely + await Promise.all([ + esbuild.build({ + stdin: { + contents: Object.keys(fsTree).reduce((result, fileAbsolutePath) => { + return result + `import "${fileAbsolutePath}";` + }, ''), + resolveDir: process.cwd() + }, + bundle: true, + logLevel: 'error', + outfile: `${projectRoot}/${output}/tests.js` + }), // NOTE: This prevents file cache most likely + Promise.all(cachedContent.htmlPathsToRunTests.map(async (htmlPath) => { + let targetPath = `${config.projectRoot}/${config.output}${htmlPath}`; + + await fs.rm(targetPath, { force: true }); + await fs.mkdir(targetPath.split('/').slice(0, -1).join('/'), { recursive: true }); // NOTE: this can be done earlier + })) + ]); cachedContent.allTestCode = await fs.readFile(`${projectRoot}/${output}/tests.js`); let TIME_COUNTER = timeCounter();