Skip to content

Commit

Permalink
fix(angular): remove karma test.ts file from generation (#13356)
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Nov 24, 2022
1 parent 2471768 commit a0d01b6
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 127 deletions.
@@ -1,55 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`karmaProject applications should create a test.ts 1`] = `
"// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: any;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\\\\.spec\\\\.ts$/);
// And load the modules.
context.keys().map(context);
"
`;

exports[`karmaProject library should create a test.ts 1`] = `
"// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: any;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\\\\.spec\\\\.ts$/);
// And load the modules.
context.keys().map(context);
"
`;

exports[`karmaProject should create a karma.conf.js 1`] = `
"// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
Expand All @@ -75,19 +25,9 @@ exports[`karmaProject should generate files 1`] = `
\\"extends\\": \\"./tsconfig.json\\",
\\"compilerOptions\\": {
\\"outDir\\": \\"../../dist/out-tsc\\",
\\"types\\": [
\\"jasmine\\",
\\"node\\"
]
\\"types\\": [\\"jasmine\\", \\"node\\"]
},
\\"files\\": [
\\"src/test.ts\\"
],
\\"include\\": [
\\"**/*.spec.ts\\",
\\"**/*.test.ts\\",
\\"**/*.d.ts\\"
]
\\"include\\": [\\"**/*.spec.ts\\", \\"**/*.test.ts\\", \\"**/*.d.ts\\"]
}
"
`;
Expand All @@ -102,14 +42,13 @@ exports[`karmaProject should generate files and correctly add polyfills if it is
\\"node\\"
]
},
\\"files\\": [
\\"src/test.ts\\",
\\"src/polyfills.ts\\"
],
\\"include\\": [
\\"**/*.spec.ts\\",
\\"**/*.test.ts\\",
\\"**/*.d.ts\\"
],
\\"files\\": [
\\"src/polyfills.ts\\"
]
}
"
Expand All @@ -120,19 +59,9 @@ exports[`karmaProject should generate files and not add polyfills if it is using
\\"extends\\": \\"./tsconfig.json\\",
\\"compilerOptions\\": {
\\"outDir\\": \\"../../dist/out-tsc\\",
\\"types\\": [
\\"jasmine\\",
\\"node\\"
]
\\"types\\": [\\"jasmine\\", \\"node\\"]
},
\\"files\\": [
\\"src/test.ts\\"
],
\\"include\\": [
\\"**/*.spec.ts\\",
\\"**/*.test.ts\\",
\\"**/*.d.ts\\"
]
\\"include\\": [\\"**/*.spec.ts\\", \\"**/*.test.ts\\", \\"**/*.d.ts\\"]
}
"
`;

This file was deleted.

Expand Up @@ -4,6 +4,5 @@
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
"types": ["jasmine", "node"]
},
"files": ["src/test.ts"],
"include": ["**/*.spec.ts", "**/*.test.ts", "**/*.d.ts"]
}
Expand Up @@ -53,7 +53,6 @@ describe('karmaProject', () => {
expect(
tree.read('/libs/lib1/tsconfig.spec.json', 'utf-8')
).toMatchSnapshot();
expect(tree.exists('/libs/lib1/src/test.ts')).toBeTruthy();
expect(tree.exists('karma.conf.js')).toBeTruthy();
});

Expand Down Expand Up @@ -114,9 +113,9 @@ describe('karmaProject', () => {
expect(workspaceJson.projects.lib1.architect.test).toEqual({
builder: '@angular-devkit/build-angular:karma',
options: {
main: 'libs/lib1/src/test.ts',
tsConfig: 'libs/lib1/tsconfig.spec.json',
karmaConfig: 'libs/lib1/karma.conf.js',
polyfills: ['zone.js', 'zone.js/testing'],
},
});
});
Expand All @@ -131,17 +130,9 @@ describe('karmaProject', () => {
outDir: '../../dist/out-tsc',
types: ['jasmine', 'node'],
},
files: ['src/test.ts'],
include: ['**/*.spec.ts', '**/*.test.ts', '**/*.d.ts'],
});
});

