Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/schematics/angular/guard/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"typeSeparator": {
"type": "string",
"default": "-",
"enum": ["-", "."]
"enum": ["-", "."],
"description": "The separator character to use before the type within the generated file's name. For example, if you set the option to `.`, the file will be named `example.guard.ts`."
}
},
"required": ["name", "project"]
Expand Down
3 changes: 2 additions & 1 deletion packages/schematics/angular/pipe/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
"typeSeparator": {
"type": "string",
"default": "-",
"enum": ["-", "."]
"enum": ["-", "."],
"description": "The separator character to use before the type within the generated file's name. For example, if you set the option to `.`, the file will be named `example.pipe.ts`."
}
},
"required": ["name", "project"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TestBed } from '@angular/core/testing';

import { <%= classify(name) %>Resolver } from './<%= dasherize(name) %>.resolver';
import { <%= classify(name) %>Resolver } from './<%= dasherize(name) %><%= typeSeparator %>resolver';

describe('<%= classify(name) %>Resolver', () => {
let resolver: <%= classify(name) %>Resolver;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TestBed } from '@angular/core/testing';
import { ResolveFn } from '@angular/router';

import { <%= camelize(name) %>Resolver } from './<%= dasherize(name) %>.resolver';
import { <%= camelize(name) %>Resolver } from './<%= dasherize(name) %><%= typeSeparator %>resolver';

describe('<%= camelize(name) %>Resolver', () => {
const executeResolver: ResolveFn<boolean> = (...resolverParameters) =>
Expand Down
40 changes: 31 additions & 9 deletions packages/schematics/angular/resolver/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ describe('resolver Schematic', () => {
appTree,
);
const files = tree.files;
expect(files).toContain('/projects/bar/src/app/foo.resolver.spec.ts');
expect(files).toContain('/projects/bar/src/app/foo.resolver.ts');
const fileString = tree.readContent('/projects/bar/src/app/foo.resolver.ts');
expect(files).toContain('/projects/bar/src/app/foo-resolver.spec.ts');
expect(files).toContain('/projects/bar/src/app/foo-resolver.ts');
const fileString = tree.readContent('/projects/bar/src/app/foo-resolver.ts');
expect(fileString).toContain('export class FooResolver implements Resolve<boolean>');
});

Expand All @@ -59,38 +59,60 @@ describe('resolver Schematic', () => {

const tree = await schematicRunner.runSchematic('resolver', options, appTree);
const files = tree.files;
expect(files).not.toContain('/projects/bar/src/app/foo.resolver.spec.ts');
expect(files).not.toContain('/projects/bar/src/app/foo-resolver.spec.ts');
expect(files).toContain('/projects/bar/src/app/foo-resolver.ts');
});

it('should use a `.` type separator when specified', async () => {
const options = { ...defaultOptions, typeSeparator: '.' };

const tree = await schematicRunner.runSchematic('resolver', options, appTree);
const files = tree.files;
expect(files).toContain('/projects/bar/src/app/foo.resolver.spec.ts');
expect(files).toContain('/projects/bar/src/app/foo.resolver.ts');
const specContent = tree.readContent('/projects/bar/src/app/foo.resolver.spec.ts');
expect(specContent).toContain(`'./foo.resolver'`);
});

it('should use a `-` type separator when specified', async () => {
const options = { ...defaultOptions, typeSeparator: '-' };

const tree = await schematicRunner.runSchematic('resolver', options, appTree);
const files = tree.files;
expect(files).toContain('/projects/bar/src/app/foo-resolver.spec.ts');
expect(files).toContain('/projects/bar/src/app/foo-resolver.ts');
const specContent = tree.readContent('/projects/bar/src/app/foo-resolver.spec.ts');
expect(specContent).toContain(`'./foo-resolver'`);
});

it('should respect the flat flag', async () => {
const options = { ...defaultOptions, flat: false };

const tree = await schematicRunner.runSchematic('resolver', options, appTree);
const files = tree.files;
expect(files).toContain('/projects/bar/src/app/foo/foo.resolver.spec.ts');
expect(files).toContain('/projects/bar/src/app/foo/foo.resolver.ts');
expect(files).toContain('/projects/bar/src/app/foo/foo-resolver.spec.ts');
expect(files).toContain('/projects/bar/src/app/foo/foo-resolver.ts');
});

it('should respect the sourceRoot value', async () => {
const config = JSON.parse(appTree.readContent('/angular.json'));
config.projects.bar.sourceRoot = 'projects/bar/custom';
appTree.overwrite('/angular.json', JSON.stringify(config, null, 2));
appTree = await schematicRunner.runSchematic('resolver', defaultOptions, appTree);
expect(appTree.files).toContain('/projects/bar/custom/app/foo.resolver.ts');
expect(appTree.files).toContain('/projects/bar/custom/app/foo-resolver.ts');
});

it('should create a functional resolver', async () => {
const tree = await schematicRunner.runSchematic('resolver', defaultOptions, appTree);
const fileString = tree.readContent('/projects/bar/src/app/foo.resolver.ts');
const fileString = tree.readContent('/projects/bar/src/app/foo-resolver.ts');
expect(fileString).toContain(
'export const fooResolver: ResolveFn<boolean> = (route, state) => {',
);
});

it('should create a helper function to run a functional resolver in a test', async () => {
const tree = await schematicRunner.runSchematic('resolver', defaultOptions, appTree);
const fileString = tree.readContent('/projects/bar/src/app/foo.resolver.spec.ts');
const fileString = tree.readContent('/projects/bar/src/app/foo-resolver.spec.ts');
expect(fileString).toContain(
'const executeResolver: ResolveFn<boolean> = (...resolverParameters) => ',
);
Expand Down
6 changes: 6 additions & 0 deletions packages/schematics/angular/resolver/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
"$default": {
"$source": "projectName"
}
},
"typeSeparator": {
"type": "string",
"default": "-",
"enum": ["-", "."],
"description": "The separator character to use before the type within the generated file's name. For example, if you set the option to `.`, the file will be named `example.resolver.ts`."
}
},
"required": ["name", "project"]
Expand Down