Skip to content

Commit 5ef6a0e

Browse files
committed
fixup! test: use TEST_TMPDIR as fallback for E2E temporary directory
1 parent 44cbedd commit 5ef6a0e

4 files changed

Lines changed: 67 additions & 30 deletions

File tree

‎packages/angular/build/src/builders/unit-test/runners/vitest/browser-provider.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ export async function setupBrowserConfiguration(
183183
}
184184
}
185185
}
186+
} else if (providerName === 'webdriverio') {
187+
const executablePath = process.env['CHROME_BIN'];
188+
provider = providerFactory();
189+
190+
if (executablePath) {
191+
for (const instance of instances) {
192+
if (instance.browser === 'chrome' || instance.browser === 'chromium') {
193+
instance.provider = providerFactory({
194+
capabilities: {
195+
'goog:chromeOptions': { binary: executablePath },
196+
},
197+
});
198+
}
199+
}
200+
}
186201
} else {
187202
provider = providerFactory();
188203
}
Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { symlink } from 'node:fs/promises';
22
import { resolve } from 'node:path';
3+
import { setTimeout } from 'node:timers/promises';
34
import { appendToFile, expectFileToMatch, writeMultipleFiles } from '../../utils/fs';
4-
import { execAndWaitForOutputToMatch, waitForAnyProcessOutputToMatch } from '../../utils/process';
5+
import {
6+
execAndWaitForOutputToMatch,
7+
killAllProcesses,
8+
waitForAnyProcessOutputToMatch,
9+
} from '../../utils/process';
510
import { updateJsonFile } from '../../utils/project';
611
import { getGlobalVariable } from '../../utils/env';
712

@@ -10,32 +15,37 @@ const buildReadyRegEx = getGlobalVariable('argv')['esbuild']
1015
: /Build at: /;
1116

1217
export default async function () {
13-
// TODO: Disabled pending investigation. Steps work outside of test
14-
if (getGlobalVariable('argv')['esbuild']) {
15-
return;
16-
}
18+
try {
19+
await updateJsonFile('angular.json', (configJson) => {
20+
configJson.projects['test-project'].architect.build.options.preserveSymlinks = true;
21+
});
22+
23+
await writeMultipleFiles({
24+
'src/link-source.ts': '// empty file',
25+
'src/main.ts': `import './link-dest';`,
26+
});
27+
28+
await symlink(resolve('src/link-source.ts'), resolve('src/link-dest.ts'));
29+
30+
await execAndWaitForOutputToMatch(
31+
'ng',
32+
['build', '--watch', '--configuration=development'],
33+
buildReadyRegEx,
34+
);
1735

18-
await updateJsonFile('angular.json', (configJson) => {
19-
configJson.projects['test-project'].architect.build.options.preserveSymlinks = true;
20-
});
21-
22-
await writeMultipleFiles({
23-
'src/link-source.ts': '// empty file',
24-
'src/main.ts': `import './link-dest';`,
25-
});
26-
27-
await symlink(resolve('src/link-source.ts'), resolve('src/link-dest.ts'));
28-
29-
await execAndWaitForOutputToMatch(
30-
'ng',
31-
['build', '--watch', '--configuration=development'],
32-
buildReadyRegEx,
33-
);
34-
35-
// Trigger a rebuild
36-
await Promise.all([
37-
waitForAnyProcessOutputToMatch(buildReadyRegEx),
38-
appendToFile('src/link-source.ts', `\nconsole.log('foo-bar');`),
39-
]);
40-
await expectFileToMatch('dist/test-project/browser/main.js', `console.log('foo-bar')`);
36+
await setTimeout(500);
37+
38+
// Trigger a rebuild
39+
await Promise.all([
40+
waitForAnyProcessOutputToMatch(buildReadyRegEx),
41+
appendToFile('src/link-source.ts', `\nconsole.log('foo-bar');`),
42+
]);
43+
44+
await expectFileToMatch(
45+
'dist/test-project/browser/main.js',
46+
/console\.log\(["']foo-bar["']\);/,
47+
);
48+
} finally {
49+
await killAllProcesses();
50+
}
4151
}

‎tests/e2e/utils/process.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
6060
const spawnOptions: SpawnOptions = {
6161
cwd,
6262
env: { ...env, PATH: paths },
63+
detached: process.platform !== 'win32',
6364
};
6465

6566
if (process.platform.startsWith('win')) {

‎tests/e2e/utils/test_process.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,24 @@ const testFunction: () => Promise<void> | void =
1111
throw new Error('Invalid test module.');
1212
};
1313

14+
// 4-minute timeout to prevent hanging tests from blocking the runner indefinitely.
15+
const TEST_TIMEOUT_MS = 4 * 60 * 1000;
16+
1417
(async () => {
18+
let timeoutId: NodeJS.Timeout | undefined;
1519
try {
16-
await testFunction();
20+
const timeoutPromise = new Promise<never>((_, reject) => {
21+
timeoutId = setTimeout(() => {
22+
reject(new Error(`Test "${testScript}" timed out after 4 minutes.`));
23+
}, TEST_TIMEOUT_MS);
24+
});
25+
26+
await Promise.race([testFunction(), timeoutPromise]);
1727
} catch (e) {
1828
console.error('Test Process error', e);
1929
process.exitCode = -1;
2030
} finally {
21-
killAllProcesses().finally(() => process.exit());
31+
clearTimeout(timeoutId);
32+
await killAllProcesses().finally(() => process.exit());
2233
}
2334
})();

0 commit comments

Comments
 (0)