Skip to content

Commit

Permalink
test: update unit tests (devkit breaking change)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jan 8, 2024
1 parent c3bba22 commit 4e3a240
Show file tree
Hide file tree
Showing 19 changed files with 781 additions and 866 deletions.
615 changes: 331 additions & 284 deletions src/lib/application/application.factory.test.ts

Large diffs are not rendered by default.

49 changes: 19 additions & 30 deletions src/lib/class/class.factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ describe('Class Factory', () => {
spec: true,
flat: true,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('class', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('class', options);

const files: string[] = tree.files;

expect(
Expand All @@ -32,9 +31,8 @@ describe('Class Factory', () => {
flat: false,
spec: false,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('class', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('class', options);

const files: string[] = tree.files;

expect(
Expand All @@ -51,9 +49,8 @@ describe('Class Factory', () => {
flat: false,
spec: false,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('class', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('class', options);

const files: string[] = tree.files;
expect(
files.find((filename) => filename === '/baz/foo/foo.ts'),
Expand All @@ -68,9 +65,8 @@ describe('Class Factory', () => {
flat: false,
spec: false,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('class', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('class', options);

const files: string[] = tree.files;
expect(
files.find((filename) => filename === '/_foo-bar/_foo-bar.ts'),
Expand All @@ -85,9 +81,8 @@ describe('Class Factory', () => {
spec: false,
flat: false,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('class', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('class', options);

const files: string[] = tree.files;
expect(
files.find((filename) => filename === '/bar-baz/_foo/_foo.ts'),
Expand All @@ -103,9 +98,8 @@ describe('Class Factory', () => {
flat: false,
spec: false,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('class', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('class', options);

const files: string[] = tree.files;
expect(
files.find((filename) => filename === '/foo/foo.js'),
Expand All @@ -118,9 +112,8 @@ describe('Class Factory', () => {
spec: true,
flat: true,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('class', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('class', options);

const files: string[] = tree.files;

expect(
Expand All @@ -136,9 +129,8 @@ describe('Class Factory', () => {
spec: true,
flat: true,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('class', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('class', options);

const files: string[] = tree.files;

expect(
Expand All @@ -152,16 +144,13 @@ describe('Class Factory', () => {
specFileSuffix: 'test',
flat: true,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('class', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('class', options);

const files: string[] = tree.files;

expect(
files.find((filename) => filename === '/foo.spec.ts'),
).toBeUndefined();
expect(
files.find((filename) => filename === '/foo.test.ts'),
).toBeDefined();
expect(files.find((filename) => filename === '/foo.test.ts')).toBeDefined();
});
});
32 changes: 24 additions & 8 deletions src/lib/configuration/configuration.factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ describe('Configuration Factory', () => {
const options: ConfigurationOptions = {
project: undefined,
};
const tree: UnitTestTree = await runner.runSchematicAsync('configuration', options).toPromise();
const tree: UnitTestTree = await runner.runSchematic(
'configuration',
options,
);

const files: string[] = tree.files;
expect(
files.find(filename => filename === '/nest-cli.json'),
files.find((filename) => filename === '/nest-cli.json'),
).not.toBeUndefined();
expect(JSON.parse(tree.readContent('/nest-cli.json'))).toEqual({
$schema: 'https://json.schemastore.org/nest-cli',
Expand All @@ -29,10 +33,14 @@ describe('Configuration Factory', () => {
const options: ConfigurationOptions = {
project: 'project',
};
const tree: UnitTestTree = await runner.runSchematicAsync('configuration', options).toPromise();
const tree: UnitTestTree = await runner.runSchematic(
'configuration',
options,
);

const files: string[] = tree.files;
expect(
files.find(filename => filename === '/project/nest-cli.json'),
files.find((filename) => filename === '/project/nest-cli.json'),
).not.toBeUndefined();
expect(JSON.parse(tree.readContent('/project/nest-cli.json'))).toEqual({
$schema: 'https://json.schemastore.org/nest-cli',
Expand All @@ -45,10 +53,14 @@ describe('Configuration Factory', () => {
project: 'project',
language: 'js',
};
const tree: UnitTestTree = await runner.runSchematicAsync('configuration', options).toPromise();
const tree: UnitTestTree = await runner.runSchematic(
'configuration',
options,
);

const files: string[] = tree.files;
expect(
files.find(filename => filename === '/project/nest-cli.json'),
files.find((filename) => filename === '/project/nest-cli.json'),
).not.toBeUndefined();
expect(JSON.parse(tree.readContent('/project/nest-cli.json'))).toEqual({
$schema: 'https://json.schemastore.org/nest-cli',
Expand All @@ -62,10 +74,14 @@ describe('Configuration Factory', () => {
project: 'project',
collection: 'foo',
};
const tree: UnitTestTree = await runner.runSchematicAsync('configuration', options).toPromise();
const tree: UnitTestTree = await runner.runSchematic(
'configuration',
options,
);

const files: string[] = tree.files;
expect(
files.find(filename => filename === '/project/nest-cli.json'),
files.find((filename) => filename === '/project/nest-cli.json'),
).not.toBeUndefined();
expect(JSON.parse(tree.readContent('/project/nest-cli.json'))).toEqual({
$schema: 'https://json.schemastore.org/nest-cli',
Expand Down
65 changes: 25 additions & 40 deletions src/lib/controller/controller.factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ describe('Controller Factory', () => {
spec: false,
flat: false,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('controller', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('controller', options);

const files: string[] = tree.files;

expect(
Expand All @@ -43,9 +42,8 @@ describe('Controller Factory', () => {
name: 'bar/foo',
skipImport: true,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('controller', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('controller', options);

const files: string[] = tree.files;
expect(
files.find((filename) => filename === '/bar/foo/foo.controller.ts'),
Expand All @@ -66,9 +64,8 @@ describe('Controller Factory', () => {
path: 'bar',
skipImport: true,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('controller', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('controller', options);

const files: string[] = tree.files;
expect(
files.find((filename) => filename === '/bar/foo/foo.controller.ts'),
Expand All @@ -88,9 +85,8 @@ describe('Controller Factory', () => {
name: 'fooBar',
skipImport: true,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('controller', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('controller', options);

const files: string[] = tree.files;
expect(
files.find((filename) => filename === '/foo-bar/foo-bar.controller.ts'),
Expand All @@ -112,9 +108,8 @@ describe('Controller Factory', () => {
name: '_bar/foo',
skipImport: true,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('controller', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('controller', options);

const files: string[] = tree.files;
expect(
files.find((filename) => filename === '/_bar/foo/foo.controller.ts'),
Expand All @@ -134,9 +129,8 @@ describe('Controller Factory', () => {
name: 'barBaz/foo',
skipImport: true,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('controller', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('controller', options);

const files: string[] = tree.files;
expect(
files.find((filename) => filename === '/bar-baz/foo/foo.controller.ts'),
Expand All @@ -159,9 +153,8 @@ describe('Controller Factory', () => {
language: 'js',
skipImport: true,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('controller', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('controller', options);

const files: string[] = tree.files;
expect(
files.find((filename) => filename === '/foo/foo.controller.js'),
Expand All @@ -180,15 +173,12 @@ describe('Controller Factory', () => {
const app: ApplicationOptions = {
name: '',
};
let tree: UnitTestTree = await runner
.runSchematicAsync('application', app)
.toPromise();
let tree: UnitTestTree = await runner.runSchematic('application', app);

const options: ControllerOptions = {
name: 'foo',
};
tree = await runner
.runSchematicAsync('controller', options, tree)
.toPromise();
tree = await runner.runSchematic('controller', options, tree);
expect(tree.readContent(normalize('/src/app.module.ts'))).toEqual(
"import { Module } from '@nestjs/common';\n" +
"import { AppController } from './app.controller';\n" +
Expand All @@ -207,19 +197,16 @@ describe('Controller Factory', () => {
const app: ApplicationOptions = {
name: '',
};
let tree: UnitTestTree = await runner
.runSchematicAsync('application', app)
.toPromise();
let tree: UnitTestTree = await runner.runSchematic('application', app);

const module: ModuleOptions = {
name: 'foo',
};
tree = await runner.runSchematicAsync('module', module, tree).toPromise();
tree = await runner.runSchematic('module', module, tree);
const options: ControllerOptions = {
name: 'foo',
};
tree = await runner
.runSchematicAsync('controller', options, tree)
.toPromise();
tree = await runner.runSchematic('controller', options, tree);
expect(tree.readContent(normalize('/src/foo/foo.module.ts'))).toEqual(
"import { Module } from '@nestjs/common';\n" +
"import { FooController } from './foo.controller';\n" +
Expand All @@ -236,9 +223,8 @@ describe('Controller Factory', () => {
spec: true,
flat: true,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('controller', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('controller', options);

const files: string[] = tree.files;

expect(
Expand All @@ -252,9 +238,8 @@ describe('Controller Factory', () => {
specFileSuffix: 'test',
flat: true,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('controller', options)
.toPromise();
const tree: UnitTestTree = await runner.runSchematic('controller', options);

const files: string[] = tree.files;

expect(
Expand Down
Loading

0 comments on commit 4e3a240

Please sign in to comment.