Skip to content

Commit

Permalink
bugfix and more parallel setup
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Apr 28, 2021
1 parent 6362a8b commit 16cfb55
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
9 changes: 1 addition & 8 deletions lib/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 = ['/'];
}
Expand Down
30 changes: 19 additions & 11 deletions lib/commands/run/tests-in-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 16cfb55

Please sign in to comment.