Skip to content

Commit 56a1e8f

Browse files
committed
feat(@schematics/angular): remove test.ts file from new projects
The test.ts is now included in `@angular-devkit/build-angular` and unless this needs to be customized is no longer needed to be provided. Default config: ```js // This file is required by karma.conf.js and loads recursively all the .spec and framework files import { getTestBed } from '@angular/core/testing'; import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; // First, initialize the Angular testing environment. getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), { errorOnUnknownElements: true, errorOnUnknownProperties: true }); ```
1 parent 05a98c0 commit 56a1e8f

File tree

11 files changed

+6
-46
lines changed

11 files changed

+6
-46
lines changed

packages/angular_devkit/build_angular/src/builders/karma/tests/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const KARMA_BUILDER_INFO = Object.freeze({
2020
* Also disables progress reporting to minimize logging output.
2121
*/
2222
export const BASE_OPTIONS = Object.freeze<Schema>({
23-
polyfills: 'src/polyfills.ts',
23+
polyfills: ['zone.js', 'zone.js/testing', '@angular/localize/init'],
2424
tsConfig: 'src/tsconfig.spec.json',
2525
karmaConfig: 'karma.conf.js',
2626
browsers: 'ChromeHeadlessCI',

packages/angular_devkit/build_angular/test/hello-world-app/angular.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@
117117
"test": {
118118
"builder": "@angular-devkit/build-angular:karma",
119119
"options": {
120-
"polyfills": "src/polyfills.ts",
120+
"polyfills": ["zone.js", "zone.js/testing", "@angular/localize/init"],
121+
121122
"tsConfig": "src/tsconfig.spec.json",
122123
"karmaConfig": "karma.conf.js",
123124
"browsers": "ChromeHeadlessCI",

packages/schematics/angular/application/files/src/test.ts.template

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/schematics/angular/application/files/tsconfig.spec.json.template

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
"jasmine"
88
]
99
},
10-
"files": [
11-
"src/test.ts"
12-
],
1310
"include": [
1411
"src/**/*.spec.ts",
1512
"src/**/*.d.ts"

packages/schematics/angular/application/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ function addAppToWorkspaceFile(
210210
: {
211211
builder: Builders.Karma,
212212
options: {
213-
main: `${sourceRoot}/test.ts`,
214213
polyfills: ['zone.js', 'zone.js/testing'],
215214
tsConfig: `${projectRoot}tsconfig.spec.json`,
216215
karmaConfig: `${projectRoot}karma.conf.js`,
@@ -231,7 +230,7 @@ function addAppToWorkspaceFile(
231230
});
232231
}
233232
function minimalPathFilter(path: string): boolean {
234-
const toRemoveList = /(test.ts|tsconfig.spec.json|karma.conf.js).template$/;
233+
const toRemoveList = /(tsconfig.spec.json|karma.conf.js).template$/;
235234

236235
return !toRemoveList.test(path);
237236
}

packages/schematics/angular/application/index_spec.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ describe('Application Schematic', () => {
6161
'/projects/foo/src/index.html',
6262
'/projects/foo/src/main.ts',
6363
'/projects/foo/src/styles.css',
64-
'/projects/foo/src/test.ts',
6564
'/projects/foo/src/app/app.module.ts',
6665
'/projects/foo/src/app/app.component.css',
6766
'/projects/foo/src/app/app.component.html',
@@ -164,8 +163,7 @@ describe('Application Schematic', () => {
164163
const tree = await schematicRunner
165164
.runSchematicAsync('application', defaultOptions, workspaceTree)
166165
.toPromise();
167-
const { files, extends: _extends } = readJsonFile(tree, '/projects/foo/tsconfig.spec.json');
168-
expect(files).toEqual(['src/test.ts']);
166+
const { extends: _extends } = readJsonFile(tree, '/projects/foo/tsconfig.spec.json');
169167
expect(_extends).toBe('../../tsconfig.json');
170168
});
171169

@@ -255,7 +253,6 @@ describe('Application Schematic', () => {
255253
[
256254
'/projects/foo/tsconfig.spec.json',
257255
'/projects/foo/karma.conf.js',
258-
'/projects/foo/src/test.ts',
259256
'/projects/foo/src/app/app.component.css',
260257
'/projects/foo/src/app/app.component.html',
261258
'/projects/foo/src/app/app.component.spec.ts',
@@ -285,7 +282,6 @@ describe('Application Schematic', () => {
285282
[
286283
'/projects/foo/tsconfig.spec.json',
287284
'/projects/foo/karma.conf.js',
288-
'/projects/foo/src/test.ts',
289285
'/projects/foo/src/app/app.component.html',
290286
'/projects/foo/src/app/app.component.spec.ts',
291287
].forEach((x) => expect(files).not.toContain(x));
@@ -315,7 +311,6 @@ describe('Application Schematic', () => {
315311
[
316312
'/projects/foo/tsconfig.spec.json',
317313
'/projects/foo/karma.conf.js',
318-
'/projects/foo/src/test.ts',
319314
'/projects/foo/src/app/app.component.css',
320315
'/projects/foo/src/app/app.component.spec.ts',
321316
].forEach((x) => expect(files).not.toContain(x));
@@ -410,7 +405,6 @@ describe('Application Schematic', () => {
410405
'/src/index.html',
411406
'/src/main.ts',
412407
'/src/styles.css',
413-
'/src/test.ts',
414408
'/src/app/app.module.ts',
415409
'/src/app/app.component.css',
416410
'/src/app/app.component.html',
@@ -436,7 +430,6 @@ describe('Application Schematic', () => {
436430
expect(buildOpt.tsConfig).toEqual('tsconfig.app.json');
437431

438432
const testOpt = prj.architect.test.options;
439-
expect(testOpt.main).toEqual('src/test.ts');
440433
expect(testOpt.tsConfig).toEqual('tsconfig.spec.json');
441434
expect(testOpt.karmaConfig).toEqual('karma.conf.js');
442435
expect(testOpt.styles).toEqual(['src/styles.css']);
@@ -510,13 +503,13 @@ describe('Application Schematic', () => {
510503
expect(appTsConfig.extends).toEqual('./tsconfig.json');
511504
const specTsConfig = readJsonFile(tree, '/tsconfig.spec.json');
512505
expect(specTsConfig.extends).toEqual('./tsconfig.json');
513-
expect(specTsConfig.files).toEqual(['src/test.ts']);
514506
});
515507

516508
it(`should create correct paths when 'newProjectRoot' is blank`, async () => {
517509
const workspaceTree = await schematicRunner
518510
.runSchematicAsync('workspace', { ...workspaceOptions, newProjectRoot: '' })
519511
.toPromise();
512+
520513
const options = { ...defaultOptions, projectRoot: undefined };
521514
const tree = await schematicRunner
522515
.runSchematicAsync('application', options, workspaceTree)

packages/schematics/angular/library/files/src/test.ts.template

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/schematics/angular/library/files/tsconfig.lib.json.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"types": []
1010
},
1111
"exclude": [
12-
"src/test.ts",
1312
"**/*.spec.ts"
1413
]
1514
}

packages/schematics/angular/library/files/tsconfig.spec.json.template

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
"jasmine"
88
]
99
},
10-
"files": [
11-
"src/test.ts"
12-
],
1310
"include": [
1411
"**/*.spec.ts",
1512
"**/*.d.ts"

packages/schematics/angular/library/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ function addLibToWorkspaceFile(
108108
test: {
109109
builder: Builders.Karma,
110110
options: {
111-
main: `${projectRoot}/src/test.ts`,
112111
tsConfig: `${projectRoot}/tsconfig.spec.json`,
113112
polyfills: ['zone.js', 'zone.js/testing'],
114113
karmaConfig: `${projectRoot}/karma.conf.js`,

0 commit comments

Comments
 (0)