Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fit('should create Nx node', async () => {
appTree = Tree.empty();
appTree = createEmptyWorkspace(appTree);
const options: XplatHelpers.Schema = { ...defaultOptions };
options.platforms = 'node';
const tree = await runSchematic('app', options, appTree);
const files = tree.files;
// console.log('files:', files);
expect(tree.exists('/apps/node-sample/src/main.ts')).toBeTruthy();
let fileContent = getFileContent(tree, '/apps/node-sample/src/main.ts');
// console.log(fileContent);
expect(
fileContent.indexOf(`console.log('Hello World!')`)
).toBeGreaterThanOrEqual(0);
});
it('should add feature', async () => {
const tree = await runSchematic(
'ngrx',
{
name: 'state',
module: 'apps/myapp/src/app/app.module.ts'
},
appTree
);
const appModule = getFileContent(tree, '/apps/myapp/src/app/app.module.ts');
expect(appModule).toContain('StoreModule.forFeature');
expect(appModule).toContain('EffectsModule.forFeature');
expect(appModule).not.toContain('!environment.production ? [] : []');
expect(
tree.exists(`/apps/myapp/src/app/+state/state.actions.ts`)
).toBeTruthy();
});
it('should update main.ts', async () => {
const tree = await runSchematic(
'downgrade-module',
{
name: 'legacy',
project: 'myapp'
},
appTree
);
const main = getFileContent(tree, '/apps/myapp/src/main.ts');
expect(main).toContain('downgradeModule(bootstrapAngular)');
expect(main).toContain(`import 'legacy';`);
expect(main).toContain(
`angular.bootstrap(document, ['legacy', downgraded.name]);`
);
});
const tsconfigApp = JSON.parse(
stripJsonComments(getFileContent(tree, 'apps/my-app/tsconfig.app.json'))
);
expect(tsconfigApp.compilerOptions.outDir).toEqual('../../dist/out-tsc');
expect(tsconfigApp.extends).toEqual('./tsconfig.json');
const tslintJson = JSON.parse(
stripJsonComments(getFileContent(tree, 'apps/my-app/tslint.json'))
);
expect(tslintJson.extends).toEqual('../../tslint.json');
expect(tree.exists('apps/my-app-e2e/cypress.json')).toBeTruthy();
const tsconfigE2E = JSON.parse(
stripJsonComments(
getFileContent(tree, 'apps/my-app-e2e/tsconfig.e2e.json')
)
);
expect(tsconfigE2E.extends).toEqual('./tsconfig.json');
});
path: 'my-dir-my-lib2',
loadChildren: () =>
import('@proj/my-dir/my-lib2').then(
module => module.MyDirMyLib2Module
)
}`);
expect(moduleContents3).toContain(`
{
path: 'my-lib3',
loadChildren: () =>
import('@proj/my-dir/my-lib3').then(module => module.MyLib3Module)
}`);
const tsConfigAppJson3 = JSON.parse(
stripJsonComments(
getFileContent(tree3, 'apps/myapp/tsconfig.app.json')
)
);
expect(tsConfigAppJson3.include).toEqual([
'**/*.ts',
'../../libs/my-dir/my-lib/src/index.ts',
'../../libs/my-dir/my-lib2/src/index.ts',
'../../libs/my-dir/my-lib3/src/index.ts'
]);
});
});
const tsconfig = readJsonInTree(tree, 'apps/my-electron-app/tsconfig.json');
expect(tsconfig.extends).toEqual('../../tsconfig.json');
expect(tsconfig.compilerOptions.types).toContain('node');
expect(tsconfig.compilerOptions.types).toContain('jest');
const tsconfigApp = JSON.parse(
stripJsonComments(
getFileContent(tree, 'apps/my-electron-app/tsconfig.app.json')
)
);
expect(tsconfigApp.compilerOptions.outDir).toEqual('../../dist/out-tsc');
expect(tsconfigApp.extends).toEqual('./tsconfig.json');
const tslintJson = JSON.parse(
stripJsonComments(getFileContent(tree, 'apps/my-electron-app/tslint.json'))
);
expect(tslintJson.extends).toEqual('../../tslint.json');
});
});
);
const moduleContents = getFileContent(
tree,
'apps/myapp/src/app/app.module.ts'
);
expect(moduleContents).toContain('RouterModule.forRoot([');
expect(moduleContents).toContain(`
{
path: 'my-dir-my-lib',
loadChildren: () =>
import('@proj/my-dir/my-lib').then(module => module.MyDirMyLibModule)
}`);
const tsConfigAppJson = JSON.parse(
stripJsonComments(
getFileContent(tree, 'apps/myapp/tsconfig.app.json')
)
);
expect(tsConfigAppJson.include).toEqual([
'**/*.ts',
'../../libs/my-dir/my-lib/src/index.ts'
]);
const tree2 = await runSchematic(
'lib',
{
name: 'myLib2',
directory: 'myDir',
routing: true,
framework: 'angular',
lazy: true,
parentModule: 'apps/myapp/src/app/app.module.ts'
const tsconfig = readJsonInTree(tree, 'apps/my-node-app/tsconfig.json');
expect(tsconfig.extends).toEqual('../../tsconfig.json');
expect(tsconfig.compilerOptions.types).toContain('node');
expect(tsconfig.compilerOptions.types).toContain('jest');
const tsconfigApp = JSON.parse(
stripJsonComments(
getFileContent(tree, 'apps/my-node-app/tsconfig.app.json')
)
);
expect(tsconfigApp.compilerOptions.outDir).toEqual('../../dist/out-tsc');
expect(tsconfigApp.extends).toEqual('./tsconfig.json');
const tslintJson = JSON.parse(
stripJsonComments(getFileContent(tree, 'apps/my-node-app/tslint.json'))
);
expect(tslintJson.extends).toEqual('../../tslint.json');
});
});
const hasJsonValue = ({ path, expectedValue, lookupFn }) => {
const content = getFileContent(tree, path);
const config = JSON.parse(stripJsonComments(content));
expect(lookupFn(config)).toEqual(expectedValue);
};
const tree = await runSchematic(
const hasJsonValue = ({ path, expectedValue, lookupFn }) => {
const content = getFileContent(tree, path);
const config = JSON.parse(stripJsonComments(content));
expect(lookupFn(config)).toEqual(expectedValue);
};
const tree = await runSchematic(