Skip to content

Commit 7c6a400

Browse files
jbedardalan-agius4
authored andcommitted
test: add shard and test type/name information to test logging
1 parent 35c4357 commit 7c6a400

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

tests/legacy-cli/e2e_runner.ts

+31-6
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,19 @@ const tests = allTests.filter((name) => {
123123
const testsToRun = tests.filter((name, i) => shardId === null || i % nbShards == shardId);
124124

125125
if (testsToRun.length === 0) {
126-
console.log(`No tests would be ran, aborting.`);
127-
process.exit(1);
126+
if (shardId !== null && tests.length >= shardId ? 1 : 0) {
127+
console.log(`No tests to run on shard ${shardId}, exiting.`);
128+
process.exit(0);
129+
} else {
130+
console.log(`No tests would be ran, aborting.`);
131+
process.exit(1);
132+
}
133+
}
134+
135+
if (shardId !== null) {
136+
console.log(`Running shard ${shardId} of ${nbShards}`);
128137
}
129138

130-
console.log(testsToRun.join('\n'));
131139
/**
132140
* Load all the files from the e2e, filter and sort them and build a promise of their default
133141
* export.
@@ -138,6 +146,8 @@ if (testsToRun.length == allTests.length) {
138146
console.log(`Running ${testsToRun.length} tests (${allTests.length} total)`);
139147
}
140148

149+
console.log(['Tests:', ...testsToRun].join('\n '));
150+
141151
setGlobalVariable('argv', argv);
142152
setGlobalVariable('ci', process.env['CI']?.toLowerCase() === 'true' || process.env['CI'] === '1');
143153
setGlobalVariable('package-manager', argv.yarn ? 'yarn' : 'npm');
@@ -156,14 +166,20 @@ Promise.all([findFreePort(), findFreePort()])
156166
await runSteps(runInitializer, allInitializers, 'initializer');
157167
await runSteps(runTest, testsToRun, 'test');
158168

159-
console.log(colors.green('Done.'));
169+
if (shardId !== null) {
170+
console.log(colors.green(`Done shard ${shardId} of ${nbShards}.`));
171+
} else {
172+
console.log(colors.green('Done.'));
173+
}
160174
} catch (err) {
161175
if (err instanceof Error) {
162176
console.log('\n');
163177
console.error(colors.red(err.message));
164178
if (err.stack) {
165179
console.error(colors.red(err.stack));
166180
}
181+
} else {
182+
console.error(colors.red(String(err)));
167183
}
168184

169185
if (argv.debug) {
@@ -192,6 +208,8 @@ async function runSteps(
192208
steps: string[],
193209
type: 'setup' | 'test' | 'initializer',
194210
) {
211+
const capsType = type[0].toUpperCase() + type.slice(1);
212+
195213
for (const [stepIndex, relativeName] of steps.entries()) {
196214
// Make sure this is a windows compatible path.
197215
let absoluteName = path.join(e2eRoot, relativeName).replace(/\.ts$/, '');
@@ -210,7 +228,8 @@ async function runSteps(
210228
await run(absoluteName);
211229
} catch (e) {
212230
console.log('\n');
213-
console.error(colors.red(`Step "${absoluteName}" failed...`));
231+
console.error(colors.red(`${capsType} "${name}" failed...`));
232+
214233
throw e;
215234
} finally {
216235
logStack.pop();
@@ -274,8 +293,14 @@ function printHeader(
274293
}
275294

276295
function printFooter(testName: string, type: 'setup' | 'initializer' | 'test', startTime: number) {
296+
const capsType = type[0].toUpperCase() + type.slice(1);
297+
277298
// Round to hundredth of a second.
278299
const t = Math.round((Date.now() - startTime) / 10) / 100;
279-
console.log(colors.green(`Last ${type} took `) + colors.bold.blue('' + t) + colors.green('s...'));
300+
console.log(
301+
colors.green(`${capsType} "${colors.bold.blue(testName)}" took `) +
302+
colors.bold.blue('' + t) +
303+
colors.green('s...'),
304+
);
280305
console.log('');
281306
}

0 commit comments

Comments
 (0)