Skip to content

Commit 0df3192

Browse files
committed
fix(@schematics/angular): align Karma project generation with unified unit-test builder
Updates the application and ng-new schematics to correctly configure Karma-based projects. - The test target in the generated angular.json now uses the `@angular/build:unit-test` builder. - The builder options are simplified to only include runner: 'karma', as other settings are now handled by the unified builder. - Corresponding schematic tests have been updated to reflect these changes.
1 parent cf47d15 commit 0df3192

File tree

6 files changed

+13
-20
lines changed

6 files changed

+13
-20
lines changed

packages/schematics/angular/application/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,9 @@ function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rul
396396
options: {},
397397
}
398398
: {
399-
builder: Builders.BuildKarma,
399+
builder: Builders.BuildUnitTest,
400400
options: {
401-
polyfills: options.zoneless ? undefined : ['zone.js', 'zone.js/testing'],
402-
tsConfig: `${projectRoot}tsconfig.spec.json`,
403-
inlineStyleLanguage,
404-
assets: [{ 'glob': '**/*', 'input': `${projectRoot}public` }],
405-
styles: [`${sourceRoot}/styles.${options.style}`],
401+
runner: 'karma',
406402
},
407403
},
408404
},

packages/schematics/angular/application/index_spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,11 @@ describe('Application Schematic', () => {
448448
const config = JSON.parse(tree.readContent('/angular.json'));
449449
const prj = config.projects.foo;
450450
const testOpt = prj.architect.test;
451-
expect(testOpt.builder).toEqual('@angular/build:karma');
452-
expect(testOpt.options.tsConfig).toEqual('tsconfig.spec.json');
453-
expect(testOpt.options.assets).toEqual([{ glob: '**/*', input: 'public' }]);
454-
expect(testOpt.options.styles).toEqual(['src/styles.css']);
451+
expect(testOpt.builder).toEqual('@angular/build:unit-test');
452+
expect(testOpt.options.runner).toEqual('karma');
453+
expect(testOpt.options.tsConfig).toBeUndefined();
454+
expect(testOpt.options.assets).toBeUndefined();
455+
expect(testOpt.options.styles).toBeUndefined();
455456
});
456457

457458
it('should set the relative tsconfig paths', async () => {

packages/schematics/angular/ng-new/index_spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ describe('Ng New Schematic', () => {
169169
},
170170
},
171171
} = JSON.parse(tree.readContent('/bar/angular.json'));
172-
expect(test.builder).toBe('@angular/build:karma');
172+
expect(test.builder).toBe('@angular/build:unit-test');
173+
expect(test.options).toEqual({ runner: 'karma' });
173174

174175
const { devDependencies } = JSON.parse(tree.readContent('/bar/package.json'));
175176
expect(devDependencies['karma']).toBeDefined();

tests/legacy-cli/e2e/tests/basic/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ export default async function () {
4848
`,
4949
});
5050

51-
await ng('test', '--watch=false', '--karma-config=karma.conf.bis.js');
51+
await ng('test', '--watch=false', '--runner-config=karma.conf.bis.js');
5252
}

tests/legacy-cli/e2e/tests/test/test-code-coverage-exclude.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@ import { expectToFail } from '../../utils/utils';
44

55
export default async function () {
66
// This test is already in build-angular, but that doesn't run on Windows.
7-
await silentNg('test', '--no-watch', '--code-coverage');
7+
await silentNg('test', '--no-watch', '--coverage');
88
await expectFileToExist('coverage/test-project/app.ts.html');
99
// Delete coverage directory
1010
await rimraf('coverage');
1111

12-
await silentNg(
13-
'test',
14-
'--no-watch',
15-
'--code-coverage',
16-
`--code-coverage-exclude='src/**/app.ts'`,
17-
);
12+
await silentNg('test', '--no-watch', '--coverage', `--coverage-exclude='src/**/app.ts'`);
1813

1914
// Doesn't include excluded.
2015
await expectFileToExist('coverage/test-project/index.html');

tests/legacy-cli/e2e/utils/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export async function useCIChrome(projectName: string, projectDir = ''): Promise
191191
return updateJsonFile('angular.json', (workspaceJson) => {
192192
const project = workspaceJson.projects[projectName];
193193
const appTargets = project.targets || project.architect;
194-
appTargets.test.options.browsers = 'ChromeHeadlessNoSandbox';
194+
appTargets.test.options.browsers = ['ChromeHeadlessNoSandbox'];
195195
});
196196
}
197197

0 commit comments

Comments
 (0)