Skip to content

Commit c06c9b6

Browse files
author
monica.lopez-gris
committed
test: update tests schematic
1 parent 226ecce commit c06c9b6

5 files changed

Lines changed: 136 additions & 196 deletions

File tree

packages/schematics/src/lib/allinone/all-in-one.factory_spec.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,45 @@
1-
import {
2-
SchematicTestRunner
3-
} from '@angular-devkit/schematics/testing';
1+
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
42
import * as path from 'path';
53

64
describe('Auth Factory', () => {
7-
const runner: SchematicTestRunner = new SchematicTestRunner(
8-
'.',
9-
path.join(process.cwd(), 'src/collection.json'),
10-
);
5+
const runner: SchematicTestRunner = new SchematicTestRunner('.', path.join(process.cwd(), 'src/collection.json'));
116
it('should set on module app', async () => {
127
const optionsApp: object = {
138
name: 'path',
149
};
1510
const optionsModule: object = {
16-
path: 'path'
11+
path: 'path',
1712
};
1813
let app;
1914
app = await runner.runSchematicAsync('application', optionsApp);
2015
app.subscribe(async tree => {
2116
app = await runner.runSchematicAsync('auth-jwt', optionsModule, tree);
2217
app.subscribe(tree => {
2318
const files: string[] = tree.files;
24-
expect(
25-
files.find(filename => filename === '/path/src/app/core/core.module.ts'),
26-
).toBeDefined();
19+
expect(files.find(filename => filename === '/path/src/app/core/core.module.ts')).toBeDefined();
2720
expect(tree.readContent('/path/src/app/core/core.module.ts')).toEqual(
2821
"import { Global, Module } from '@nestjs/common';\n" +
29-
"import { ClassSerializerInterceptor } from '@devon4node/common/serializer';\n" +
30-
"import { APP_INTERCEPTOR, APP_FILTER } from '@nestjs/core';\n" +
31-
"import { WinstonLogger } from '../shared/logger/winston.logger';\n" +
32-
"import { BusinessLogicFilter } from '../shared/filters/business-logic.filter';\n" +
33-
"import { AuthModule } from './auth/auth.module';\n" +
34-
"import { UserModule } from './user/user.module';\n" +
35-
"\n" +
36-
"@Global()\n" +
37-
"@Module({\n" +
38-
" imports: [UserModule, AuthModule],\n" +
39-
" controllers: [],\n" +
40-
" providers: [\n" +
41-
" { provide: APP_FILTER, useClass: BusinessLogicFilter },\n" +
42-
" { provide: APP_INTERCEPTOR, useClass: ClassSerializerInterceptor },\n" +
43-
" WinstonLogger,\n" +
44-
" ],\n" +
45-
" exports: [UserModule, AuthModule, WinstonLogger],\n" +
46-
"})\n" +
47-
"export class CoreModule {}\n"
22+
"import { ClassSerializerInterceptor } from '@devon4node/common/serializer';\n" +
23+
"import { APP_INTERCEPTOR, APP_FILTER } from '@nestjs/core';\n" +
24+
"import { WinstonLogger } from '../shared/logger/winston.logger';\n" +
25+
"import { BusinessLogicFilter } from '../shared/filters/business-logic.filter';\n" +
26+
"import { AuthModule } from './auth/auth.module';\n" +
27+
"import { UserModule } from './user/user.module';\n" +
28+
'\n' +
29+
'@Global()\n' +
30+
'@Module({\n' +
31+
' imports: [UserModule, AuthModule],\n' +
32+
' controllers: [],\n' +
33+
' providers: [\n' +
34+
' { provide: APP_FILTER, useClass: BusinessLogicFilter },\n' +
35+
' { provide: APP_INTERCEPTOR, useClass: ClassSerializerInterceptor },\n' +
36+
' WinstonLogger,\n' +
37+
' ],\n' +
38+
' exports: [UserModule, AuthModule, WinstonLogger],\n' +
39+
'})\n' +
40+
'export class CoreModule {}\n',
4841
);
49-
})
50-
})
42+
});
43+
});
5144
});
52-
});
45+
});

packages/schematics/src/lib/config-module/config-module.factory_spec.ts

Lines changed: 50 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
22
import * as path from 'path';
33

