本文整理汇总了TypeScript中@angular-devkit/schematics/testing.SchematicTestRunner类的典型用法代码示例。如果您正苦于以下问题:TypeScript SchematicTestRunner类的具体用法?TypeScript SchematicTestRunner怎么用?TypeScript SchematicTestRunner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SchematicTestRunner类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('NgAlainSchematic: plugin', () => {
let runner: SchematicTestRunner;
let tree: UnitTestTree;
describe(`[g2]`, () => {
beforeEach(() => ({ runner, tree } = createAlainApp({ g2: true })));
describe('when add', () => {
it(`should add dependencies`, () => {
const json = JSON.parse(tree.readContent('package.json'));
expect(json.dependencies['@antv/g2']).toBeDefined();
});
it(`should add scripts`, () => {
const json = JSON.parse(tree.readContent('angular.json'));
const scripts: string[] = json.projects.foo.architect.build.options.scripts || [];
expect(scripts.filter(w => w.includes('g2')).length).toBeGreaterThan(0);
});
});
describe('when remove', () => {
beforeEach(() =>
runner.runSchematic('plugin', { name: 'g2', type: 'remove' }, tree));
it(`should add dependencies`, () => {
const json = JSON.parse(tree.readContent('package.json'));
expect(json.dependencies['@antv/g2']).not.toBeDefined();
});
it(`should add scripts`, () => {
const json = JSON.parse(tree.readContent('angular.json'));
const scripts: string[] = json.projects.foo.architect.build.options.scripts || [];
expect(scripts.filter(w => w.includes('g2')).length).toBe(0);
});
});
});
describe(`[codeStyle]`, () => {
beforeEach(() => ({ runner, tree } = createAlainApp({ codeStyle: true })));
describe('when add', () => {
it(`should add precommit`, () => {
const json = JSON.parse(tree.readContent('package.json'));
expect(json.scripts.precommit).not.toBeUndefined();
});
});
describe('when remove', () => {
beforeEach(() =>
runner.runSchematic(
'plugin',
{ name: 'codeStyle', type: 'remove' },
tree,
));
it(`should remove precommit`, () => {
const json = JSON.parse(tree.readContent('package.json'));
expect(json.scripts.precommit).toBeUndefined();
});
});
});
describe(`[npm]`, () => {
const npmrc = '/.npmrc';
beforeEach(() => ({ runner, tree } = createAlainApp({ npm: true })));
describe('when add', () => {
it(`should add .npmrc`, () => {
expect(tree.exists(npmrc)).toBe(true);
expect(tree.readContent(npmrc)).toContain('taobao.org');
});
});
describe('when remove', () => {
beforeEach(() =>
runner.runSchematic(
'plugin',
{ name: 'npm', type: 'remove' },
tree,
));
it(`should remove .npmrc`, () => {
expect(tree.exists(npmrc)).toBe(false);
});
});
});
describe(`[yarn]`, () => {
beforeEach(() => ({ runner, tree } = createAlainApp({ yarn: true })));
describe('when add', () => {
it(`should add devDependencies`, () => {
const json = JSON.parse(tree.readContent('package.json'));
expect(json.devDependencies['less']).not.toBeUndefined();
expect(json.devDependencies['less-loader']).not.toBeUndefined();
});
});
describe('when remove', () => {
//.........这里部分代码省略.........
开发者ID:wexz,项目名称:delon,代码行数:101,代码来源:index_spec.ts
示例2: describe
describe('ng-add-schematic', () => {
const collectionPath = join(__dirname, '../collection.json');
const schematicRunner = new SchematicTestRunner('schematics', collectionPath);
const projectPath = getTestProjectPath();
let appTree: UnitTestTree;
beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
});
it('should update package.json', () => {
const tree = schematicRunner.runSchematic('ng-add', {}, appTree);
const packageJson = JSON.parse(getFileContent(tree, '/package.json'));
expect(packageJson.dependencies['@angular/forms']).toBeDefined();
expect(packageJson.dependencies['@ngx-formly/core']).toBeDefined();
});
it('should not add a theme by default to package.json', () => {
const tree = schematicRunner.runSchematic('ng-add', {}, appTree);
const packageJson = JSON.parse(getFileContent(tree, '/package.json'));
// @TODO: list of themes should probably be retrieved from some config file
['material', 'bootstrap', 'ionic', 'primeng', 'kendo'].forEach(theme => {
expect(packageJson.dependencies[`@ngx-formly/${theme}`]).toBeUndefined();
});
});
it('should skip package.json update', () => {
const options = { skipPackageJson: true } as Schema;
const tree = schematicRunner.runSchematic('ng-add', options, appTree);
const packageJson = JSON.parse(getFileContent(tree, '/package.json'));
expect(packageJson.dependencies['@ngx-formly/core']).toBeUndefined();
});
it('should add to root app module', () => {
const tree = schematicRunner.runSchematic('ng-add', {}, appTree);
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
expect(content).toMatch(
// tslint:disable-next-line:trailing-comma
/import { FormlyModule } from '@ngx-formly\/core';/
);
expect(content).toMatch(
// tslint:disable-next-line:trailing-comma
/FormlyModule.forRoot\(\)/
);
expect(content).toMatch(
// tslint:disable-next-line:trailing-comma
/import { ReactiveFormsModule } from '@angular\/forms';/
);
expect(content).toMatch(
// tslint:disable-next-line:trailing-comma
/ReactiveFormsModule,/
);
});
it('should add UI theme to package.json', () => {
const tree = schematicRunner.runSchematic('ng-add', {
uiTheme: 'bootstrap',
}, appTree);
const packageJson = JSON.parse(getFileContent(tree, '/package.json'));
expect(packageJson.dependencies['@ngx-formly/bootstrap']).toBeDefined();
});
it('should add UI theme to root app module', () => {
const tree = schematicRunner.runSchematic('ng-add', {
uiTheme: 'bootstrap',
}, appTree);
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
expect(content).toMatch(
// tslint:disable-next-line:trailing-comma
/import { FormlyBootstrapModule } from '@ngx-formly\/bootstrap';/
);
expect(content).toMatch(
// tslint:disable-next-line:trailing-comma
/FormlyBootstrapModule/
);
});
it('should add to any module', () => {
const fooModule = `${projectPath}/src/app/foo.module.ts`;
appTree.create(fooModule, `
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
@NgModule({
imports: [],
declarations: []
})
export class FooModule { }
`);
const tree = schematicRunner.runSchematic('ng-add', {
//.........这里部分代码省略.........
开发者ID:formly-js,项目名称:ng2-formly,代码行数:101,代码来源:index_spec.ts
示例3: describe
describe('ng-add schematic', () => {
const defaultOptions = {name: 'demo'};
let host: UnitTestTree;
let schematicRunner: SchematicTestRunner;
beforeEach(() => {
host = new UnitTestTree(new HostTree());
host.create('package.json', JSON.stringify({
name: 'demo',
dependencies: {
'@angular/core': '1.2.3',
'rxjs': '~6.3.3',
},
devDependencies: {
'typescript': '3.2.2',
},
}));
host.create('tsconfig.json', JSON.stringify({
compileOnSave: false,
compilerOptions: {
baseUrl: './',
outDir: './dist/out-tsc',
}
}));
host.create('angular.json', JSON.stringify({
projects: {
'demo': {
architect: {
build: {},
serve: {},
test: {},
'extract-i18n': {
builder: '@angular-devkit/build-angular:extract-i18n',
},
},
},
'demo-e2e': {
architect: {
e2e: {},
lint: {
builder: '@angular-devkit/build-angular:tslint',
},
},
},
},
}));
schematicRunner =
new SchematicTestRunner('@angular/bazel', require.resolve('../collection.json'));
});
it('throws if package.json is not found', () => {
expect(host.files).toContain('/package.json');
host.delete('/package.json');
expect(() => schematicRunner.runSchematic('ng-add', defaultOptions))
.toThrowError('Could not find package.json');
});
it('throws if angular.json is not found', () => {
expect(host.files).toContain('/angular.json');
host.delete('/angular.json');
expect(() => schematicRunner.runSchematic('ng-add', defaultOptions, host))
.toThrowError('Could not find angular.json');
});
it('should add @angular/bazel to package.json dependencies', () => {
host = schematicRunner.runSchematic('ng-add', defaultOptions, host);
const {files} = host;
expect(files).toContain('/package.json');
const content = host.readContent('/package.json');
expect(() => JSON.parse(content)).not.toThrow();
const json = JSON.parse(content);
const core = '@angular/core';
const bazel = '@angular/bazel';
expect(Object.keys(json)).toContain('dependencies');
expect(Object.keys(json)).toContain('devDependencies');
expect(Object.keys(json.dependencies)).toContain(core);
expect(Object.keys(json.devDependencies)).toContain(bazel);
expect(json.dependencies[core]).toBe(json.devDependencies[bazel]);
});
it('should add @bazel/* dev dependencies', () => {
host = schematicRunner.runSchematic('ng-add', defaultOptions, host);
const content = host.readContent('/package.json');
const json = JSON.parse(content);
const devDeps = Object.keys(json.devDependencies);
expect(devDeps).toContain('@bazel/bazel');
expect(devDeps).toContain('@bazel/ibazel');
expect(devDeps).toContain('@bazel/karma');
});
it('should not create Bazel workspace file', () => {
host = schematicRunner.runSchematic('ng-add', defaultOptions, host);
const {files} = host;
expect(files).not.toContain('/WORKSPACE');
expect(files).not.toContain('/BUILD.bazel');
});
it('should produce main.dev.ts and main.prod.ts for AOT', () => {
host.create('/src/main.ts', 'generated by CLI');
//.........这里部分代码省略.........
开发者ID:StephenFluin,项目名称:angular,代码行数:101,代码来源:index_spec.ts
示例4: it
it('requires required option', () => {
// We test that
const runner = new SchematicTestRunner('schematics', collectionPath);
expect(() => runner.runSchematic('my-full-schematic', {}, Tree.empty())).toThrow();
});
开发者ID:MathieuNls,项目名称:Angular-2-Design-Patterns-and-Best-Practices,代码行数:5,代码来源:index_spec.ts
示例5: it
it('should add router module to client app module', () => {
const tree = schematicRunner.runSchematic('appShell', defaultOptions, appTree);
const filePath = '/projects/bar/src/app/app.module.ts';
const content = tree.readContent(filePath);
expect(content).toMatch(/import { RouterModule } from \'@angular\/router\';/);
});
开发者ID:rexebin,项目名称:angular-cli,代码行数:6,代码来源:index_spec.ts
示例6: it
it('should create the new config file', () => {
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
expect(tree.exists(configPath)).toEqual(true);
});
开发者ID:DevIntent,项目名称:angular-cli,代码行数:5,代码来源:index_spec.ts
示例7: it
it('fails with an invalid version', done => {
const rule = updatePackageJson(['@angular/core'], 'babababarbaraann');
schematicRunner.callRule(rule, inputTree)
.subscribe(() => done.fail('version should not match.'), () => done());
});
开发者ID:iwe7,项目名称:devkit,代码行数:6,代码来源:npm_spec.ts
示例8: runSetupSchematic
function runSetupSchematic(options: Partial<NgAddOptions> = {}) {
return runner.runSchematic('setup', options, appTree);
}
开发者ID:kevinheader,项目名称:nebular,代码行数:3,代码来源:index.spec.ts
示例9: it
it('should not create Bazel workspace file', () => {
host = schematicRunner.runSchematic('ng-add', defaultOptions, host);
const {files} = host;
expect(files).not.toContain('/WORKSPACE');
expect(files).not.toContain('/BUILD.bazel');
});
开发者ID:StephenFluin,项目名称:angular,代码行数:6,代码来源:index_spec.ts
注:本文中的@angular-devkit/schematics/testing.SchematicTestRunner类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论