Skip to content

Commit

Permalink
feat(sub-app): add spec file suffix option
Browse files Browse the repository at this point in the history
  • Loading branch information
garritfra committed Jun 19, 2022
1 parent da10bce commit 0c5dbf5
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/lib/sub-app/files/ts/tsconfig.app.json
Expand Up @@ -5,5 +5,5 @@
"outDir": "../../dist/apps/<%= name %>"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
"exclude": ["node_modules", "dist", "test", "**/*<%= specFileSuffix %>.ts"]
}
5 changes: 5 additions & 0 deletions src/lib/sub-app/schema.json
Expand Up @@ -26,6 +26,11 @@
"type": "string",
"format": "path",
"description": "Applications root directory."
},
"specFileSuffix": {
"type": "string",
"default": "spec",
"description": "Specifies the file suffix of spec files."
}
},
"required": ["name"]
Expand Down
38 changes: 30 additions & 8 deletions src/lib/sub-app/sub-app.factory.test.ts
Expand Up @@ -18,7 +18,7 @@ describe('SubApp Factory', () => {
.runSchematicAsync('sub-app', options)
.toPromise();
const files: string[] = tree.files;
expect(files).toEqual([
expect(files.sort()).toEqual([
'/nest-cli.json',
'/apps/nestjs-schematics/tsconfig.app.json',
'/apps/project/tsconfig.app.json',
Expand All @@ -29,7 +29,7 @@ describe('SubApp Factory', () => {
'/apps/project/src/project.service.ts',
'/apps/project/test/app.e2e-spec.ts',
'/apps/project/test/jest-e2e.json',
]);
].sort());
});
it('should manage name to normalize', async () => {
const options: SubAppOptions = {
Expand All @@ -39,7 +39,7 @@ describe('SubApp Factory', () => {
.runSchematicAsync('sub-app', options)
.toPromise();
const files: string[] = tree.files;
expect(files).toEqual([
expect(files.sort()).toEqual([
'/nest-cli.json',
'/apps/nestjs-schematics/tsconfig.app.json',
'/apps/awesome-project/tsconfig.app.json',
Expand All @@ -50,7 +50,7 @@ describe('SubApp Factory', () => {
'/apps/awesome-project/src/awesome-project.service.ts',
'/apps/awesome-project/test/app.e2e-spec.ts',
'/apps/awesome-project/test/jest-e2e.json',
]);
].sort());
});
it("should keep underscores in sub-app's path and file name", async () => {
const options: SubAppOptions = {
Expand All @@ -60,7 +60,7 @@ describe('SubApp Factory', () => {
.runSchematicAsync('sub-app', options)
.toPromise();
const files: string[] = tree.files;
expect(files).toEqual([
expect(files.sort()).toEqual([
'/nest-cli.json',
'/apps/nestjs-schematics/tsconfig.app.json',
'/apps/_project/tsconfig.app.json',
Expand All @@ -71,7 +71,7 @@ describe('SubApp Factory', () => {
'/apps/_project/src/_project.service.ts',
'/apps/_project/test/app.e2e-spec.ts',
'/apps/_project/test/jest-e2e.json',
]);
].sort());
});
it('should manage javascript files', async () => {
const options: SubAppOptions = {
Expand All @@ -82,7 +82,7 @@ describe('SubApp Factory', () => {
.runSchematicAsync('sub-app', options)
.toPromise();
const files: string[] = tree.files;
expect(files).toEqual([
expect(files.sort()).toEqual([
'/nest-cli.json',
'/apps/nestjs-schematics/.babelrc',
'/apps/nestjs-schematics/index.js',
Expand All @@ -97,6 +97,28 @@ describe('SubApp Factory', () => {
'/apps/project/src/main.js',
'/apps/project/test/app.e2e-spec.js',
'/apps/project/test/jest-e2e.json',
]);
].sort());
});
it('should generate spec files with custom suffix', async () => {
const options: SubAppOptions = {
name: 'project',
specFileSuffix: 'test',
};
const tree: UnitTestTree = await runner
.runSchematicAsync('sub-app', options)
.toPromise();
const files: string[] = tree.files;
expect(files.sort()).toEqual([
'/nest-cli.json',
'/apps/nestjs-schematics/tsconfig.app.json',
'/apps/project/tsconfig.app.json',
'/apps/project/src/main.ts',
'/apps/project/src/project.controller.test.ts',
'/apps/project/src/project.controller.ts',
'/apps/project/src/project.module.ts',
'/apps/project/src/project.service.ts',
'/apps/project/test/jest-e2e.json',
'/apps/project/test/app.e2e-test.ts',
].sort());
});
});
4 changes: 4 additions & 0 deletions src/lib/sub-app/sub-app.schema.d.ts
Expand Up @@ -17,5 +17,9 @@ export interface SubAppOptions {
* Applications root directory
*/
rootDir?: string | Path;
/**
* Specifies the file suffix of spec files.
*/
specFileSuffix?: string;
sourceRoot?: string;
}
2 changes: 1 addition & 1 deletion src/lib/sub-app/workspace/ts/tsconfig.app.json
Expand Up @@ -5,5 +5,5 @@
"outDir": "../../dist/apps/<%= name %>"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
"exclude": ["node_modules", "dist", "test", "**/*<%= specFileSuffix %>.ts"]
}

0 comments on commit 0c5dbf5

Please sign in to comment.