44
describe('Config-module', () => {
5-
const runner: SchematicTestRunner = new SchematicTestRunner(
6-
'.',
7-
path.join(process.cwd(), 'src/collection.json'),
8-
);
5+
const runner: SchematicTestRunner = new SchematicTestRunner('.', path.join(process.cwd(), 'src/collection.json'));
96
it('should manage path', async () => {
107
const optionsApp: object = {
118
name: 'foo',
@@ -19,32 +16,29 @@ describe('Config-module', () => {
1916
app = runner.runSchematicAsync('config-module', optionsModule, tree);
2017
app.subscribe(tree => {
2118
const files: string[] = tree.files;
22-
expect(
23-
files.find(filename => filename === '/foo/src/main.ts'),
24-
).toBeDefined();
19+
expect(files.find(filename => filename === '/foo/src/main.ts')).toBeDefined();
2520
expect(tree.readContent('/foo/src/main.ts')).toEqual(
2621
"import { NestFactory } from '@nestjs/core';\n" +
27-
"import { AppModule } from './app/app.module';\n" +
28-
"import { WinstonLogger } from './app/shared/logger/winston.logger';\n" +
29-
"import { ValidationPipe } from '@nestjs/common';\n" +
30-
"import { ConfigService } from '@devon4node/config';\n" +
31-
"\n" +
32-
"async function bootstrap(): Promise<void> {\n" +
33-
" const app = await NestFactory.create(AppModule, { logger: new WinstonLogger() });\n" +
34-
" const configModule = app.get(ConfigService);\n" +
35-
" app.useGlobalPipes(\n" +
36-
" new ValidationPipe({\n" +
37-
" transform: true,\n" +
38-
" }),\n" +
39-
" );\n" +
40-
" app.setGlobalPrefix(configModule.values.globalPrefix);\n" +
41-
" await app.listen(configModule.values.port);\n" +
42-
"}\n" +
43-
"bootstrap();\n"
22+
"import { AppModule } from './app/app.module';\n" +
23+
"import { WinstonLogger } from './app/shared/logger/winston.logger';\n" +
24+
"import { ValidationPipe } from '@nestjs/common';\n" +
25+
"import { ConfigService } from '@devon4node/config';\n" +
26+
'\n' +
27+
'async function bootstrap(): Promise<void> {\n' +
28+
' const app = await NestFactory.create(AppModule, { logger: new WinstonLogger() });\n' +
29+
' const configModule = app.get(ConfigService);\n' +
30+
' app.useGlobalPipes(\n' +
31+
' new ValidationPipe({\n' +
32+
' transform: true,\n' +
33+
' }),\n' +
34+
' );\n' +
35+
' app.setGlobalPrefix(configModule.values.globalPrefix);\n' +
36+
' await app.listen(configModule.values.port);\n' +
37+
'}\n' +
38+
'bootstrap();\n',
4439
);
45-
})
46-
})
47-
40+
});
41+
});
4842
});
4943
it('should manage declaration in core module', async () => {
5044
const optionsApp: object = {
@@ -59,37 +53,35 @@ describe('Config-module', () => {
5953
app = runner.runSchematicAsync('config-module', optionsModule, tree);
6054
app.subscribe(tree => {
6155
const files: string[] = tree.files;
62-
expect(
63-
files.find(filename => filename === '/src/app/core/core.module.ts')
64-
).toBeDefined();
56+
expect(files.find(filename => filename === '/src/app/core/core.module.ts')).toBeDefined();
6557
expect(tree.readContent('/src/app/core/core.module.ts')).toEqual(
6658
"import { Global, Module } from '@nestjs/common';\n" +
67-
"import { ClassSerializerInterceptor } from '@devon4node/common/serializer';\n" +
68-
"import { APP_INTERCEPTOR, APP_FILTER } from '@nestjs/core';\n" +
69-
"import { WinstonLogger } from '../shared/logger/winston.logger';\n" +
70-
"import { BusinessLogicFilter } from '../shared/filters/business-logic.filter';\n" +
71-
"import { ConfigModule } from '@devon4node/config';\n" +
72-
"import { Config } from '../shared/model/config/config.model';\n" +
73-
"\n" +
74-
"@Global()\n" +
75-
"@Module({\n" +
76-
" imports: [\n" +
77-
" ConfigModule.forRoot({\n" +
78-
" configPrefix: 'devon4node',\n" +
79-
" configType: Config,\n" +
80-
" }),\n" +
81-
" ],\n" +
82-
" controllers: [],\n" +
83-
" providers: [\n" +
84-
" { provide: APP_FILTER, useClass: BusinessLogicFilter },\n" +
85-
" { provide: APP_INTERCEPTOR, useClass: ClassSerializerInterceptor },\n" +
86-
" WinstonLogger,\n" +
87-
" ],\n" +
88-
" exports: [ConfigModule, WinstonLogger],\n" +
89-
"})\n" +
90-
"export class CoreModule {}\n"
91-
)
92-
})
93-
})
59+
"import { ClassSerializerInterceptor } from '@devon4node/common/serializer';\n" +
60+
"import { APP_INTERCEPTOR, APP_FILTER } from '@nestjs/core';\n" +
61+
"import { WinstonLogger } from '../shared/logger/winston.logger';\n" +
62+
"import { BusinessLogicFilter } from '../shared/filters/business-logic.filter';\n" +
63+
"import { ConfigModule } from '@devon4node/config';\n" +
64+
"import { Config } from '../shared/model/config/config.model';\n" +
65+
'\n' +
66+
'@Global()\n' +
67+
'@Module({\n' +
68+
' imports: [\n' +
69+
' ConfigModule.forRoot({\n' +
70+
" configPrefix: 'devon4node',\n" +
71+
' configType: Config,\n' +
72+
' }),\n' +
73+
' ],\n' +
74+
' controllers: [],\n' +
75+
' providers: [\n' +
76+
' { provide: APP_FILTER, useClass: BusinessLogicFilter },\n' +
77+
' { provide: APP_INTERCEPTOR, useClass: ClassSerializerInterceptor },\n' +
78+
' WinstonLogger,\n' +
79+
' ],\n' +
80+
' exports: [ConfigModule, WinstonLogger],\n' +
81+
'})\n' +
82+
'export class CoreModule {}\n',
83+
);
84+
});
85+
});
9486
});
95-
});
87+
});

