Skip to content

Commit 0a9c2ab

Browse files
committed
test: remove unneeded kill-all-processes calls in E2E tests
The E2E test runner will always perform the call after the completion of each E2E test. This removes the need to manually execute the helper function at the end of a test. All tests that did so have had the call removed from the end of the test. Some tests use the helper within the test and those calls have not been altered and remain.
1 parent 1d82a7c commit 0a9c2ab

14 files changed

+94
-148
lines changed

tests/legacy-cli/e2e/tests/basic/serve.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@ import { killAllProcesses } from '../../utils/process';
22
import { ngServe } from '../../utils/project';
33

44
export default async function () {
5-
try {
6-
// Serve works without HMR
7-
const noHmrPort = await ngServe('--no-hmr');
8-
await verifyResponse(noHmrPort);
9-
await killAllProcesses();
5+
// Serve works without HMR
6+
const noHmrPort = await ngServe('--no-hmr');
7+
await verifyResponse(noHmrPort);
8+
await killAllProcesses();
109

11-
// Serve works with HMR
12-
const hmrPort = await ngServe('--hmr');
13-
await verifyResponse(hmrPort);
14-
} finally {
15-
await killAllProcesses();
16-
}
10+
// Serve works with HMR
11+
const hmrPort = await ngServe('--hmr');
12+
await verifyResponse(hmrPort);
1713
}
1814

1915
async function verifyResponse(port: number): Promise<void> {
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getGlobalVariable } from '../../utils/env';
22
import { appendToFile } from '../../utils/fs';
3-
import { killAllProcesses, waitForAnyProcessOutputToMatch } from '../../utils/process';
3+
import { waitForAnyProcessOutputToMatch } from '../../utils/process';
44
import { ngServe } from '../../utils/project';
55
import { expectToFail, wait } from '../../utils/utils';
66

@@ -9,24 +9,20 @@ const webpackGoodRegEx = getGlobalVariable('argv')['esbuild']
99
: / Compiled successfully\./;
1010

1111
export default async function () {
12-
try {
13-
await ngServe('--poll=10000');
12+
await ngServe('--poll=10000');
1413

15-
// Wait before editing a file.
16-
// Editing too soon seems to trigger a rebuild and throw polling out of whack.
17-
await wait(3000);
18-
await appendToFile('src/main.ts', 'console.log(1);');
14+
// Wait before editing a file.
15+
// Editing too soon seems to trigger a rebuild and throw polling out of whack.
16+
await wait(3000);
17+
await appendToFile('src/main.ts', 'console.log(1);');
1918

20-
// We have to wait poll time + rebuild build time for the regex match.
21-
await waitForAnyProcessOutputToMatch(webpackGoodRegEx, 14000);
19+
// We have to wait poll time + rebuild build time for the regex match.
20+
await waitForAnyProcessOutputToMatch(webpackGoodRegEx, 14000);
2221

23-
// No rebuilds should occur for a while
24-
await appendToFile('src/main.ts', 'console.log(1);');
25-
await expectToFail(() => waitForAnyProcessOutputToMatch(webpackGoodRegEx, 7000));
22+
// No rebuilds should occur for a while
23+
await appendToFile('src/main.ts', 'console.log(1);');
24+
await expectToFail(() => waitForAnyProcessOutputToMatch(webpackGoodRegEx, 7000));
2625

27-
// But a rebuild should happen roughly within the 10 second window.
28-
await waitForAnyProcessOutputToMatch(webpackGoodRegEx, 7000);
29-
} finally {
30-
await killAllProcesses();
31-
}
26+
// But a rebuild should happen roughly within the 10 second window.
27+
await waitForAnyProcessOutputToMatch(webpackGoodRegEx, 7000);
3228
}

tests/legacy-cli/e2e/tests/build/rebuild-deps-type-check.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
killAllProcesses,
3-
waitForAnyProcessOutputToMatch,
4-
execAndWaitForOutputToMatch,
5-
} from '../../utils/process';
1+
import { waitForAnyProcessOutputToMatch, execAndWaitForOutputToMatch } from '../../utils/process';
62
import { writeFile, prependToFile, appendToFile } from '../../utils/fs';
73
import { getGlobalVariable } from '../../utils/env';
84

@@ -129,6 +125,5 @@ export default function () {
129125
throw new Error('Expected no error but an error was shown.');
130126
}
131127
})
132-
.finally(() => killAllProcesses())
133128
);
134129
}
Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getGlobalVariable } from '../../utils/env';
22
import { appendToFile, createDir, writeMultipleFiles } from '../../utils/fs';
3-
import { killAllProcesses, waitForAnyProcessOutputToMatch } from '../../utils/process';
3+
import { waitForAnyProcessOutputToMatch } from '../../utils/process';
44
import { ngServe, updateJsonFile } from '../../utils/project';
55

