Repository navigation
Expand file tree
/
Copy pathschematics_spec.ts
More file actions
96 lines (85 loc) · 3.78 KB
/
Copy pathschematics_spec.ts
File metadata and controls
96 lines (85 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { PassThrough } from 'node:stream';
import { stripVTControlCharacters } from 'node:util';
import { main } from '../bin/schematics';
describe('schematics-cli binary', () => {
let stdout: PassThrough, stderr: PassThrough;
beforeEach(() => {
stdout = new PassThrough();
stderr = new PassThrough();
});
it('list-schematics works', async () => {
const args = ['--list-schematics'];
const res = await main({ args, stdout, stderr });
const output = stripVTControlCharacters(stdout.read()?.toString() || '');
expect(output).toMatch(/blank/);
expect(output).toMatch(/schematic/);
expect(res).toEqual(0);
});
it('errors when using camel case listSchematics', async () => {
const args = ['--listSchematics'];
await expectAsync(main({ args, stdout, stderr })).toBeRejectedWithError(
'Unknown argument listSchematics. Did you mean list-schematics?',
);
});
it('dry-run works', async () => {
const args = ['blank', 'foo', '--dry-run'];
const res = await main({ args, stdout, stderr });
const output = stripVTControlCharacters(stdout.read()?.toString() || '');
expect(output).toMatch(/CREATE foo\/README.md/);
expect(output).toMatch(/CREATE foo\/.gitignore/);
expect(output).toMatch(/CREATE foo\/src\/foo\/index.ts/);
expect(output).toMatch(/CREATE foo\/src\/foo\/index_spec.ts/);
expect(output).toMatch(/Dry run enabled./);
expect(res).toEqual(0);
});
it('dry-run is default when debug mode', async () => {
const args = ['blank', 'foo', '--debug'];
const res = await main({ args, stdout, stderr });
const output = stripVTControlCharacters(stdout.read()?.toString() || '');
expect(output).toMatch(/Debug mode enabled./);
expect(output).toMatch(/CREATE foo\/README.md/);
expect(output).toMatch(/CREATE foo\/.gitignore/);
expect(output).toMatch(/CREATE foo\/src\/foo\/index.ts/);
expect(output).toMatch(/CREATE foo\/src\/foo\/index_spec.ts/);
expect(output).toMatch(/Dry run enabled by default in debug mode./);
expect(res).toEqual(0);
});
it('handles boolean CLI options with explicit inline false values', async () => {
const args = ['blank', 'foo', '--dry-run', '--debug=false'];
const res = await main({ args, stdout, stderr });
const output = stripVTControlCharacters(stdout.read()?.toString() || '');
expect(output).not.toMatch(/Debug mode enabled/);
expect(output).toMatch(/Dry run enabled\./);
expect(res).toEqual(0);
});
it('does not display help when --help=false is passed', async () => {
const args = ['blank', 'foo', '--dry-run', '--help=false'];
const res = await main({ args, stdout, stderr });
const output = stripVTControlCharacters(stdout.read()?.toString() || '');
expect(output).not.toMatch(/schematics \[collection-name:\]schematic-name/);
expect(output).toMatch(/Dry run enabled\./);
expect(res).toEqual(0);
});
it('does not list schematics when --list-schematics=false is passed', async () => {
const args = ['blank', 'foo', '--dry-run', '--list-schematics=false'];
const res = await main({ args, stdout, stderr });
const output = stripVTControlCharacters(stdout.read()?.toString() || '');
expect(output).not.toMatch(/blank/);
expect(output).toMatch(/Dry run enabled\./);
expect(res).toEqual(0);
});
it('error when no name is provided', async () => {
const args = ['blank'];
const res = await main({ args, stdout, stderr });
const output = stripVTControlCharacters(stderr.read()?.toString() || '');
expect(output).toMatch(/Error: name option is required/);
expect(res).toEqual(1);
});
});