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
});
```
This commit is contained in:
Alan Agius 2022-09-27 16:30:12 +00:00 committed by Alan Agius
parent 05a98c0292
commit 56a1e8f9f5
11 changed files with 6 additions and 46 deletions

View File

@ -20,7 +20,7 @@ export const KARMA_BUILDER_INFO = Object.freeze({
* Also disables progress reporting to minimize logging output.
*/
export const BASE_OPTIONS = Object.freeze<Schema>({
polyfills: 'src/polyfills.ts',
polyfills: ['zone.js', 'zone.js/testing', '@angular/localize/init'],
tsConfig: 'src/tsconfig.spec.json',
karmaConfig: 'karma.conf.js',
browsers: 'ChromeHeadlessCI',

View File

@ -117,7 +117,8 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": "src/polyfills.ts",
"polyfills": ["zone.js", "zone.js/testing", "@angular/localize/init"],
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"browsers": "ChromeHeadlessCI",

View File

@ -1,12 +0,0 @@
// 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
});

View File

@ -7,9 +7,6 @@
"jasmine"
]
},
"files": [
"src/test.ts"
],
"include": [
"src/**/*.spec.ts",
"src/**/*.d.ts"

View File

@ -210,7 +210,6 @@ function addAppToWorkspaceFile(
: {
builder: Builders.Karma,
options: {
main: `${sourceRoot}/test.ts`,
polyfills: ['zone.js', 'zone.js/testing'],
tsConfig: `${projectRoot}tsconfig.spec.json`,
karmaConfig: `${projectRoot}karma.conf.js`,
@ -231,7 +230,7 @@ function addAppToWorkspaceFile(
});
}
function minimalPathFilter(path: string): boolean {
const toRemoveList = /(test.ts|tsconfig.spec.json|karma.conf.js).template$/;
const toRemoveList = /(tsconfig.spec.json|karma.conf.js).template$/;
return !toRemoveList.test(path);
}

View File

@ -61,7 +61,6 @@ describe('Application Schematic', () => {
'/projects/foo/src/index.html',
'/projects/foo/src/main.ts',
'/projects/foo/src/styles.css',
'/projects/foo/src/test.ts',
'/projects/foo/src/app/app.module.ts',
'/projects/foo/src/app/app.component.css',
'/projects/foo/src/app/app.component.html',
@ -164,8 +163,7 @@ describe('Application Schematic', () => {
const tree = await schematicRunner
.runSchematicAsync('application', defaultOptions, workspaceTree)
.toPromise();
const { files, extends: _extends } = readJsonFile(tree, '/projects/foo/tsconfig.spec.json');
expect(files).toEqual(['src/test.ts']);
const { extends: _extends } = readJsonFile(tree, '/projects/foo/tsconfig.spec.json');
expect(_extends).toBe('../../tsconfig.json');
});
@ -255,7 +253,6 @@ describe('Application Schematic', () => {
[
'/projects/foo/tsconfig.spec.json',
'/projects/foo/karma.conf.js',
'/projects/foo/src/test.ts',
'/projects/foo/src/app/app.component.css',
'/projects/foo/src/app/app.component.html',
'/projects/foo/src/app/app.component.spec.ts',
@ -285,7 +282,6 @@ describe('Application Schematic', () => {
[
'/projects/foo/tsconfig.spec.json',
'/projects/foo/karma.conf.js',
'/projects/foo/src/test.ts',
'/projects/foo/src/app/app.component.html',
'/projects/foo/src/app/app.component.spec.ts',
].forEach((x) => expect(files).not.toContain(x));
@ -315,7 +311,6 @@ describe('Application Schematic', () => {
[
'/projects/foo/tsconfig.spec.json',
'/projects/foo/karma.conf.js',
'/projects/foo/src/test.ts',
'/projects/foo/src/app/app.component.css',
'/projects/foo/src/app/app.component.spec.ts',
].forEach((x) => expect(files).not.toContain(x));
@ -410,7 +405,6 @@ describe('Application Schematic', () => {
'/src/index.html',
'/src/main.ts',
'/src/styles.css',
'/src/test.ts',
'/src/app/app.module.ts',
'/src/app/app.component.css',
'/src/app/app.component.html',
@ -436,7 +430,6 @@ describe('Application Schematic', () => {
expect(buildOpt.tsConfig).toEqual('tsconfig.app.json');
const testOpt = prj.architect.test.options;
expect(testOpt.main).toEqual('src/test.ts');
expect(testOpt.tsConfig).toEqual('tsconfig.spec.json');
expect(testOpt.karmaConfig).toEqual('karma.conf.js');
expect(testOpt.styles).toEqual(['src/styles.css']);
@ -510,13 +503,13 @@ describe('Application Schematic', () => {
expect(appTsConfig.extends).toEqual('./tsconfig.json');
const specTsConfig = readJsonFile(tree, '/tsconfig.spec.json');
expect(specTsConfig.extends).toEqual('./tsconfig.json');
expect(specTsConfig.files).toEqual(['src/test.ts']);
});
it(`should create correct paths when 'newProjectRoot' is blank`, async () => {
const workspaceTree = await schematicRunner
.runSchematicAsync('workspace', { ...workspaceOptions, newProjectRoot: '' })
.toPromise();
const options = { ...defaultOptions, projectRoot: undefined };
const tree = await schematicRunner
.runSchematicAsync('application', options, workspaceTree)

View File

@ -1,12 +0,0 @@
// 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
});

View File

@ -9,7 +9,6 @@
"types": []
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}

View File

@ -7,9 +7,6 @@
"jasmine"
]
},
"files": [
"src/test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"

View File

@ -108,7 +108,6 @@ function addLibToWorkspaceFile(
test: {
builder: Builders.Karma,
options: {
main: `${projectRoot}/src/test.ts`,
tsConfig: `${projectRoot}/tsconfig.spec.json`,
polyfills: ['zone.js', 'zone.js/testing'],
karmaConfig: `${projectRoot}/karma.conf.js`,

View File

@ -57,7 +57,6 @@ describe('Library Schematic', () => {
'/projects/foo/README.md',
'/projects/foo/tsconfig.lib.json',
'/projects/foo/tsconfig.lib.prod.json',
'/projects/foo/src/test.ts',
'/projects/foo/src/my-index.ts',
'/projects/foo/src/lib/foo.module.ts',
'/projects/foo/src/lib/foo.component.spec.ts',