Skip to content

Commit 4e3a240

Browse files
test: update unit tests (devkit breaking change)
1 parent c3bba22 commit 4e3a240

19 files changed

+781
-866
lines changed

src/lib/application/application.factory.test.ts

Lines changed: 331 additions & 284 deletions
Large diffs are not rendered by default.

src/lib/class/class.factory.test.ts

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ describe('Class Factory', () => {
1616
spec: true,
1717
flat: true,
1818
};
19-
const tree: UnitTestTree = await runner
20-
.runSchematicAsync('class', options)
21-
.toPromise();
19+
const tree: UnitTestTree = await runner.runSchematic('class', options);
20+
2221
const files: string[] = tree.files;
2322

2423
expect(
@@ -32,9 +31,8 @@ describe('Class Factory', () => {
3231
flat: false,
3332
spec: false,
3433
};
35-
const tree: UnitTestTree = await runner
36-
.runSchematicAsync('class', options)
37-
.toPromise();
34+
const tree: UnitTestTree = await runner.runSchematic('class', options);
35+
3836
const files: string[] = tree.files;
3937

4038
expect(
@@ -51,9 +49,8 @@ describe('Class Factory', () => {
5149
flat: false,
5250
spec: false,
5351
};
54-
const tree: UnitTestTree = await runner
55-
.runSchematicAsync('class', options)
56-
.toPromise();
52+
const tree: UnitTestTree = await runner.runSchematic('class', options);
53+
5754
const files: string[] = tree.files;
5855
expect(
5956
files.find((filename) => filename === '/baz/foo/foo.ts'),
@@ -68,9 +65,8 @@ describe('Class Factory', () => {
6865
flat: false,
6966
spec: false,
7067
};
71-
const tree: UnitTestTree = await runner
72-
.runSchematicAsync('class', options)
73-
.toPromise();
68+
const tree: UnitTestTree = await runner.runSchematic('class', options);
69+
7470
const files: string[] = tree.files;
7571
expect(
7672
files.find((filename) => filename === '/_foo-bar/_foo-bar.ts'),
@@ -85,9 +81,8 @@ describe('Class Factory', () => {
8581
spec: false,
8682
flat: false,
8783
};
88-
const tree: UnitTestTree = await runner
89-
.runSchematicAsync('class', options)
90-
.toPromise();
84+
const tree: UnitTestTree = await runner.runSchematic('class', options);
85+
9186
const files: string[] = tree.files;
9287
expect(
9388
files.find((filename) => filename === '/bar-baz/_foo/_foo.ts'),
@@ -103,9 +98,8 @@ describe('Class Factory', () => {
10398
flat: false,
10499
spec: false,
105100
};
106-
const tree: UnitTestTree = await runner
107-
.runSchematicAsync('class', options)
108-
.toPromise();
101+
const tree: UnitTestTree = await runner.runSchematic('class', options);
102+
109103
const files: string[] = tree.files;
110104
expect(
111105
files.find((filename) => filename === '/foo/foo.js'),
@@ -118,9 +112,8 @@ describe('Class Factory', () => {
118112
spec: true,
119113
flat: true,
120114
};
121-
const tree: UnitTestTree = await runner
122-
.runSchematicAsync('class', options)
123-
.toPromise();
115+
const tree: UnitTestTree = await runner.runSchematic('class', options);
116+
124117
const files: string[] = tree.files;
125118

126119
expect(
@@ -136,9 +129,8 @@ describe('Class Factory', () => {
136129
spec: true,
137130
flat: true,
138131
};
139-
const tree: UnitTestTree = await runner
140-
.runSchematicAsync('class', options)
141-
.toPromise();
132+
const tree: UnitTestTree = await runner.runSchematic('class', options);
133+
142134
const files: string[] = tree.files;
143135

144136
expect(
@@ -152,16 +144,13 @@ describe('Class Factory', () => {
152144
specFileSuffix: 'test',
153145
flat: true,
154146
};
155-
const tree: UnitTestTree = await runner
156-
.runSchematicAsync('class', options)
157-
.toPromise();
147+
const tree: UnitTestTree = await runner.runSchematic('class', options);
148+
158149
const files: string[] = tree.files;
159150

160151
expect(
161152
files.find((filename) => filename === '/foo.spec.ts'),
162153
).toBeUndefined();
163-
expect(
164-
files.find((filename) => filename === '/foo.test.ts'),
165-
).toBeDefined();
154+
expect(files.find((filename) => filename === '/foo.test.ts')).toBeDefined();
166155
});
167156
});

src/lib/configuration/configuration.factory.test.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ describe('Configuration Factory', () => {
1414
const options: ConfigurationOptions = {
1515
project: undefined,
1616
};
17-
const tree: UnitTestTree = await runner.runSchematicAsync('configuration', options).toPromise();
17+
const tree: UnitTestTree = await runner.runSchematic(
18+
'configuration',
19+
options,
20+
);
21+
1822
const files: string[] = tree.files;
1923
expect(
20-
files.find(filename => filename === '/nest-cli.json'),
24+
files.find((filename) => filename === '/nest-cli.json'),
2125
).not.toBeUndefined();
2226
expect(JSON.parse(tree.readContent('/nest-cli.json'))).toEqual({
2327
$schema: 'https://json.schemastore.org/nest-cli',
@@ -29,10 +33,14 @@ describe('Configuration Factory', () => {
2933
const options: ConfigurationOptions = {
3034
project: 'project',
3135
};
32-
const tree: UnitTestTree = await runner.runSchematicAsync('configuration', options).toPromise();
36+
const tree: UnitTestTree = await runner.runSchematic(
37+
'configuration',
38+
options,
39+
);
40+
3341
const files: string[] = tree.files;
3442
expect(
35-
files.find(filename => filename === '/project/nest-cli.json'),
43+
files.find((filename) => filename === '/project/nest-cli.json'),
3644
).not.toBeUndefined();
3745
expect(JSON.parse(tree.readContent('/project/nest-cli.json'))).toEqual({
3846
$schema: 'https://json.schemastore.org/nest-cli',
@@ -45,10 +53,14 @@ describe('Configuration Factory', () => {
4553
project: 'project',
4654
language: 'js',
4755
};
48-
const tree: UnitTestTree = await runner.runSchematicAsync('configuration', options).toPromise();
56+
const tree: UnitTestTree = await runner.runSchematic(
57+
'configuration',
58+
options,
59+
);
60+
4961
const files: string[] = tree.files;
5062
expect(
51-
files.find(filename => filename === '/project/nest-cli.json'),
63+
files.find((filename) => filename === '/project/nest-cli.json'),
5264
).not.toBeUndefined();
5365
expect(JSON.parse(tree.readContent('/project/nest-cli.json'))).toEqual({
5466
$schema: 'https://json.schemastore.org/nest-cli',
@@ -62,10 +74,14 @@ describe('Configuration Factory', () => {
6274
project: 'project',
6375
collection: 'foo',
6476
};
65-
const tree: UnitTestTree = await runner.runSchematicAsync('configuration', options).toPromise();
77+
const tree: UnitTestTree = await runner.runSchematic(
78+
'configuration',
79+
options,
80+
);
81+
6682
const files: string[] = tree.files;
6783
expect(
68-
files.find(filename => filename === '/project/nest-cli.json'),
84+
files.find((filename) => filename === '/project/nest-cli.json'),
6985
).not.toBeUndefined();
7086
expect(JSON.parse(tree.readContent('/project/nest-cli.json'))).toEqual({
7187
$schema: 'https://json.schemastore.org/nest-cli',

src/lib/controller/controller.factory.test.ts

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ describe('Controller Factory', () => {
2020
spec: false,
2121
flat: false,
2222
};
23-
const tree: UnitTestTree = await runner
24-
.runSchematicAsync('controller', options)
25-
.toPromise();
23+
const tree: UnitTestTree = await runner.runSchematic('controller', options);
24+
2625
const files: string[] = tree.files;
2726

2827
expect(
@@ -43,9 +42,8 @@ describe('Controller Factory', () => {
4342
name: 'bar/foo',
4443
skipImport: true,
4544
};
46-
const tree: UnitTestTree = await runner
47-
.runSchematicAsync('controller', options)
48-
.toPromise();
45+
const tree: UnitTestTree = await runner.runSchematic('controller', options);
46+
4947
const files: string[] = tree.files;
5048
expect(
5149
files.find((filename) => filename === '/bar/foo/foo.controller.ts'),
@@ -66,9 +64,8 @@ describe('Controller Factory', () => {
6664
path: 'bar',
6765
skipImport: true,
6866
};
69-
const tree: UnitTestTree = await runner
70-
.runSchematicAsync('controller', options)
71-
.toPromise();
67+
const tree: UnitTestTree = await runner.runSchematic('controller', options);
68+
7269
const files: string[] = tree.files;
7370
expect(
7471
files.find((filename) => filename === '/bar/foo/foo.controller.ts'),
@@ -88,9 +85,8 @@ describe('Controller Factory', () => {
8885
name: 'fooBar',
8986
skipImport: true,
9087
};
91-
const tree: UnitTestTree = await runner
92-
.runSchematicAsync('controller', options)
93-
.toPromise();
88+
const tree: UnitTestTree = await runner.runSchematic('controller', options);
89+
9490
const files: string[] = tree.files;
9591
expect(
9692
files.find((filename) => filename === '/foo-bar/foo-bar.controller.ts'),
@@ -112,9 +108,8 @@ describe('Controller Factory', () => {
112108
name: '_bar/foo',
113109
skipImport: true,
114110
};
115-
const tree: UnitTestTree = await runner
116-
.runSchematicAsync('controller', options)
117-
.toPromise();
111+
const tree: UnitTestTree = await runner.runSchematic('controller', options);
112+
118113
const files: string[] = tree.files;
119114
expect(
120115
files.find((filename) => filename === '/_bar/foo/foo.controller.ts'),
@@ -134,9 +129,8 @@ describe('Controller Factory', () => {
134129
name: 'barBaz/foo',
135130
skipImport: true,
136131
};
137-
const tree: UnitTestTree = await runner
138-
.runSchematicAsync('controller', options)
139-
.toPromise();
132+
const tree: UnitTestTree = await runner.runSchematic('controller', options);
133+
140134
const files: string[] = tree.files;
141135
expect(
142136
files.find((filename) => filename === '/bar-baz/foo/foo.controller.ts'),
@@ -159,9 +153,8 @@ describe('Controller Factory', () => {
159153
language: 'js',
160154
skipImport: true,
161155
};
162-
const tree: UnitTestTree = await runner
163-
.runSchematicAsync('controller', options)
164-
.toPromise();
156+
const tree: UnitTestTree = await runner.runSchematic('controller', options);
157+
165158
const files: string[] = tree.files;
166159
expect(
167160
files.find((filename) => filename === '/foo/foo.controller.js'),
@@ -180,15 +173,12 @@ describe('Controller Factory', () => {
180173
const app: ApplicationOptions = {
181174
name: '',
182175
};
183-
let tree: UnitTestTree = await runner
184-
.runSchematicAsync('application', app)
185-
.toPromise();
176+
let tree: UnitTestTree = await runner.runSchematic('application', app);
177+
186178
const options: ControllerOptions = {
187179
name: 'foo',
188180
};
189-
tree = await runner
190-
.runSchematicAsync('controller', options, tree)
191-
.toPromise();
181+
tree = await runner.runSchematic('controller', options, tree);
192182
expect(tree.readContent(normalize('/src/app.module.ts'))).toEqual(
193183
"import { Module } from '@nestjs/common';\n" +
194184
"import { AppController } from './app.controller';\n" +
@@ -207,19 +197,16 @@ describe('Controller Factory', () => {
207197
const app: ApplicationOptions = {
208198
name: '',
209199
};
210-
let tree: UnitTestTree = await runner
211-
.runSchematicAsync('application', app)
212-
.toPromise();
200+
let tree: UnitTestTree = await runner.runSchematic('application', app);
201+
213202
const module: ModuleOptions = {
214203
name: 'foo',
215204
};
216-
tree = await runner.runSchematicAsync('module', module, tree).toPromise();
205+
tree = await runner.runSchematic('module', module, tree);
217206
const options: ControllerOptions = {
218207
name: 'foo',
219208
};
220-
tree = await runner
221-
.runSchematicAsync('controller', options, tree)
222-
.toPromise();
209+
tree = await runner.runSchematic('controller', options, tree);
223210
expect(tree.readContent(normalize('/src/foo/foo.module.ts'))).toEqual(
224211
"import { Module } from '@nestjs/common';\n" +
225212
"import { FooController } from './foo.controller';\n" +
@@ -236,9 +223,8 @@ describe('Controller Factory', () => {
236223
spec: true,
237224
flat: true,
238225
};
239-
const tree: UnitTestTree = await runner
240-
.runSchematicAsync('controller', options)
241-
.toPromise();
226+
const tree: UnitTestTree = await runner.runSchematic('controller', options);
227+
242228
const files: string[] = tree.files;
243229

244230
expect(
@@ -252,9 +238,8 @@ describe('Controller Factory', () => {
252238
specFileSuffix: 'test',
253239
flat: true,
254240
};
255-
const tree: UnitTestTree = await runner
256-
.runSchematicAsync('controller', options)
257-
.toPromise();
241+
const tree: UnitTestTree = await runner.runSchematic('controller', options);
242+
258243
const files: string[] = tree.files;
259244

260245
expect(

0 commit comments

Comments
 (0)