66
const webpackGoodRegEx = getGlobalVariable('argv')['esbuild']
@@ -14,32 +14,28 @@ export default async function () {
1414

1515
await createDir('src/environments');
1616

17-
try {
18-
await writeMultipleFiles({
19-
'src/environments/environment.ts': `export const env = 'dev';`,
20-
'src/environments/environment.prod.ts': `export const env = 'prod';`,
21-
'src/main.ts': `
17+
await writeMultipleFiles({
18+
'src/environments/environment.ts': `export const env = 'dev';`,
19+
'src/environments/environment.prod.ts': `export const env = 'prod';`,
20+
'src/main.ts': `
2221
import { env } from './environments/environment';
2322
console.log(env);
2423
`,
25-
});
24+
});
2625

27-
await updateJsonFile('angular.json', (workspaceJson) => {
28-
const appArchitect = workspaceJson.projects['test-project'].architect;
29-
appArchitect.build.configurations.production.fileReplacements = [
30-
{
31-
replace: 'src/environments/environment.ts',
32-
with: 'src/environments/environment.prod.ts',
33-
},
34-
];
35-
});
26+
await updateJsonFile('angular.json', (workspaceJson) => {
27+
const appArchitect = workspaceJson.projects['test-project'].architect;
28+
appArchitect.build.configurations.production.fileReplacements = [
29+
{
30+
replace: 'src/environments/environment.ts',
31+
with: 'src/environments/environment.prod.ts',
32+
},
33+
];
34+
});
3635

37-
await ngServe('--configuration=production');
36+
await ngServe('--configuration=production');
3837

39-
// Should trigger a rebuild.
40-
await appendToFile('src/environments/environment.prod.ts', `console.log('PROD');`);
41-
await waitForAnyProcessOutputToMatch(webpackGoodRegEx);
42-
} finally {
43-
await killAllProcesses();
44-
}
38+
// Should trigger a rebuild.
39+
await appendToFile('src/environments/environment.prod.ts', `console.log('PROD');`);
40+
await waitForAnyProcessOutputToMatch(webpackGoodRegEx);
4541
}
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
killAllProcesses,
3-
waitForAnyProcessOutputToMatch,
4-
execAndWaitForOutputToMatch,
5-
} from '../../utils/process';
1+
import { waitForAnyProcessOutputToMatch, execAndWaitForOutputToMatch } from '../../utils/process';
62
import { writeFile, prependToFile } from '../../utils/fs';
73
import { getGlobalVariable } from '../../utils/env';
84

@@ -20,14 +16,10 @@ export default async function () {
2016
await writeFile('src/app/type.ts', `export type MyType = number;`);
2117
await prependToFile('src/app/app.component.ts', 'import { MyType } from "./type";\n');
2218

23-
try {
24-
await execAndWaitForOutputToMatch('ng', ['serve'], successRe);
19+
await execAndWaitForOutputToMatch('ng', ['serve'], successRe);
2520

26-
await Promise.all([
27-
waitForAnyProcessOutputToMatch(successRe, 20000),
28-
writeFile('src/app/type.ts', `export type MyType = string;`),
29-
]);
30-
} finally {
31-
await killAllProcesses();
32-
}
21+
await Promise.all([
22+
waitForAnyProcessOutputToMatch(successRe, 20000),
23+
writeFile('src/app/type.ts', `export type MyType = string;`),
24+
]);
3325
}

tests/legacy-cli/e2e/tests/build/ssr/express-engine-csp-nonce.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getGlobalVariable } from '../../../utils/env';
22
import { rimraf, writeMultipleFiles } from '../../../utils/fs';
33
import { findFreePort } from '../../../utils/network';
44
import { installWorkspacePackages } from '../../../utils/packages';
5-
import { execAndWaitForOutputToMatch, killAllProcesses, ng } from '../../../utils/process';
5+
import { execAndWaitForOutputToMatch, ng } from '../../../utils/process';
66
import { updateJsonFile, useSha } from '../../../utils/project';
77

88
export default async function () {
@@ -154,10 +154,6 @@ export default async function () {
154154
return port;
155155
}
156156

157-
try {
158-
const port = await ngDevSsr();
159-
await ng('e2e', `--base-url=http://localhost:${port}`, '--dev-server-target=');
160-
} finally {
161-
await killAllProcesses();
162-
}
157+
const port = await ngDevSsr();
158+
await ng('e2e', `--base-url=http://localhost:${port}`, '--dev-server-target=');
163159
}

tests/legacy-cli/e2e/tests/build/ssr/express-engine-ngmodule.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getGlobalVariable } from '../../../utils/env';
22
import { rimraf, writeMultipleFiles } from '../../../utils/fs';
33
import { findFreePort } from '../../../utils/network';
44
import { installWorkspacePackages } from '../../../utils/packages';
5-
import { execAndWaitForOutputToMatch, killAllProcesses, ng } from '../../../utils/process';
5+
import { execAndWaitForOutputToMatch, ng } from '../../../utils/process';
66
import { updateJsonFile, useCIChrome, useCIDefaults, useSha } from '../../../utils/project';
77

88
export default async function () {
@@ -158,15 +158,11 @@ export default async function () {
158158
return port;
159159
}
160160

161-
try {
162-
const port = await ngDevSsr();
163-
await ng(
164-
'e2e',
165-
'test-project-two',
166-
`--base-url=http://localhost:${port}`,
167-
'--dev-server-target=',
168-
);
169-
} finally {
170-
await killAllProcesses();
171-
}
161+
const port = await ngDevSsr();
162+
await ng(
163+
'e2e',
164+
'test-project-two',
165+
`--base-url=http://localhost:${port}`,
166+
'--dev-server-target=',
167+
);
172168
}

tests/legacy-cli/e2e/tests/build/ssr/express-engine-standalone.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getGlobalVariable } from '../../../utils/env';
22
import { rimraf, writeMultipleFiles } from '../../../utils/fs';
33
import { findFreePort } from '../../../utils/network';
44
import { installWorkspacePackages } from '../../../utils/packages';
5-
import { execAndWaitForOutputToMatch, killAllProcesses, ng } from '../../../utils/process';
5+
import { execAndWaitForOutputToMatch, ng } from '../../../utils/process';
66
import { updateJsonFile, useSha } from '../../../utils/project';
77

