Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should add dependencies into `package.json` file', async () => {
const tree = await runSchematic('init', {}, appTree);
const packageJson = readJsonInTree(tree, 'package.json');
expect(packageJson.devDependencies['@storybook/angular']).toBeDefined();
expect(packageJson.devDependencies['@storybook/addon-knobs']).toBeDefined();
expect(packageJson.devDependencies['babel-loader']).toBeDefined();
expect(packageJson.devDependencies['@babel/core']).toBeDefined();
});
});
it('should update nx.json', async () => {
const tree = await runSchematic(
'app',
{ name: 'myApp', tags: 'one,two' },
appTree
);
const nxJson = readJsonInTree(tree, '/nx.json');
expect(nxJson).toEqual({
npmScope: 'proj',
projects: {
'my-app': {
tags: ['one', 'two']
},
'my-app-e2e': {
tags: []
}
}
});
});
it('should extend the local tsconfig.json with tsconfig.lib.json', async () => {
const tree = await runSchematic('lib', { name: 'myLib' }, appTree);
const tsconfigJson = readJsonInTree(
tree,
'libs/my-lib/tsconfig.lib.json'
);
expect(tsconfigJson.extends).toEqual('./tsconfig.json');
});
it('should create a local tsconfig.json', async () => {
const tree = await runSchematic(
'lib',
{ name: 'myLib', directory: 'myDir' },
appTree
);
const tsconfigJson = readJsonInTree(
tree,
'libs/my-dir/my-lib/tsconfig.json'
);
expect(tsconfigJson).toEqual({
extends: '../../../tsconfig.json',
compilerOptions: {
types: ['node', 'jest']
},
include: ['**/*.ts']
});
});
it('should not generate test configuration', async () => {
const tree = await runSchematic(
'app',
{ name: 'myApp', unitTestRunner: 'none' },
appTree
);
expect(tree.exists('apps/my-app/src/app/app.spec.tsx')).toBeFalsy();
expect(tree.exists('apps/my-app/tsconfig.spec.json')).toBeFalsy();
expect(tree.exists('apps/my-app/jest.config.js')).toBeFalsy();
const workspaceJson = readJsonInTree(tree, 'workspace.json');
expect(workspaceJson.projects['my-app'].architect.test).toBeUndefined();
expect(
workspaceJson.projects['my-app'].architect.lint.options.tsConfig
).toEqual(['apps/my-app/tsconfig.app.json']);
});
});
it('should update package.json', async () => {
const tree = await runSchematic(
'ngrx',
{
name: 'state',
module: 'apps/myapp/src/app/app.module.ts'
},
appTree
);
const packageJson = readJsonInTree(tree, 'package.json');
expect(packageJson.dependencies['@ngrx/store']).toBeDefined();
expect(packageJson.dependencies['@ngrx/router-store']).toBeDefined();
expect(packageJson.dependencies['@ngrx/effects']).toBeDefined();
expect(packageJson.devDependencies['@ngrx/store-devtools']).toBeDefined();
});
it('should be added to existing recommendations', async () => {
initialTree = await schematicRunner
.callRule(
updateJsonInTree('.vscode/extensions.json', () => ({
recommendations: ['eamodio.gitlens', 'angular.ng-template']
})),
initialTree
)
.toPromise();
const result = await schematicRunner
.runSchematicAsync('update-7.6.0', {}, initialTree)
.toPromise();
expect(readJsonInTree(result, '.vscode/extensions.json')).toEqual({
recommendations: [
'eamodio.gitlens',
'angular.ng-template',
'nrwl.angular-console',
'esbenp.prettier-vscode'
]
});
});
});
return (host: Tree): Rule => {
const packageJson = readJsonInTree(host, 'package.json');
const dependencyList: { name: string; version: string }[] = [];
if (!packageJson.devDependencies.cypress) {
dependencyList.push({ name: 'cypress', version: cypressVersion });
}
if (!packageJson.devDependencies['@nrwl/cypress']) {
dependencyList.push({ name: '@nrwl/cypress', version: nxVersion });
}
if (!dependencyList.length) {
return noop();
}
return addDepsToPackageJson(
{},
dependencyList.reduce((dictionary, value) => {
dictionary[value.name] = value.version;
function getTypes(path: string) {
return readJsonInTree(result, path).compilerOptions.types;
}
tree = await createLibWithTests(
tree,
lib,
jestBuilder,
'test-modified.ts.ts'
);
tree.create(
`/libs/${lib}/tsconfig.lib.json`,
JSON.stringify({ exclude })
);
const result = await schematicRunner
.runSchematicAsync(schematicName, {}, tree)
.toPromise();
const tsconfigJson = readJsonInTree(
result,
`libs/${lib}/tsconfig.lib.json`
);
expect(tsconfigJson.exclude).toEqual(exclude);
});
});