Skip to content

Commit ef600f2

Browse files
authored
test: improve E2E test cleanup and assertion reliability
1 parent 512bb90 commit ef600f2

9 files changed

Lines changed: 78 additions & 59 deletions

File tree

‎tests/e2e.bzl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ WEBPACK_IGNORE_TESTS = [
5959
"tests/build/chunk-optimizer-heuristic.js",
6060
"tests/build/chunk-optimizer-env.js",
6161
"tests/build/chunk-optimizer-animations.js",
62+
"tests/build/prerender/error-component-render.js",
6263
]
6364

6465
def _to_glob(patterns):

‎tests/e2e/tests/architect_cli/direct_execution.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as assert from 'node:assert/strict';
1+
import assert from 'node:assert/strict';
22
import { exec } from '../../utils/process';
33
import { join } from 'node:path';
44

‎tests/e2e/tests/commands/config/config-global-validation.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from 'node:assert/strict';
22
import { homedir } from 'node:os';
3-
import * as path from 'node:path';
3+
import { join } from 'node:path';
44
import { deleteFile, expectFileToExist } from '../../../utils/fs';
55
import { ng, silentNg } from '../../../utils/process';
66
import { expectToFail } from '../../../utils/utils';
@@ -22,10 +22,14 @@ export default async function () {
2222
ngError = await expectToFail(() => silentNg('config', 'cli.completion.prompted'));
2323
assert.match(ngError.message, /Value cannot be found\./);
2424

25-
await ng('config', '--global', 'cli.completion.prompted', 'true');
26-
const { stdout } = await silentNg('config', '--global', 'cli.completion.prompted');
27-
assert.match(stdout, /true/);
25+
const globalConfigPath = join(homedir(), '.angular-config.json');
26+
try {
27+
await ng('config', '--global', 'cli.completion.prompted', 'true');
28+
const { stdout } = await silentNg('config', '--global', 'cli.completion.prompted');
29+
assert.match(stdout, /true/);
2830

29-
await expectFileToExist(path.join(homedir(), '.angular-config.json'));
30-
await deleteFile(path.join(homedir(), '.angular-config.json'));
31+
await expectFileToExist(globalConfigPath);
32+
} finally {
33+
await deleteFile(globalConfigPath).catch(() => {});
34+
}
3135
}
Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,47 @@
11
import assert from 'node:assert/strict';
22
import { homedir } from 'node:os';
3-
import * as path from 'node:path';
3+
import { join } from 'node:path';
44
import { deleteFile, expectFileToExist } from '../../../utils/fs';
55
import { ng } from '../../../utils/process';
66
import { expectToFail } from '../../../utils/utils';
77

88
export default async function () {
9-
await expectToFail(() =>
10-
ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle'),
11-
);
9+
const globalConfigPath = join(homedir(), '.angular-config.json');
1210

13-
await ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'false');
14-
let output = await ng(
15-
'config',
16-
'--global',
17-
'schematics.@schematics/angular.component.inlineStyle',
18-
);
19-
assert.match(output.stdout, /false\n?/);
11+
try {
12+
await expectToFail(() =>
13+
ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle'),
14+
);
2015

21-
// This test requires schema querying capabilities
22-
// .then(() => expectToFail(() => {
23-
// return ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'INVALID_BOOLEAN');
24-
// }))
16+
await ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'false');
17+
let output = await ng(
18+
'config',
19+
'--global',
20+
'schematics.@schematics/angular.component.inlineStyle',
21+
);
22+
assert.match(output.stdout, /false\n?/);
2523

26-
const cwd = process.cwd();
27-
process.chdir('/');
28-
try {
29-
await ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'true');
30-
} finally {
31-
process.chdir(cwd);
32-
}
24+
const cwd = process.cwd();
25+
process.chdir('/');
26+
try {
27+
await ng(
28+
'config',
29+
'--global',
30+
'schematics.@schematics/angular.component.inlineStyle',
31+
'true',
32+
);
33+
} finally {
34+
process.chdir(cwd);
35+
}
3336

34-
output = await ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle');
35-
assert.match(output.stdout, /true\n?/);
37+
output = await ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle');
38+
assert.match(output.stdout, /true\n?/);
3639

37-
await expectToFail(() => ng('config', '--global', 'cli.warnings.notreal', 'true'));
40+
await expectToFail(() => ng('config', '--global', 'cli.warnings.notreal', 'true'));
3841

39-
await ng('config', '--global', 'cli.warnings.versionMismatch', 'false');
40-
await expectFileToExist(path.join(homedir(), '.angular-config.json'));
41-
await deleteFile(path.join(homedir(), '.angular-config.json'));
42+
await ng('config', '--global', 'cli.warnings.versionMismatch', 'false');
43+
await expectFileToExist(globalConfigPath);
44+
} finally {
45+
await deleteFile(globalConfigPath).catch(() => {});
46+
}
4247
}