88
export default async function () {
@@ -123,10 +123,6 @@ export default async function () {
123123
return port;
124124
}
125125

126-
try {
127-
const port = await ngDevSsr();
128-
await ng('e2e', `--base-url=http://localhost:${port}`, '--dev-server-target=');
129-
} finally {
130-
await killAllProcesses();
131-
}
126+
const port = await ngDevSsr();
127+
await ng('e2e', `--base-url=http://localhost:${port}`, '--dev-server-target=');
132128
}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import { killAllProcesses, silentNg } from '../../../utils/process';
1+
import { silentNg } from '../../../utils/process';
22
import { ngServe } from '../../../utils/project';
33

44
export default async function () {
5-
try {
6-
// Should run side-by-side with `ng serve`
7-
await ngServe();
8-
await silentNg('e2e');
9-
} finally {
10-
killAllProcesses();
11-
}
5+
// Should run side-by-side with `ng serve`
6+
await ngServe();
7+
await silentNg('e2e');
128
}
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
import { prependToFile, writeFile } from '../../../utils/fs';
2-
import { execAndWaitForOutputToMatch, killAllProcesses } from '../../../utils/process';
2+
import { execAndWaitForOutputToMatch } from '../../../utils/process';
33

44
export default async function () {
55
// Simulate a JS library using a Node.js specific module
66
await writeFile('src/node-usage.js', `const path = require('path');\n`);
77
await prependToFile('src/main.ts', `import './node-usage';\n`);
88

9-
try {
10-
// Make sure serve is consistent with build
11-
await execAndWaitForOutputToMatch(
12-
'ng',
13-
['build'],
14-
/Module not found: Error: Can't resolve 'path'/,
15-
);
16-
// The Node.js specific module should not be found
17-
await execAndWaitForOutputToMatch(
18-
'ng',
19-
['serve', '--port=0'],
20-
/Module not found: Error: Can't resolve 'path'/,
21-
);
22-
} finally {
23-
await killAllProcesses();
24-
}
9+
// Make sure serve is consistent with build
10+
await execAndWaitForOutputToMatch(
11+
'ng',
12+
['build'],
13+
/Module not found: Error: Can't resolve 'path'/,
14+
);
15+
// The Node.js specific module should not be found
16+
await execAndWaitForOutputToMatch(
17+
'ng',
18+
['serve', '--port=0'],
19+
/Module not found: Error: Can't resolve 'path'/,
20+
);
2521
}

0 commit comments

Comments
 (0)