This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Tree } from '@angular-devkit/schematics'; | |
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; | |
import * as path from 'path'; | |
const collectionPath = path.join(__dirname, '../collection.json'); | |
describe('simple-schematic', () => { | |
it('works', () => { | |
const runner = new SchematicTestRunner('schematics', collectionPath); | |
const tree = runner.runSchematic('simple-schematic', {}, Tree.empty()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const angularCollectionPath = require.resolve( | |
'../../node_modules/@schematics/angular/collection.json' | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const schematicRunner = new SchematicTestRunner( | |
'@schematics/angular', angularCollectionPath); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Schema as WorkspaceOptions} from '@schematics/angular/workspace/schema'; | |
import {Schema as ApplicationOptions} from '@schematics/angular/application/schema'; | |
... | |
const workspaceOptions: WorkspaceOptions = { | |
name: 'workspace', | |
newProjectRoot: 'projects', | |
version: '6.0.0', | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let appTree: UnitTestTree; | |
beforeEach(() => { | |
appTree = testRunner.runExternalSchematic( | |
'@schematics/angular', 'workspace', workspaceOptions); | |
appTree = testRunner.runExternalSchematic( | |
'@schematics/angular', 'application', appOptions, appTree); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('fails with missing tree', () => { | |
expect(() => testRunner.runSchematic( | |
'simple-schematic', | |
{name: "test"}, | |
Tree.empty())).toThrow(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('fails with missing params', () => { | |
expect(() => testRunner.runSchematic( | |
'simple-schematic', | |
{}, | |
appTree)).toThrowError(InvalidInputOptions, | |
'Schematic input does not validate against the Schema: {"spec":true,"flat":false}\n'+ | |
'Errors:\n\n'+ | |
' Data path "" should have required property \'name\'.'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('works', () => { | |
const tree = testRunner.runSchematic('simple-schematic', { | |
name: "test" | |
}, appTree); | |
//[see assertions below] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expect(tree.files).toEqual([ | |
"/README.md", | |
"/angular.json", | |
"/package.json", | |
"/tsconfig.json", | |
"/tslint.json", | |
"/.editorconfig", | |
"/.gitignore", | |
... | |
"/projects/bar/src/app/test/test.spec.ts", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expect(tree.files).toContain("/projects/bar/src/app/test/test.spec.ts"); | |
expect(tree.files).toContain("/projects/bar/src/app/test/test.ts"); |
OlderNewer