‎tests/e2e/tests/commands/serve/ssr-http-requests-assets.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default async function () {
8888
await killAllProcesses();
8989

9090
// With OpenSSl cert+key
91-
writeMultipleFiles({
91+
await writeMultipleFiles({
9292
'server.key': `-----BEGIN PRIVATE KEY-----
9393
MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQDOyBmVy61zEqfs
9494
oTPQ9gTX233/nlrVXtaUGJkbDR5actq0X+XQtZuIoO4JgRpiYz5/8XiY8AiaMdt3

‎tests/e2e/tests/generate/component/component-child-dir.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default async function () {
1414
// Generate a component inside the child directory
1515
await ng('generate', 'component', 'test-component');
1616

17-
// Move back to the root of the workspacee
17+
// Move back to the root of the workspace
1818
process.chdir(currentDirectory);
1919

2020
// Ensure component is created in the correct location relative to the workspace root
@@ -27,6 +27,7 @@ export default async function () {
2727
// Ensure unit test execute and pass
2828
await ng('test', '--watch=false');
2929
} finally {
30+
process.chdir(currentDirectory);
3031
// Windows CI may fail to clean up the created directory
3132
// Resolves: "Error: Running "cmd.exe /c git clean -df" returned error code 1"
3233
await rimraf(childDirectory);

‎tests/e2e/tests/mcp/ai-tutor.ts‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { chdir } from 'node:process';
21
import { exec, ProcessOutput, silentNpm } from '../../utils/process';
32
import assert from 'node:assert/strict';
43

@@ -28,13 +27,17 @@ export default async function () {
2827
`${MCP_INSPECTOR_PACKAGE_NAME}@${MCP_INSPECTOR_PACKAGE_VERSION}`,
2928
);
3029

31-
// Ensure `get_best_practices` returns the markdown content
32-
const { stdout: stdoutInsideWorkspace } = await runInspector(
33-
'--method',
34-
'tools/call',
35-
'--tool-name',
36-
'ai_tutor',
37-
);
30+
try {
31+
// Ensure `get_best_practices` returns the markdown content
32+
const { stdout: stdoutInsideWorkspace } = await runInspector(
33+
'--method',
34+
'tools/call',
35+
'--tool-name',
36+
'ai_tutor',
37+
);
3838

39-
assert.match(stdoutInsideWorkspace, /# `airules.md` - Modern Angular Tutor 🧑‍🏫/);
39+
assert.match(stdoutInsideWorkspace, /# `airules.md` - Modern Angular Tutor 🧑‍🏫/);
40+
} finally {
41+
await silentNpm('uninstall', '-g', MCP_INSPECTOR_PACKAGE_NAME);
42+
}
4043
}

‎tests/e2e/tests/mcp/best-practices.ts‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { chdir } from 'node:process';
21
import { exec, ProcessOutput, silentNpm } from '../../utils/process';
32
import assert from 'node:assert/strict';
43

@@ -28,16 +27,20 @@ export default async function () {
2827
`${MCP_INSPECTOR_PACKAGE_NAME}@${MCP_INSPECTOR_PACKAGE_VERSION}`,
2928
);
3029

31-
// Ensure `get_best_practices` returns the markdown content
32-
const { stdout: stdoutInsideWorkspace } = await runInspector(
33-
'--method',
34-
'tools/call',
35-
'--tool-name',
36-
'get_best_practices',
37-
);
30+
try {
31+
// Ensure `get_best_practices` returns the markdown content
32+
const { stdout: stdoutInsideWorkspace } = await runInspector(
33+
'--method',
34+
'tools/call',
35+
'--tool-name',
36+
'get_best_practices',
37+
);
3838

39-
assert.match(
40-
stdoutInsideWorkspace,
41-
/You are an expert in TypeScript, Angular, and scalable web application development./,
42-
);
39+
assert.match(
40+
stdoutInsideWorkspace,
41+
/You are an expert in TypeScript, Angular, and scalable web application development./,
42+
);
43+
} finally {
44+
await silentNpm('uninstall', '-g', MCP_INSPECTOR_PACKAGE_NAME);
45+
}
4346
}

‎tests/e2e/tests/mcp/registers-tools.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default async function () {
2828
`${MCP_INSPECTOR_PACKAGE_NAME}@${MCP_INSPECTOR_PACKAGE_VERSION}`,
2929
);
3030

31+
const initialCwd = process.cwd();
3132
// Ensure 'list_projects' is registered when inside an Angular workspace
3233
try {
3334
const { stdout: stdoutInsideWorkspace } = await runInspector('--method', 'tools/list');
@@ -42,8 +43,9 @@ export default async function () {
4243

4344
assert.match(stdoutOutsideWorkspace, /"list_projects"/);
4445
assert.match(stdoutOutsideWorkspace, /"get_best_practices"/);
45-
assert.match(stdoutInsideWorkspace, /"search_documentation"/);
46+
assert.match(stdoutOutsideWorkspace, /"search_documentation"/);
4647
} finally {
48+
chdir(initialCwd);
4749
await silentNpm('uninstall', '-g', MCP_INSPECTOR_PACKAGE_NAME);
4850
}
4951
}

0 commit comments

Comments
 (0)