Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
38 changes: 38 additions & 0 deletions schematics/scully/src/add-blog/index_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {HostTree} from '@angular-devkit/schematics';
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
import * as path from 'path';

import {setupProject} from '../utils/test-utils';
import {Schema} from './schema';

const collectionPath = path.join(__dirname, '../collection.json');

describe('add-blog schematic', () => {
const schematicRunner = new SchematicTestRunner('scully-schematics', collectionPath);
const project = 'foo';
const defaultOptions: Schema = {};
let appTree: UnitTestTree;

beforeEach(async () => {
appTree = new UnitTestTree(new HostTree());
appTree = await setupProject(appTree, schematicRunner, project);
});

describe('when using the default options', () => {
beforeEach(async () => {
appTree = await schematicRunner.runSchematicAsync('blog', defaultOptions, appTree).toPromise();
});

it('should have run the markdown schematic', () => {
expect(
schematicRunner.tasks.some(
task =>
task.name === 'run-schematic' &&
(task.options as any).name === 'create-markdown' &&
(task.options as any).options.name === 'blog' &&
(task.options as any).options.slug === 'slug'
)
).toBe(true);
});
});
});
21 changes: 13 additions & 8 deletions schematics/scully/src/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default (options: Schema): Rule => {
addHttpClientModule(options),
addPolyfill(options),
injectIdleService(options),
runBlogSchematic(options),
runScullySchematic(options),
]);
};
Expand Down Expand Up @@ -134,17 +135,21 @@ const injectIdleService = (options: Schema) => (tree: Tree, context: SchematicCo
}
};

const runScullySchematic = (options: Schema) => (tree: Tree, context: SchematicContext) => {
const runBlogSchematic = (options: Schema) => (tree: Tree, context: SchematicContext) => {
Comment thread
d-koppenhagen marked this conversation as resolved.
const nextRules: Rule[] = [];
if (options.blog === true) {
// @ts-ignore
nextRules.push(context.addTask(new RunSchematicTask('blog', options), []));
nextRules.push((host: Tree, ctx: SchematicContext) => {
ctx.addTask(new RunSchematicTask('blog', options), []);
});
}
// tslint:disable-next-line:no-shadowed-variable
nextRules.push((tree: Tree, context: SchematicContext) => {
const installTaskId = context.addTask(new NodePackageInstallTask());
context.addTask(new RunSchematicTask('run', options), [installTaskId]);
});
return chain(nextRules);
};

const runScullySchematic = (options: Schema) => (tree: Tree, context: SchematicContext) => {
const nextRules: Rule[] = [];
nextRules.push((host: Tree, ctx: SchematicContext) => {
const installTaskId = ctx.addTask(new NodePackageInstallTask());
ctx.addTask(new RunSchematicTask('run', options), [installTaskId]);
});
return chain(nextRules);
};
20 changes: 20 additions & 0 deletions schematics/scully/src/ng-add/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,25 @@ describe('ng-add schematic', () => {
const appModuleContent = getFileContent(appTree, 'src/app/app.component.ts');
expect(appModuleContent).toMatch(/constructor*.*.private idle: IdleMonitorService/s);
});

it('should run NodePackageInstallTask', () => {
expect(schematicRunner.tasks.some(task => task.name === 'node-package')).toBe(true);
});

it('should have run the blog schematic', () => {
expect(
schematicRunner.tasks.some(
task => task.name === 'run-schematic' && (task.options as any).name === 'blog'
)
).toBe(true);
});

it('should have run the blog schematic', () => {
expect(
schematicRunner.tasks.some(
task => task.name === 'run-schematic' && (task.options as any).name === 'run'
)
).toBe(true);
});
});
});
11 changes: 10 additions & 1 deletion schematics/scully/src/scully/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('scully schematic', () => {
appTree = await schematicRunner.runSchematicAsync('scully', defaultOptions, appTree).toPromise();
});

it('add config file', () => {
it('should create the scully config file when not exists', () => {
expect(appTree.files).toContain(SCULLY_PATH);
});

Expand All @@ -39,5 +39,14 @@ describe('scully schematic', () => {
expect(scripts.scully).toEqual('scully');
expect(scripts['scully:serve']).toEqual('scully serve');
});

it(`should not override an existing cully config file'`, async () => {
Comment thread
d-koppenhagen marked this conversation as resolved.
Outdated
appTree = new UnitTestTree(new HostTree());
appTree = await setupProject(appTree, schematicRunner, project);
appTree.create(SCULLY_PATH, 'foo');
appTree = await schematicRunner.runSchematicAsync('scully', defaultOptions, appTree).toPromise();
expect(appTree.files).toContain(PACKAGE_JSON_PATH);
expect(getFileContent(appTree, SCULLY_PATH)).toEqual('foo');
});
});
});