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 create a custom theme file if no SCSS file could be found', () => {
// TODO(devversion): do not re-create test app here.
appTree = createTestApp(runner, {style: 'css'});
const tree = runner.runSchematic('ng-add-setup-project', {theme: 'custom'}, appTree);
const workspace = getWorkspace(tree);
const project = getProjectFromWorkspace(workspace);
const expectedStylesPath = normalize(`/${project.root}/src/custom-theme.scss`);
expect(tree.files).toContain(expectedStylesPath, 'Expected a custom theme file to be created');
expectProjectStyleFile(project, 'projects/material/src/custom-theme.scss');
});
it('should not add NoopAnimationsModule if BrowserAnimationsModule is set up', () => {
const workspace = getWorkspace(appTree);
const project = getProjectFromWorkspace(workspace);
// Simulate the case where a developer uses `ng-add` on an Angular CLI project which already
// explicitly uses the `BrowserAnimationsModule`. It would be wrong to forcibly change
// to noop animations.
const fileContent = addModuleImportToRootModule(appTree, 'BrowserAnimationsModule',
'@angular/platform-browser/animations', project);
runSetupSchematic({ animations: false });
expect(fileContent).not.toContain('NoopAnimationsModule',
'Expected the project app module to not import the "NoopAnimationsModule".');
});
});
return (host: Tree) => {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project);
const appModulePath = getAppModulePath(host, getProjectMainFile(project));
if (options.animations) {
// In case the project explicitly uses the NoopAnimationsModule, we should print a warning
// message that makes the user aware of the fact that we won't automatically set up
// animations. If we would add the BrowserAnimationsModule while the NoopAnimationsModule
// is already configured, we would cause unexpected behavior and runtime exceptions.
if (hasNgModuleImport(host, appModulePath, noopAnimationsModuleName)) {
return console.warn(
chalk.red(
`Could not set up "${chalk.bold(browserAnimationsModuleName)}" ` +
`because "${chalk.bold(noopAnimationsModuleName)}" is already imported. Please ` +
`manually set up browser animations.`
)
);
}
return (host: Tree) => {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project);
const appModulePath = getAppModulePath(host, getProjectMainFile(project));
if (options.animations) {
if (hasNgModuleImport(host, appModulePath, noopAnimationsModuleName)) {
console.log();
return console.log(chalk.yellow(`Could not set up "${chalk.blue(browserAnimationsModuleName)}" ` +
`because "${chalk.blue(noopAnimationsModuleName)}" is already imported. Please manually ` +
`set up browser animations.`));
}
addModuleImportToRootModule(host, browserAnimationsModuleName,
animationsModulePath, project);
} else if (!hasNgModuleImport(host, appModulePath, browserAnimationsModuleName)) {
addModuleImportToRootModule(host, noopAnimationsModuleName,
animationsModulePath, project);
}
it('should add custom theme', async () => {
appTree = await createTestApp(runner, {style: 'less'});
const tree = await runner.runSchematicAsync('ng-add-setup-project', {theme: true}, appTree).toPromise();
const workspace = getWorkspace(tree);
const project = getProjectFromWorkspace(workspace);
const customThemePath = normalize(join(project.sourceRoot, 'styles.less'));
const buffer = tree.read(customThemePath);
const themeContent = buffer!.toString();
expect(themeContent).toContain(`@import "../node_modules/ng-zorro-antd/ng-zorro-antd.less`);
expect(themeContent).toContain(`@ant-prefix: ant;`);
expect(themeContent).toContain(`@primary-color: @blue-6;`);
expect(getProjectTargetOptions(project, 'build').styles)
.toContain('projects/ng-zorro/src/styles.less');
});
it('addNgxFaceApiJsModule works', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('ng-add', {}, createTestApp()).toPromise();
const workspace = getWorkspace(tree);
const project = getProjectFromWorkspace(workspace);
const appModulePath = getAppModulePath(tree, getProjectMainFile(project));
if (appModulePath) {
const appModuleContent = getFileContent(tree, appModulePath);
expect(appModuleContent).toMatch(`${NGX_SPEECH_RECOGNITION_MODULE_NAME}.forRoot`);
}
});
});
return function (host: Tree): Tree {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project) as WorkspaceProject;
if (options.theme) {
insertCustomTheme(project, options.project, host, workspace);
} else {
insertCompiledTheme(project, host, workspace);
}
return host;
};
}
return function(host: Tree): Tree {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project);
const themeName = options.theme || 'indigo-pink';
if (themeName === 'custom') {
insertCustomTheme(project, options.project, host, workspace);
} else {
insertPrebuiltTheme(project, host, themeName, workspace);
}
return host;
};
}
function overwriteTargetBuilder(tree: Tree, targetName: string, newBuilder: string) {
const workspace = getWorkspace(tree);
const project = getProjectFromWorkspace(workspace);
const targetConfig = project.architect && project.architect[targetName] ||
project.targets && project.targets[targetName];
targetConfig['builder'] = newBuilder;
tree.overwrite('/angular.json', JSON.stringify(workspace, null, 2));
}
return (tree: Tree) => {
const workspace = getWorkspace(tree);
const project = getProjectFromWorkspace(workspace, options.project);
const themePath = `./node_modules/@nebular/theme/styles/prebuilt/${options.theme}.css`;
addStyleToTarget(project, 'build', tree, themePath, workspace);
return tree;
}
}