it('should create a test.ts', async () => {
await karmaProjectGenerator(tree, { project: 'lib1' });

const testTs = tree.read('libs/lib1/src/test.ts').toString();
expect(testTs).toMatchSnapshot();
});
});

describe('applications', () => {
Expand All @@ -152,7 +143,6 @@ describe('karmaProject', () => {
expect(workspaceJson.projects.app1.architect.test).toEqual({
builder: '@angular-devkit/build-angular:karma',
options: {
main: 'apps/app1/src/test.ts',
polyfills: ['zone.js', 'zone.js/testing'],
tsConfig: 'apps/app1/tsconfig.spec.json',
karmaConfig: 'apps/app1/karma.conf.js',
Expand All @@ -173,7 +163,6 @@ describe('karmaProject', () => {
outDir: '../../dist/out-tsc',
types: ['jasmine', 'node'],
},
files: ['src/test.ts'],
include: ['**/*.spec.ts', '**/*.test.ts', '**/*.d.ts'],
});
});
Expand All @@ -190,7 +179,6 @@ describe('karmaProject', () => {
expect(workspaceJson.projects.app1.architect.test).toEqual({
builder: '@angular-devkit/build-angular:karma',
options: {
main: 'apps/app1/src/test.ts',
polyfills: 'apps/app1/src/polyfills.ts',
tsConfig: 'apps/app1/tsconfig.spec.json',
karmaConfig: 'apps/app1/karma.conf.js',
Expand All @@ -216,16 +204,9 @@ describe('karmaProject', () => {
outDir: '../../dist/out-tsc',
types: ['jasmine', 'node'],
},
files: ['src/test.ts', 'src/polyfills.ts'],
files: ['src/polyfills.ts'],
include: ['**/*.spec.ts', '**/*.test.ts', '**/*.d.ts'],
});
});

it('should create a test.ts', async () => {
await karmaProjectGenerator(tree, { project: 'app1' });

const testTs = tree.read('apps/app1/src/test.ts').toString();
expect(testTs).toMatchSnapshot();
});
});
});
Expand Up @@ -37,13 +37,17 @@ export function updateTsConfigs(tree: Tree, project: string): void {
extraFiles = [polyfillsPath];
}

return updateJson(
if (!extraFiles.length) {
return;
}

updateJson(
tree,
joinPathFragments(projectConfig.root, 'tsconfig.spec.json'),
(json) => {
return {
...json,
files: [...json.files, ...extraFiles],
files: [...(json.files ?? []), ...extraFiles],
};
}
);
Expand Down
Expand Up @@ -10,9 +10,9 @@ export function updateWorkspaceConfig(tree: Tree, project: string): void {
projectConfig.targets.test = {
executor: '@angular-devkit/build-angular:karma',
options: {
main: joinPathFragments(projectConfig.sourceRoot, 'test.ts'),
tsConfig: joinPathFragments(projectConfig.root, 'tsconfig.spec.json'),
karmaConfig: joinPathFragments(projectConfig.root, 'karma.conf.js'),
polyfills: ['zone.js', 'zone.js/testing'],
},
};

Expand All @@ -23,7 +23,7 @@ export function updateWorkspaceConfig(tree: Tree, project: string): void {

projectConfig.targets.test.options = {
...projectConfig.targets.test.options,
polyfills: polyfillsPath ?? ['zone.js', 'zone.js/testing'],
polyfills: polyfillsPath ?? projectConfig.targets.test.options.polyfills,
styles: [],
scripts: [],
assets: [],
Expand Down
1 change: 0 additions & 1 deletion packages/angular/src/generators/library/library.spec.ts
Expand Up @@ -1131,7 +1131,6 @@ describe('lib', () => {
// ASSERT
const workspaceJson = readJson(tree, 'workspace.json');

expect(tree.exists('libs/my-lib/src/test.ts')).toBeTruthy();
expect(tree.exists('libs/my-lib/src/test-setup.ts')).toBeFalsy();
expect(tree.exists('libs/my-lib/tsconfig.spec.json')).toBeTruthy();
expect(tree.exists('libs/my-lib/karma.conf.js')).toBeTruthy();
Expand Down

0 comments on commit a0d01b6

Please sign in to comment.