packages/schematics/src/lib/controller/controller.factory_spec.ts

Lines changed: 43 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,81 +3,58 @@ import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
33
import * as path from 'path';
44

55
describe('Controller Factory', () => {
6-
const runner: SchematicTestRunner = new SchematicTestRunner(
7-
'.',
8-
path.join(process.cwd(), 'src/collection.json'),
9-
);
6+
const runner: SchematicTestRunner = new SchematicTestRunner('.', path.join(process.cwd(), 'src/collection.json'));
107
it('should manage name only', () => {
118
const optionsApp: object = {
129
name: 'project',
1310
spec: false,
1411
};
15-
let app;
16-
app = runner.runSchematicAsync('controller', optionsApp);
17-
app.subscribe(tree => {
12+
runner.runSchematicAsync('controller', optionsApp).subscribe(tree => {
1813
const files: string[] = tree.files;
19-
expect(
20-
files.find(filename => filename === '/src/app/controllers/project.controller.ts'),
21-
).toBeDefined();
22-
expect(
23-
files.find(filename => filename === '/src/app/controllers/project.controller.spec.ts'),
24-
).not.toBeDefined();
14+
expect(files.find(filename => filename === '/src/app/controllers/project.controller.ts')).toBeDefined();
15+
expect(files.find(filename => filename === '/src/app/controllers/project.controller.spec.ts')).not.toBeDefined();
2516
expect(tree.readContent('/src/app/controllers/project.controller.ts')).toEqual(
2617
"import { Controller } from '@nestjs/common';\n" +
27-
'\n' +
28-
"@Controller('projects')\n" +
29-
'export class ProjectController {}\n',
18+
'\n' +
19+
"@Controller('projects')\n" +
20+
'export class ProjectController {}\n',
3021
);
31-
})
32-
22+
});
3323
});
3424
it('should manage name and path', () => {
3525
const optionsApp: object = {
3626
name: 'foo',
3727
path: 'bar',
3828
skipImport: true,
3929
};
40-
runner.runSchematicAsync('controller', optionsApp)
41-
.subscribe(tree => {
42-
const files: string[] = tree.files;
43-
expect(
44-
files.find(filename => filename === '/bar/src/app/controllers/foo.controller.ts'),
45-
).toBeDefined();
46-
expect(
47-
files.find(filename => filename === '/bar/src/app/controllers/foo.controller.spec.ts'),
48-
).toBeDefined();
49-
expect(tree.readContent('/bar/src/app/controllers/foo.controller.ts')).toEqual(
50-
"import { Controller } from '@nestjs/common';\n" +
30+
runner.runSchematicAsync('controller', optionsApp).subscribe(tree => {
31+
const files: string[] = tree.files;
32+
expect(files.find(filename => filename === '/bar/src/app/controllers/foo.controller.ts')).toBeDefined();
33+
expect(files.find(filename => filename === '/bar/src/app/controllers/foo.controller.spec.ts')).toBeDefined();
34+
expect(tree.readContent('/bar/src/app/controllers/foo.controller.ts')).toEqual(
35+
"import { Controller } from '@nestjs/common';\n" +
5136
'\n' +
5237
"@Controller('foos')\n" +
5338
'export class FooController {}\n',
54-
);
55-
});
39+
);
40+
});
5641
});
5742
it('should manage name to dasherize', () => {
5843
const optionsApp: object = {
5944
name: 'fooBar',
6045
skipImport: true,
6146
};
62-
runner.runSchematicAsync('controller', optionsApp)
63-
.subscribe(tree => {
64-
const files: string[] = tree.files;
65-
expect(
66-
files.find(filename => filename === '/src/app/controllers/foo-bar.controller.ts'),
67-
).toBeDefined();
68-
expect(
69-
files.find(
70-
filename => filename === '/src/app/controllers/foo-bar.controller.spec.ts',
71-
),
72-
).toBeDefined();
73-
expect(tree.readContent('/src/app/controllers/foo-bar.controller.ts')).toEqual(
74-
"import { Controller } from '@nestjs/common';\n" +
47+
runner.runSchematicAsync('controller', optionsApp).subscribe(tree => {
48+
const files: string[] = tree.files;
49+
expect(files.find(filename => filename === '/src/app/controllers/foo-bar.controller.ts')).toBeDefined();
50+
expect(files.find(filename => filename === '/src/app/controllers/foo-bar.controller.spec.ts')).toBeDefined();
51+
expect(tree.readContent('/src/app/controllers/foo-bar.controller.ts')).toEqual(
52+
"import { Controller } from '@nestjs/common';\n" +
7553
'\n' +
7654
"@Controller('foo-bars')\n" +
7755
'export class FooBarController {}\n',
78-
);
79-
})
80-
56+
);
57+
});
8158
});
8259
it('should manage declaration in app module', () => {
8360
const optionsApp: object = {
@@ -86,25 +63,23 @@ describe('Controller Factory', () => {
8663
const optionsModule: object = {
8764
name: 'foo',
8865
};
89-
runner.runSchematicAsync('application', optionsApp)
90-
.subscribe(tree => {
91-
runner.runSchematicAsync('controller', optionsModule, tree)
92-
.subscribe(tree => {
93-
expect(tree.readContent(normalize('/src/app/app.module.ts'))).toEqual(
94-
"import { Module } from '@nestjs/common';\n" +
95-
"import { AppController } from './app.controller';\n" +
96-
"import { AppService } from './app.service';\n" +
97-
"import { CoreModule } from './core/core.module';\n" +
98-
"import { FooController } from './controllers/foo.controller';\n" +
99-
'\n' +
100-
'@Module({\n' +
101-
' imports: [CoreModule],\n' +
102-
' controllers: [FooController, AppController],\n' +
103-
' providers: [AppService],\n' +
104-
'})\n' +
105-
'export class AppModule {}\n',
106-
);
107-
})
108-
})
66+
runner.runSchematicAsync('application', optionsApp).subscribe(tree => {
67+
runner.runSchematicAsync('controller', optionsModule, tree).subscribe(tree => {
68+
expect(tree.readContent(normalize('/src/app/app.module.ts'))).toEqual(
69+
"import { Module } from '@nestjs/common';\n" +
70+
"import { AppController } from './app.controller';\n" +
71+
"import { AppService } from './app.service';\n" +
72+
"import { CoreModule } from './core/core.module';\n" +
73+
"import { FooController } from './controllers/foo.controller';\n" +
74+
'\n' +
75+
'@Module({\n' +
76+
' imports: [CoreModule],\n' +
77+
' controllers: [FooController, AppController],\n' +
78+
' providers: [AppService],\n' +
79+
'})\n' +
80+
'export class AppModule {}\n',
81+
);
82+
});
83+
});
10984
});
110-
});
85+
});

0 commit comments

Comments
 (0)