Skip to content

Commit

Permalink
feat(pipe): 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 d4e6bbe commit 913dc16
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions src/lib/pipe/pipe.factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,38 @@ describe('Pipe Factory', () => {
'}\n',
);
});
it('should create a spec file', async () => {
const options: PipeOptions = {
name: 'foo',
spec: true,
flat: true,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('pipe', options)
.toPromise();
const files: string[] = tree.files;

expect(
files.find((filename) => filename === '/foo.pipe.spec.ts'),
).not.toBeUndefined();
});
it('should create a spec file with custom file suffix', async () => {
const options: PipeOptions = {
name: 'foo',
spec: true,
specFileSuffix: 'test',
flat: true,
};
const tree: UnitTestTree = await runner
.runSchematicAsync('pipe', options)
.toPromise();
const files: string[] = tree.files;

expect(
files.find((filename) => filename === '/foo.pipe.spec.ts'),
).toBeUndefined();
expect(
files.find((filename) => filename === '/foo.pipe.test.ts'),
).toBeDefined();
});
});
10 changes: 10 additions & 0 deletions src/lib/pipe/pipe.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ function transform(options: PipeOptions): PipeOptions {
target.name = normalizeToKebabOrSnakeCase(location.name);
target.path = normalizeToKebabOrSnakeCase(location.path);
target.language = target.language !== undefined ? target.language : 'ts';
target.specFileSuffix = normalizeToKebabOrSnakeCase(
options.specFileSuffix || 'spec',
);

target.path = target.flat
? target.path
Expand All @@ -43,6 +46,13 @@ function generate(options: PipeOptions): Source {
return (context: SchematicContext) =>
apply(url(join('./files' as Path, options.language)), [
options.spec ? noop() : filter((path) => !path.endsWith('.spec.ts')),
options.spec
? noop()
: filter((path) => {
const languageExtension = options.language || 'ts';
const suffix = `.__specFileSuffix__.${languageExtension}`;
return !path.endsWith(suffix)
}),
template({
...strings,
...options,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/pipe/pipe.schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export interface PipeOptions {
* Specifies if a spec file is generated.
*/
spec?: boolean;
/**
* Specifies the file suffix of spec files.
*/
specFileSuffix?: string;
/**
* Flag to indicate if a directory is created.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/lib/pipe/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
"type": "boolean",
"default": true,
"description": "Specifies if a spec file is generated."
},
"specFileSuffix": {
"type": "string",
"default": "spec",
"description": "Specifies the file suffix of spec files."
}
},
"required": ["name"]
Expand Down

0 comments on commit 913dc16

Please sign in to comment.