|
1 | | -import { homedir } from 'os'; |
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { homedir } from 'node:os'; |
2 | 3 | import { silentNg } from '../../utils/process'; |
3 | | -import { expectToFail } from '../../utils/utils'; |
4 | 4 |
|
5 | 5 | export default async function () { |
6 | | - const originalCwd = process.cwd(); |
| 6 | + // Run inside workspace |
| 7 | + await silentNg('generate', 'component', 'foo', '--dry-run'); |
7 | 8 |
|
8 | | - try { |
9 | | - // Run inside workspace |
10 | | - await silentNg('generate', 'component', 'foo', '--dry-run'); |
| 9 | + // The version command can be run in and outside of a workspace. |
| 10 | + await silentNg('version'); |
11 | 11 |
|
12 | | - // The version command can be run in and outside of a workspace. |
13 | | - await silentNg('version'); |
| 12 | + assert.rejects( |
| 13 | + silentNg('new', 'proj-name', '--dry-run'), |
| 14 | + /This command is not available when running the Angular CLI inside a workspace\./, |
| 15 | + ); |
14 | 16 |
|
15 | | - const { message: ngNewFailure } = await expectToFail(() => |
16 | | - silentNg('new', 'proj-name', '--dry-run'), |
17 | | - ); |
18 | | - if ( |
19 | | - !ngNewFailure.includes( |
20 | | - 'This command is not available when running the Angular CLI inside a workspace.', |
21 | | - ) |
22 | | - ) { |
23 | | - throw new Error('ng new should have failed when ran inside a workspace.'); |
24 | | - } |
| 17 | + // Change CWD to run outside a workspace. |
| 18 | + process.chdir(homedir()); |
25 | 19 |
|
26 | | - // Chnage CWD to run outside a workspace. |
27 | | - process.chdir(homedir()); |
| 20 | + // ng generate can only be ran inside. |
| 21 | + assert.rejects( |
| 22 | + silentNg('generate', 'component', 'foo', '--dry-run'), |
| 23 | + /This command is not available when running the Angular CLI outside a workspace\./, |
| 24 | + ); |
28 | 25 |
|
29 | | - // ng generate can only be ran inside. |
30 | | - const { message: ngGenerateFailure } = await expectToFail(() => |
31 | | - silentNg('generate', 'component', 'foo', '--dry-run'), |
32 | | - ); |
33 | | - if ( |
34 | | - !ngGenerateFailure.includes( |
35 | | - 'This command is not available when running the Angular CLI outside a workspace.', |
36 | | - ) |
37 | | - ) { |
38 | | - throw new Error('ng generate should have failed when ran outside a workspace.'); |
39 | | - } |
| 26 | + // ng new can only be ran outside of a workspace |
| 27 | + await silentNg('new', 'proj-name', '--dry-run'); |
40 | 28 |
|
41 | | - // ng new can only be ran outside of a workspace |
42 | | - await silentNg('new', 'proj-name', '--dry-run'); |
43 | | - |
44 | | - // The version command can be run in and outside of a workspace. |
45 | | - await silentNg('version'); |
46 | | - } finally { |
47 | | - process.chdir(originalCwd); |
48 | | - } |
| 29 | + // The version command can be run in and outside of a workspace. |
| 30 | + await silentNg('version'); |
49 | 31 | } |
0 commit comments