Skip to content

Commit

Permalink
build: improve test runner concurrency (#2679)
Browse files Browse the repository at this point in the history
By using streaming in our vite to web-test-runner proxy, we can improve the concurrency capabilities of running tests.
  • Loading branch information
kyubisation authored May 21, 2024
1 parent 42d28b5 commit fa2c305
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
3 changes: 2 additions & 1 deletion tools/web-test-runner/vite-plugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { existsSync } from 'fs';
import { Readable } from 'stream';
import { createServer } from 'vite';

// Reference: https://github.com/remcovaes/web-test-runner-vite-plugin
Expand Down Expand Up @@ -52,8 +53,8 @@ export function vitePlugin() {
// Retry once on failure.
// This can happen when too many http requests are being handled by the operating system.
const response = await fetch(url).catch(() => Promise.resolve().then(() => fetch(url)));
ctx.body = Readable.fromWeb(response.body);
ctx.set(Object.fromEntries(response.headers));
ctx.body = await response.text();
ctx.status = response.status;
});
},
Expand Down
9 changes: 0 additions & 9 deletions web-test-runner.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { puppeteerLauncher } from '@web/test-runner-puppeteer';
import { a11ySnapshotPlugin } from '@web/test-runner-commands/plugins';
import { visualRegressionPlugin } from '@web/test-runner-visual-regression/plugin';
import * as sass from 'sass';
import { cpus } from 'node:os';

import {
minimalReporter,
Expand Down Expand Up @@ -99,13 +98,6 @@ const testRunnerHtml = (testFramework, _config, group) => `
</html>
`;

// Slow down fast cpus to not run into too much fetches
function resolveConcurrency() {
const localCpus = cpus();
const factor = localCpus.some((el) => el.model.includes('Apple M')) ? 4 : 2;
return Math.floor(localCpus.length / factor);
}

// A list of log messages, that should not be printed to the test console.
const suppressedLogs = [
'Lit is in dev mode. Not recommended for production! See https://lit.dev/msg/dev-mode for more information.',
Expand All @@ -128,7 +120,6 @@ export default {
files: ['src/**/*.{e2e,spec,!snapshot.spec}.ts'],
groups,
nodeResolve: true,
concurrency: resolveConcurrency(),
reporters:
isDebugMode || !isCIEnvironment
? [defaultReporter(), patchedSummaryReporter()]
Expand Down

0 comments on commit fa2c305

Please sign in to comment.