cleanup(angular): remove karma generation support (#15419)
This commit is contained in:
parent
98001cc489
commit
2ab66dd410
@ -3707,22 +3707,6 @@
|
||||
"isExternal": false,
|
||||
"disableCollapsible": false
|
||||
},
|
||||
{
|
||||
"id": "karma",
|
||||
"path": "/packages/angular/generators/karma",
|
||||
"name": "karma",
|
||||
"children": [],
|
||||
"isExternal": false,
|
||||
"disableCollapsible": false
|
||||
},
|
||||
{
|
||||
"id": "karma-project",
|
||||
"path": "/packages/angular/generators/karma-project",
|
||||
"name": "karma-project",
|
||||
"children": [],
|
||||
"isExternal": false,
|
||||
"disableCollapsible": false
|
||||
},
|
||||
{
|
||||
"id": "library",
|
||||
"path": "/packages/angular/generators/library",
|
||||
|
||||
@ -15,12 +15,12 @@
|
||||
"githubRoot": "https://github.com/nrwl/nx/blob/master",
|
||||
"name": "angular",
|
||||
"packageName": "@nrwl/angular",
|
||||
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Cypress, Karma, and Protractor. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
||||
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Cypress, and Protractor. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
||||
"documents": {
|
||||
"/packages/angular/documents/overview": {
|
||||
"id": "overview",
|
||||
"name": "Overview",
|
||||
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Cypress, Karma, and Protractor. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
||||
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Cypress, and Protractor. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
||||
"file": "generated/packages/angular/documents/overview",
|
||||
"itemList": [],
|
||||
"isExternal": false,
|
||||
@ -31,7 +31,7 @@
|
||||
"/packages/angular/documents/angular-nx-version-matrix": {
|
||||
"id": "angular-nx-version-matrix",
|
||||
"name": "Angular and Nx Version Matrix",
|
||||
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Cypress, Karma, and Protractor. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
||||
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Cypress, and Protractor. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
||||
"file": "generated/packages/angular/documents/angular-nx-version-matrix",
|
||||
"itemList": [],
|
||||
"isExternal": false,
|
||||
@ -198,24 +198,6 @@
|
||||
"path": "/packages/angular/generators/init",
|
||||
"type": "generator"
|
||||
},
|
||||
"/packages/angular/generators/karma": {
|
||||
"description": "Adds Karma configuration to a workspace.",
|
||||
"file": "generated/packages/angular/generators/karma.json",
|
||||
"hidden": false,
|
||||
"name": "karma",
|
||||
"originalFilePath": "/packages/angular/src/generators/karma/schema.json",
|
||||
"path": "/packages/angular/generators/karma",
|
||||
"type": "generator"
|
||||
},
|
||||
"/packages/angular/generators/karma-project": {
|
||||
"description": "Adds Karma configuration to a project.",
|
||||
"file": "generated/packages/angular/generators/karma-project.json",
|
||||
"hidden": false,
|
||||
"name": "karma-project",
|
||||
"originalFilePath": "/packages/angular/src/generators/karma-project/schema.json",
|
||||
"path": "/packages/angular/generators/karma-project",
|
||||
"type": "generator"
|
||||
},
|
||||
"/packages/angular/generators/library": {
|
||||
"description": "Creates an Angular library.",
|
||||
"file": "generated/packages/angular/generators/library.json",
|
||||
|
||||
@ -11,12 +11,12 @@
|
||||
"source": "/packages/add-nx-to-monorepo/src"
|
||||
},
|
||||
{
|
||||
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Cypress, Karma, and Protractor. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
||||
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Cypress, and Protractor. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
||||
"documents": [
|
||||
{
|
||||
"id": "overview",
|
||||
"name": "Overview",
|
||||
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Cypress, Karma, and Protractor. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
||||
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Cypress, and Protractor. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
||||
"file": "generated/packages/angular/documents/overview",
|
||||
"itemList": [],
|
||||
"isExternal": false,
|
||||
@ -27,7 +27,7 @@
|
||||
{
|
||||
"id": "angular-nx-version-matrix",
|
||||
"name": "Angular and Nx Version Matrix",
|
||||
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Cypress, Karma, and Protractor. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
||||
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Cypress, and Protractor. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
||||
"file": "generated/packages/angular/documents/angular-nx-version-matrix",
|
||||
"itemList": [],
|
||||
"isExternal": false,
|
||||
@ -192,24 +192,6 @@
|
||||
"path": "angular/generators/init",
|
||||
"type": "generator"
|
||||
},
|
||||
{
|
||||
"description": "Adds Karma configuration to a workspace.",
|
||||
"file": "generated/packages/angular/generators/karma.json",
|
||||
"hidden": false,
|
||||
"name": "karma",
|
||||
"originalFilePath": "/packages/angular/src/generators/karma/schema.json",
|
||||
"path": "angular/generators/karma",
|
||||
"type": "generator"
|
||||
},
|
||||
{
|
||||
"description": "Adds Karma configuration to a project.",
|
||||
"file": "generated/packages/angular/generators/karma-project.json",
|
||||
"hidden": false,
|
||||
"name": "karma-project",
|
||||
"originalFilePath": "/packages/angular/src/generators/karma-project/schema.json",
|
||||
"path": "angular/generators/karma-project",
|
||||
"type": "generator"
|
||||
},
|
||||
{
|
||||
"description": "Creates an Angular library.",
|
||||
"file": "generated/packages/angular/generators/library.json",
|
||||
|
||||
@ -96,7 +96,7 @@
|
||||
},
|
||||
"unitTestRunner": {
|
||||
"type": "string",
|
||||
"enum": ["karma", "jest", "none"],
|
||||
"enum": ["jest", "none"],
|
||||
"description": "Test runner to use for unit tests.",
|
||||
"default": "jest"
|
||||
},
|
||||
|
||||
@ -102,7 +102,7 @@
|
||||
},
|
||||
"unitTestRunner": {
|
||||
"type": "string",
|
||||
"enum": ["karma", "jest", "none"],
|
||||
"enum": ["jest", "none"],
|
||||
"description": "Test runner to use for unit tests.",
|
||||
"default": "jest"
|
||||
},
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
"properties": {
|
||||
"unitTestRunner": {
|
||||
"type": "string",
|
||||
"enum": ["karma", "jest", "none"],
|
||||
"enum": ["jest", "none"],
|
||||
"description": "Test runner to use for unit tests.",
|
||||
"default": "jest",
|
||||
"x-priority": "important"
|
||||
|
||||
@ -95,7 +95,7 @@
|
||||
},
|
||||
"unitTestRunner": {
|
||||
"type": "string",
|
||||
"enum": ["karma", "jest", "none"],
|
||||
"enum": ["jest", "none"],
|
||||
"description": "Test runner to use for unit tests.",
|
||||
"default": "jest"
|
||||
},
|
||||
|
||||
@ -96,7 +96,7 @@
|
||||
},
|
||||
"unitTestRunner": {
|
||||
"type": "string",
|
||||
"enum": ["karma", "jest", "none"],
|
||||
"enum": ["jest", "none"],
|
||||
"description": "Test runner to use for unit tests.",
|
||||
"default": "jest"
|
||||
},
|
||||
|
||||
@ -32,14 +32,6 @@ describe('nx-dev: Packages Section', () => {
|
||||
path: '/packages/angular/generators/convert-tslint-to-eslint',
|
||||
},
|
||||
{ title: '@nrwl/angular:init', path: '/packages/angular/generators/init' },
|
||||
{
|
||||
title: '@nrwl/angular:karma',
|
||||
path: '/packages/angular/generators/karma',
|
||||
},
|
||||
{
|
||||
title: '@nrwl/angular:karma-project',
|
||||
path: '/packages/angular/generators/karma-project',
|
||||
},
|
||||
{
|
||||
title: '@nrwl/angular:library',
|
||||
path: '/packages/angular/generators/library',
|
||||
|
||||
@ -50,16 +50,6 @@
|
||||
"description": "Initializes the `@nrwl/angular` plugin.",
|
||||
"hidden": true
|
||||
},
|
||||
"karma": {
|
||||
"factory": "./src/generators/karma/compat",
|
||||
"schema": "./src/generators/karma/schema.json",
|
||||
"description": "Adds Karma configuration to a workspace."
|
||||
},
|
||||
"karma-project": {
|
||||
"factory": "./src/generators/karma-project/compat",
|
||||
"schema": "./src/generators/karma-project/schema.json",
|
||||
"description": "Adds Karma configuration to a project."
|
||||
},
|
||||
"library": {
|
||||
"factory": "./src/generators/library/library.compat#librarySchematic",
|
||||
"schema": "./src/generators/library/schema.json",
|
||||
@ -211,16 +201,6 @@
|
||||
"description": "Initializes the `@nrwl/angular` plugin.",
|
||||
"hidden": true
|
||||
},
|
||||
"karma": {
|
||||
"factory": "./src/generators/karma/karma",
|
||||
"schema": "./src/generators/karma/schema.json",
|
||||
"description": "Adds Karma configuration to a workspace."
|
||||
},
|
||||
"karma-project": {
|
||||
"factory": "./src/generators/karma-project/karma-project",
|
||||
"schema": "./src/generators/karma-project/schema.json",
|
||||
"description": "Adds Karma configuration to a project."
|
||||
},
|
||||
"library": {
|
||||
"factory": "./src/generators/library/library",
|
||||
"schema": "./src/generators/library/schema.json",
|
||||
|
||||
@ -6,8 +6,6 @@ export * from './src/generators/component/component';
|
||||
export * from './src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint';
|
||||
export * from './src/generators/host/host';
|
||||
export * from './src/generators/init/init';
|
||||
export * from './src/generators/karma-project/karma-project';
|
||||
export * from './src/generators/karma/karma';
|
||||
export * from './src/generators/library-secondary-entry-point/library-secondary-entry-point';
|
||||
export * from './src/generators/library/library';
|
||||
export * from './src/generators/move/move';
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
"name": "@nrwl/angular",
|
||||
"version": "0.0.1",
|
||||
"private": false,
|
||||
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Cypress, Karma, and Protractor. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
||||
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Cypress, and Protractor. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nrwl/nx.git",
|
||||
|
||||
@ -4,7 +4,6 @@ import type { NormalizedSchema } from './normalized-schema';
|
||||
import { jestProjectGenerator } from '@nrwl/jest';
|
||||
|
||||
import { UnitTestRunner } from '../../../../utils/test-runners';
|
||||
import karmaProjectGenerator from '../../../karma-project/karma-project';
|
||||
|
||||
export async function addUnitTestRunner(host: Tree, options: NormalizedSchema) {
|
||||
if (options.unitTestRunner === UnitTestRunner.Jest) {
|
||||
@ -16,10 +15,5 @@ export async function addUnitTestRunner(host: Tree, options: NormalizedSchema) {
|
||||
skipPackageJson: options.skipPackageJson,
|
||||
rootProject: options.rootProject,
|
||||
});
|
||||
} else if (options.unitTestRunner === UnitTestRunner.Karma) {
|
||||
await karmaProjectGenerator(host, {
|
||||
project: options.name,
|
||||
skipFormat: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -586,27 +586,6 @@ describe('app', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('karma', () => {
|
||||
it('should generate a karma config', async () => {
|
||||
await generateApp(appTree, 'myApp', {
|
||||
unitTestRunner: UnitTestRunner.Karma,
|
||||
});
|
||||
|
||||
expect(appTree.exists('apps/my-app/tsconfig.spec.json')).toBeTruthy();
|
||||
expect(appTree.exists('apps/my-app/karma.conf.js')).toBeTruthy();
|
||||
expect(
|
||||
readProjectConfiguration(appTree, 'my-app').targets.test.executor
|
||||
).toEqual('@angular-devkit/build-angular:karma');
|
||||
const tsconfigAppJson = readJson(
|
||||
appTree,
|
||||
'apps/my-app/tsconfig.app.json'
|
||||
);
|
||||
expect(tsconfigAppJson.compilerOptions.outDir).toEqual(
|
||||
'../../dist/out-tsc'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('none', () => {
|
||||
it('should not generate test configuration', async () => {
|
||||
await generateApp(appTree, 'myApp', {
|
||||
|
||||
@ -4,7 +4,6 @@ import type { NormalizedSchema } from './normalized-schema';
|
||||
import { jestProjectGenerator } from '@nrwl/jest';
|
||||
|
||||
import { UnitTestRunner } from '../../../utils/test-runners';
|
||||
import karmaProjectGenerator from '../../karma-project/karma-project';
|
||||
|
||||
export async function addUnitTestRunner(host: Tree, options: NormalizedSchema) {
|
||||
if (options.unitTestRunner === UnitTestRunner.Jest) {
|
||||
@ -16,10 +15,5 @@ export async function addUnitTestRunner(host: Tree, options: NormalizedSchema) {
|
||||
skipPackageJson: options.skipPackageJson,
|
||||
rootProject: options.rootProject,
|
||||
});
|
||||
} else if (options.unitTestRunner === UnitTestRunner.Karma) {
|
||||
await karmaProjectGenerator(host, {
|
||||
project: options.name,
|
||||
skipFormat: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +99,7 @@
|
||||
},
|
||||
"unitTestRunner": {
|
||||
"type": "string",
|
||||
"enum": ["karma", "jest", "none"],
|
||||
"enum": ["jest", "none"],
|
||||
"description": "Test runner to use for unit tests.",
|
||||
"default": "jest"
|
||||
},
|
||||
|
||||
@ -105,7 +105,7 @@
|
||||
},
|
||||
"unitTestRunner": {
|
||||
"type": "string",
|
||||
"enum": ["karma", "jest", "none"],
|
||||
"enum": ["jest", "none"],
|
||||
"description": "Test runner to use for unit tests.",
|
||||
"default": "jest"
|
||||
},
|
||||
|
||||
@ -16,7 +16,6 @@ import { initGenerator as jsInitGenerator } from '@nrwl/js';
|
||||
|
||||
import { backwardCompatibleVersions } from '../../../utils/backward-compatible-versions';
|
||||
import { E2eTestRunner, UnitTestRunner } from '../../../utils/test-runners';
|
||||
import { karmaGenerator } from '../../karma/karma';
|
||||
import {
|
||||
addDependenciesToPackageJsonIfDontExist,
|
||||
getInstalledPackageVersion,
|
||||
@ -159,10 +158,6 @@ async function addUnitTestRunner(
|
||||
options: Schema
|
||||
): Promise<GeneratorCallback> {
|
||||
switch (options.unitTestRunner) {
|
||||
case UnitTestRunner.Karma:
|
||||
return await karmaGenerator(tree, {
|
||||
skipPackageJson: options.skipPackageJson,
|
||||
});
|
||||
case UnitTestRunner.Jest:
|
||||
if (!options.skipPackageJson) {
|
||||
addDependenciesToPackageJsonIfDontExist(
|
||||
|
||||
@ -112,62 +112,6 @@ describe('init', () => {
|
||||
});
|
||||
|
||||
describe('--unit-test-runner', () => {
|
||||
describe('karma', () => {
|
||||
it('should add karma dependencies', async () => {
|
||||
// ACT
|
||||
await init(tree, {
|
||||
unitTestRunner: UnitTestRunner.Karma,
|
||||
linter: Linter.EsLint,
|
||||
skipFormat: false,
|
||||
});
|
||||
|
||||
const { devDependencies } = readJson(tree, 'package.json');
|
||||
|
||||
// ASSERT
|
||||
expect(devDependencies['karma']).toBeDefined();
|
||||
expect(devDependencies['karma-chrome-launcher']).toBeDefined();
|
||||
expect(devDependencies['karma-coverage']).toBeDefined();
|
||||
expect(devDependencies['karma-jasmine']).toBeDefined();
|
||||
expect(devDependencies['karma-jasmine-html-reporter']).toBeDefined();
|
||||
expect(devDependencies['jasmine-core']).toBeDefined();
|
||||
expect(devDependencies['jasmine-spec-reporter']).toBeDefined();
|
||||
expect(devDependencies['@types/jasmine']).toBeDefined();
|
||||
});
|
||||
|
||||
it('should add karma configuration', async () => {
|
||||
// ACT
|
||||
await init(tree, {
|
||||
unitTestRunner: UnitTestRunner.Karma,
|
||||
linter: Linter.EsLint,
|
||||
skipFormat: false,
|
||||
});
|
||||
|
||||
const hasKarmaConfigFile = tree.exists('karma.conf.js');
|
||||
|
||||
// ASSERT
|
||||
expect(hasKarmaConfigFile).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should set defaults', async () => {
|
||||
// ACT
|
||||
await init(tree, {
|
||||
unitTestRunner: UnitTestRunner.Karma,
|
||||
linter: Linter.EsLint,
|
||||
skipFormat: false,
|
||||
});
|
||||
|
||||
const { generators } = readJson<NxJsonConfiguration>(tree, 'nx.json');
|
||||
|
||||
// ASSERT
|
||||
expect(generators['@nrwl/angular:application'].unitTestRunner).toEqual(
|
||||
'karma'
|
||||
);
|
||||
expect(generators['@nrwl/angular:library'].unitTestRunner).toEqual(
|
||||
'karma'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('jest', () => {
|
||||
it('should add jest dependencies', async () => {
|
||||
// ACT
|
||||
@ -496,79 +440,6 @@ bar
|
||||
});
|
||||
|
||||
describe('--unit-test-runner', () => {
|
||||
describe('karma', () => {
|
||||
it('should add karma dependencies', async () => {
|
||||
// ACT
|
||||
await init(tree, {
|
||||
unitTestRunner: UnitTestRunner.Karma,
|
||||
linter: Linter.EsLint,
|
||||
skipFormat: false,
|
||||
});
|
||||
|
||||
const { devDependencies } = readJson(tree, 'package.json');
|
||||
|
||||
// ASSERT
|
||||
expect(devDependencies['karma']).toEqual(
|
||||
backwardCompatibleVersions.angularV14.karmaVersion
|
||||
);
|
||||
expect(devDependencies['karma-chrome-launcher']).toEqual(
|
||||
backwardCompatibleVersions.angularV14.karmaChromeLauncherVersion
|
||||
);
|
||||
expect(devDependencies['karma-coverage']).toEqual(
|
||||
backwardCompatibleVersions.angularV14.karmaCoverageVersion
|
||||
);
|
||||
expect(devDependencies['karma-jasmine']).toEqual(
|
||||
backwardCompatibleVersions.angularV14.karmaJasmineVersion
|
||||
);
|
||||
expect(devDependencies['karma-jasmine-html-reporter']).toEqual(
|
||||
backwardCompatibleVersions.angularV14
|
||||
.karmaJasmineHtmlReporterVersion
|
||||
);
|
||||
expect(devDependencies['jasmine-core']).toEqual(
|
||||
backwardCompatibleVersions.angularV14.jasmineCoreVersion
|
||||
);
|
||||
expect(devDependencies['jasmine-spec-reporter']).toEqual(
|
||||
backwardCompatibleVersions.angularV14.jasmineSpecReporterVersion
|
||||
);
|
||||
expect(devDependencies['@types/jasmine']).toEqual(
|
||||
backwardCompatibleVersions.angularV14.typesJasmineVersion
|
||||
);
|
||||
});
|
||||
|
||||
it('should add karma configuration', async () => {
|
||||
// ACT
|
||||
await init(tree, {
|
||||
unitTestRunner: UnitTestRunner.Karma,
|
||||
linter: Linter.EsLint,
|
||||
skipFormat: false,
|
||||
});
|
||||
|
||||
const hasKarmaConfigFile = tree.exists('karma.conf.js');
|
||||
|
||||
// ASSERT
|
||||
expect(hasKarmaConfigFile).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should set defaults', async () => {
|
||||
// ACT
|
||||
await init(tree, {
|
||||
unitTestRunner: UnitTestRunner.Karma,
|
||||
linter: Linter.EsLint,
|
||||
skipFormat: false,
|
||||
});
|
||||
|
||||
const { generators } = readJson<NxJsonConfiguration>(tree, 'nx.json');
|
||||
|
||||
// ASSERT
|
||||
expect(
|
||||
generators['@nrwl/angular:application'].unitTestRunner
|
||||
).toEqual('karma');
|
||||
expect(generators['@nrwl/angular:library'].unitTestRunner).toEqual(
|
||||
'karma'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('jest', () => {
|
||||
it('should add jest dependencies', async () => {
|
||||
// ACT
|
||||
|
||||
@ -30,7 +30,6 @@ import {
|
||||
typesJasminewd2Version,
|
||||
zoneJsVersion,
|
||||
} from '../../utils/versions';
|
||||
import { karmaGenerator } from '../karma/karma';
|
||||
import {
|
||||
addDependenciesToPackageJsonIfDontExist,
|
||||
getGeneratorDirectoryForInstalledAngularVersion,
|
||||
@ -182,10 +181,6 @@ async function addUnitTestRunner(
|
||||
options: Schema
|
||||
): Promise<GeneratorCallback> {
|
||||
switch (options.unitTestRunner) {
|
||||
case UnitTestRunner.Karma:
|
||||
return await karmaGenerator(tree, {
|
||||
skipPackageJson: options.skipPackageJson,
|
||||
});
|
||||
case UnitTestRunner.Jest:
|
||||
if (!options.skipPackageJson) {
|
||||
addDependenciesToPackageJsonIfDontExist(
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
"properties": {
|
||||
"unitTestRunner": {
|
||||
"type": "string",
|
||||
"enum": ["karma", "jest", "none"],
|
||||
"enum": ["jest", "none"],
|
||||
"description": "Test runner to use for unit tests.",
|
||||
"default": "jest",
|
||||
"x-priority": "important"
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
import { convertNxGenerator } from '@nrwl/devkit';
|
||||
import { karmaProjectGenerator } from './karma-project';
|
||||
|
||||
export default convertNxGenerator(karmaProjectGenerator);
|
||||
@ -1,16 +0,0 @@
|
||||
// Karma configuration file, see link for more information
|
||||
// https://karma-runner.github.io/6.4/config/configuration-file.html
|
||||
|
||||
const { join } = require('path');
|
||||
const getBaseKarmaConfig = require('<%= offsetFromRoot %>karma.conf');
|
||||
|
||||
module.exports = function(config) {
|
||||
const baseConfig = getBaseKarmaConfig();
|
||||
config.set({
|
||||
...baseConfig,
|
||||
coverageReporter: {
|
||||
...baseConfig.coverageReporter,
|
||||
dir: join(__dirname, '<%= offsetFromRoot %>coverage/<%= projectRoot %>')
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -1,8 +0,0 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
|
||||
"types": ["jasmine", "node"]
|
||||
},
|
||||
"include": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.d.ts"]
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
// Karma configuration file, see link for more information
|
||||
// https://karma-runner.github.io/6.4/config/configuration-file.html
|
||||
|
||||
const { constants } = require('karma');
|
||||
const { join } = require('path');
|
||||
|
||||
module.exports = (config) => {
|
||||
config.set({
|
||||
basePath: '',
|
||||
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
||||
plugins: [
|
||||
require('karma-jasmine'),
|
||||
require('karma-chrome-launcher'),
|
||||
require('karma-jasmine-html-reporter'),
|
||||
require('karma-coverage'),
|
||||
require('@angular-devkit/build-angular/plugins/karma'),
|
||||
],
|
||||
client: {
|
||||
jasmine: {
|
||||
// you can add configuration options for Jasmine here
|
||||
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
|
||||
// for example, you can disable the random execution with `random: false`
|
||||
// or set a specific seed with `seed: 4321`
|
||||
},
|
||||
clearContext: false, // leave Jasmine Spec Runner output visible in browser
|
||||
},
|
||||
jasmineHtmlReporter: {
|
||||
suppressAll: true, // removes the duplicated traces
|
||||
},
|
||||
coverageReporter: {
|
||||
dir: join(__dirname, 'coverage/<%= projectName %>'),
|
||||
subdir: '.',
|
||||
reporters: [{ type: 'html' }, { type: 'text-summary' }],
|
||||
},
|
||||
reporters: ['progress', 'kjhtml'],
|
||||
port: 9876,
|
||||
colors: true,
|
||||
logLevel: constants.LOG_INFO,
|
||||
autoWatch: true,
|
||||
browsers: ['Chrome'],
|
||||
singleRun: true,
|
||||
restartOnFileChange: true,
|
||||
});
|
||||
};
|
||||
@ -1,28 +0,0 @@
|
||||
// Karma configuration file, see link for more information
|
||||
// https://karma-runner.github.io/6.4/config/configuration-file.html
|
||||
|
||||
const { join } = require('path');<% if (rootProjectWithConfigSet) { %>
|
||||
const setBaseKarmaConfig = require('<%= offsetFromRoot %>karma.conf');
|
||||
|
||||
module.exports = function (config) {
|
||||
setBaseKarmaConfig(config);
|
||||
|
||||
config.set({
|
||||
coverageReporter: {
|
||||
dir: join(__dirname, '<%= offsetFromRoot %>coverage/<%= projectRoot %>')
|
||||
}
|
||||
});
|
||||
};<% } else { %>
|
||||
const getBaseKarmaConfig = require('<%= offsetFromRoot %>karma.conf');
|
||||
|
||||
module.exports = function (config) {
|
||||
const baseConfig = getBaseKarmaConfig(config);
|
||||
|
||||
config.set({
|
||||
...baseConfig,
|
||||
coverageReporter: {
|
||||
...baseConfig.coverageReporter,
|
||||
dir: join(__dirname, '<%= offsetFromRoot %>coverage/<%= projectRoot %>')
|
||||
}
|
||||
});
|
||||
};<% } %>
|
||||
@ -1,27 +0,0 @@
|
||||
import type { GeneratorCallback, Tree } from '@nrwl/devkit';
|
||||
import { formatFiles } from '@nrwl/devkit';
|
||||
import { checkProjectTestTarget } from './lib/check-test-target';
|
||||
import { generateKarmaProjectFiles } from './lib/generate-karma-project-files';
|
||||
import { updateTsConfigs } from './lib/update-tsconfig';
|
||||
import { updateWorkspaceConfig } from './lib/update-workspace-config';
|
||||
import type { KarmaProjectOptions } from './schema';
|
||||
import { karmaGenerator } from '../karma/karma';
|
||||
|
||||
export async function karmaProjectGenerator(
|
||||
tree: Tree,
|
||||
options: KarmaProjectOptions
|
||||
): Promise<GeneratorCallback> {
|
||||
const installTask = await karmaGenerator(tree, options);
|
||||
checkProjectTestTarget(tree, options.project);
|
||||
generateKarmaProjectFiles(tree, options.project);
|
||||
updateTsConfigs(tree, options.project);
|
||||
updateWorkspaceConfig(tree, options.project);
|
||||
|
||||
if (!options.skipFormat) {
|
||||
await formatFiles(tree);
|
||||
}
|
||||
|
||||
return installTask;
|
||||
}
|
||||
|
||||
export default karmaProjectGenerator;
|
||||
@ -1,9 +0,0 @@
|
||||
import type { Tree } from '@nrwl/devkit';
|
||||
import { readProjectConfiguration } from '@nrwl/devkit';
|
||||
|
||||
export function checkProjectTestTarget(tree: Tree, project: string): void {
|
||||
const projectConfig = readProjectConfiguration(tree, project);
|
||||
if (projectConfig.targets.test) {
|
||||
throw new Error(`"${project}" already has a test target.`);
|
||||
}
|
||||
}
|
||||
@ -1,89 +0,0 @@
|
||||
import type { Tree } from '@nrwl/devkit';
|
||||
import {
|
||||
generateFiles,
|
||||
getProjects,
|
||||
joinPathFragments,
|
||||
offsetFromRoot,
|
||||
readProjectConfiguration,
|
||||
} from '@nrwl/devkit';
|
||||
import { getInstalledAngularVersionInfo } from '../../utils/version-utils';
|
||||
import { v14TestFile } from './v14-test-file';
|
||||
import { ensureTypescript } from '@nrwl/js/src/utils/typescript/ensure-typescript';
|
||||
|
||||
export function generateKarmaProjectFiles(tree: Tree, project: string): void {
|
||||
const projectConfig = readProjectConfiguration(tree, project);
|
||||
generateFiles(
|
||||
tree,
|
||||
joinPathFragments(__dirname, '..', 'files', 'common'),
|
||||
projectConfig.root,
|
||||
{
|
||||
tmpl: '',
|
||||
projectRoot: projectConfig.root,
|
||||
offsetFromRoot: offsetFromRoot(projectConfig.root),
|
||||
}
|
||||
);
|
||||
|
||||
if (projectConfig.root === '' || projectConfig.root === '.') {
|
||||
generateFiles(
|
||||
tree,
|
||||
joinPathFragments(__dirname, '..', 'files', 'root-project'),
|
||||
projectConfig.root,
|
||||
{
|
||||
tmpl: '',
|
||||
projectName: project,
|
||||
}
|
||||
);
|
||||
} else if (isWorkspaceWithProjectAtRoot(tree)) {
|
||||
generateFiles(
|
||||
tree,
|
||||
joinPathFragments(
|
||||
__dirname,
|
||||
'..',
|
||||
'files',
|
||||
'workspace-with-root-project'
|
||||
),
|
||||
projectConfig.root,
|
||||
{
|
||||
tmpl: '',
|
||||
projectRoot: projectConfig.root,
|
||||
offsetFromRoot: offsetFromRoot(projectConfig.root),
|
||||
rootProjectWithConfigSet: isUsingConfigSetInBaseKarmaConfig(tree),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const installedAngularVersion = getInstalledAngularVersionInfo(tree);
|
||||
if (installedAngularVersion.major === 14) {
|
||||
tree.write(
|
||||
joinPathFragments(projectConfig.sourceRoot, 'test.ts'),
|
||||
v14TestFile({ isLibrary: projectConfig.projectType === 'library' })
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function isWorkspaceWithProjectAtRoot(tree: Tree): boolean {
|
||||
const projects = getProjects(tree);
|
||||
for (const [, project] of projects) {
|
||||
if (project.root === '.' || project.root === '') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isUsingConfigSetInBaseKarmaConfig(tree: Tree) {
|
||||
if (!tree.exists('karma.conf.js')) {
|
||||
return false;
|
||||
}
|
||||
ensureTypescript();
|
||||
const { tsquery } = require('@phenomnomnominal/tsquery');
|
||||
|
||||
const CONFIG_SET_SELECTOR =
|
||||
'PropertyAccessExpression:has(Identifier[name=config], Identifier[name=set])';
|
||||
|
||||
const ast = tsquery.ast(tree.read('karma.conf.js', 'utf-8'));
|
||||
const nodes = tsquery(ast, CONFIG_SET_SELECTOR, { visitAllChildren: true });
|
||||
|
||||
return nodes.length > 0;
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
import type { Tree } from '@nrwl/devkit';
|
||||
import {
|
||||
joinPathFragments,
|
||||
readProjectConfiguration,
|
||||
updateJson,
|
||||
} from '@nrwl/devkit';
|
||||
import { getInstalledAngularVersionInfo } from '../../utils/version-utils';
|
||||
|
||||
export function updateTsConfigs(tree: Tree, project: string): void {
|
||||
const projectConfig = readProjectConfiguration(tree, project);
|
||||
|
||||
updateJson(
|
||||
tree,
|
||||
joinPathFragments(projectConfig.root, 'tsconfig.json'),
|
||||
(json) => {
|
||||
return {
|
||||
...json,
|
||||
references: [
|
||||
...(json.references || []),
|
||||
{
|
||||
path: './tsconfig.spec.json',
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
const installedAngularVersion = getInstalledAngularVersionInfo(tree);
|
||||
let extraFiles: string[] =
|
||||
installedAngularVersion.major === 14 ? ['src/test.ts'] : [];
|
||||
if (
|
||||
projectConfig.projectType == 'application' &&
|
||||
projectConfig.targets.build?.options?.polyfills &&
|
||||
typeof projectConfig.targets.build.options.polyfills === 'string'
|
||||
) {
|
||||
let polyfillsPath = projectConfig.targets.build.options.polyfills;
|
||||
polyfillsPath = polyfillsPath.startsWith(projectConfig.root)
|
||||
? polyfillsPath.replace(`${projectConfig.root}/`, '')
|
||||
: polyfillsPath;
|
||||
extraFiles = [...extraFiles, polyfillsPath];
|
||||
}
|
||||
|
||||
if (!extraFiles.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateJson(
|
||||
tree,
|
||||
joinPathFragments(projectConfig.root, 'tsconfig.spec.json'),
|
||||
(json) => {
|
||||
return {
|
||||
...json,
|
||||
files: [...(json.files ?? []), ...extraFiles],
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
import type { Tree } from '@nrwl/devkit';
|
||||
import {
|
||||
joinPathFragments,
|
||||
readProjectConfiguration,
|
||||
updateProjectConfiguration,
|
||||
} from '@nrwl/devkit';
|
||||
import { getInstalledAngularVersionInfo } from '../../utils/version-utils';
|
||||
|
||||
export function updateWorkspaceConfig(tree: Tree, project: string): void {
|
||||
const installedAngularVersionInfo = getInstalledAngularVersionInfo(tree);
|
||||
const projectConfig = readProjectConfiguration(tree, project);
|
||||
projectConfig.targets.test = {
|
||||
executor: '@angular-devkit/build-angular:karma',
|
||||
options: {
|
||||
...(installedAngularVersionInfo.major === 14
|
||||
? { 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'],
|
||||
},
|
||||
};
|
||||
|
||||
if (projectConfig.projectType === 'application') {
|
||||
const polyfills = projectConfig.targets.build?.options?.polyfills;
|
||||
let polyfillsPath =
|
||||
polyfills && typeof polyfills === 'string' ? polyfills : undefined;
|
||||
|
||||
projectConfig.targets.test.options = {
|
||||
...projectConfig.targets.test.options,
|
||||
polyfills: polyfillsPath ?? projectConfig.targets.test.options.polyfills,
|
||||
styles: [],
|
||||
scripts: [],
|
||||
assets: [],
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
projectConfig.targets.lint &&
|
||||
projectConfig.targets.lint.executor ===
|
||||
'@angular-devkit/build-angular:tslint'
|
||||
) {
|
||||
projectConfig.targets.lint.options.tsConfig = [
|
||||
...projectConfig.targets.lint.options.tsConfig,
|
||||
joinPathFragments(projectConfig.root, 'tsconfig.spec.json'),
|
||||
];
|
||||
}
|
||||
|
||||
updateProjectConfiguration(tree, project, projectConfig);
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
export const v14TestFile = (opts: {
|
||||
isLibrary: boolean;
|
||||
}) => `// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
||||
${
|
||||
opts.isLibrary
|
||||
? `
|
||||
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);`;
|
||||
@ -1,5 +0,0 @@
|
||||
export interface KarmaProjectOptions {
|
||||
project: string;
|
||||
skipFormat?: boolean;
|
||||
skipPackageJson?: boolean;
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/schema",
|
||||
"$id": "NxKarmaProjectGenerator",
|
||||
"title": "Create Karma Configuration for a project",
|
||||
"description": "Add Karma configuration to an angular project.",
|
||||
"cli": "nx",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"project": {
|
||||
"type": "string",
|
||||
"description": "The name of the project.",
|
||||
"x-dropdown": "projects",
|
||||
"x-priority": "important"
|
||||
},
|
||||
"skipFormat": {
|
||||
"description": "Skip formatting files.",
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"x-priority": "internal"
|
||||
},
|
||||
"skipPackageJson": {
|
||||
"description": "Skip updating package.json.",
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"x-priority": "internal"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["project"],
|
||||
"examplesFile": "../../../docs/karma-project-examples.md"
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
// Karma configuration file, see link for more information
|
||||
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
||||
|
||||
const { join } = require('path');
|
||||
const { constants } = require('karma');
|
||||
|
||||
module.exports = () => {
|
||||
return {
|
||||
basePath: '',
|
||||
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
||||
plugins: [
|
||||
require('karma-jasmine'),
|
||||
require('karma-chrome-launcher'),
|
||||
require('karma-jasmine-html-reporter'),
|
||||
require('karma-coverage'),
|
||||
require('@angular-devkit/build-angular/plugins/karma'),
|
||||
],
|
||||
client: {
|
||||
jasmine: {
|
||||
// you can add configuration options for Jasmine here
|
||||
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
|
||||
// for example, you can disable the random execution with `random: false`
|
||||
// or set a specific seed with `seed: 4321`
|
||||
},
|
||||
clearContext: false, // leave Jasmine Spec Runner output visible in browser
|
||||
},
|
||||
jasmineHtmlReporter: {
|
||||
suppressAll: true, // removes the duplicated traces
|
||||
},
|
||||
coverageReporter: {
|
||||
dir: join(__dirname, './coverage'),
|
||||
subdir: '.',
|
||||
reporters: [{ type: 'html' }, { type: 'text-summary' }],
|
||||
},
|
||||
reporters: ['progress', 'kjhtml'],
|
||||
port: 9876,
|
||||
colors: true,
|
||||
logLevel: constants.LOG_INFO,
|
||||
autoWatch: true,
|
||||
browsers: ['Chrome'],
|
||||
singleRun: true,
|
||||
restartOnFileChange: true
|
||||
};
|
||||
};
|
||||
@ -1,80 +0,0 @@
|
||||
import type { Tree } from '@nrwl/devkit';
|
||||
import {
|
||||
generateFiles,
|
||||
joinPathFragments,
|
||||
readJson,
|
||||
readNxJson,
|
||||
updateNxJson,
|
||||
} from '@nrwl/devkit';
|
||||
import { backwardCompatibleVersions } from '../../../utils/backward-compatible-versions';
|
||||
import { addDependenciesToPackageJsonIfDontExist } from '../../utils/version-utils';
|
||||
import { GeneratorOptions } from './schema';
|
||||
|
||||
function addTestInputs(tree: Tree) {
|
||||
const nxJson = readNxJson(tree);
|
||||
|
||||
const productionFileSet = nxJson.namedInputs?.production;
|
||||
if (productionFileSet) {
|
||||
productionFileSet.push(
|
||||
// Exclude spec files from production fileset
|
||||
'!{projectRoot}/**/*.spec.[jt]s',
|
||||
// Remove tsconfig.spec.json
|
||||
'!{projectRoot}/tsconfig.spec.json',
|
||||
// Remove karma.conf.js
|
||||
'!{projectRoot}/karma.conf.js'
|
||||
);
|
||||
// Dedupe and set
|
||||
nxJson.namedInputs.production = Array.from(new Set(productionFileSet));
|
||||
}
|
||||
|
||||
// Test targets depend on all their project's sources + production sources of dependencies
|
||||
nxJson.targetDefaults ??= {};
|
||||
nxJson.targetDefaults.test ??= {};
|
||||
nxJson.targetDefaults.test.inputs ??= [
|
||||
'default',
|
||||
productionFileSet ? '^production' : '^default',
|
||||
];
|
||||
nxJson.targetDefaults.test.inputs.push('{workspaceRoot}/karma.conf.js');
|
||||
|
||||
updateNxJson(tree, nxJson);
|
||||
}
|
||||
|
||||
export function karmaGenerator(tree: Tree, options: GeneratorOptions) {
|
||||
const packageJson = readJson(tree, 'package.json');
|
||||
|
||||
if (!tree.exists('karma.conf.js')) {
|
||||
generateFiles(tree, joinPathFragments(__dirname, 'files'), '.', {
|
||||
tmpl: '',
|
||||
});
|
||||
|
||||
addTestInputs(tree);
|
||||
}
|
||||
|
||||
if (options.skipPackageJson || packageJson.devDependencies['karma']) {
|
||||
return () => {};
|
||||
}
|
||||
|
||||
return addDependenciesToPackageJsonIfDontExist(
|
||||
tree,
|
||||
{},
|
||||
{
|
||||
karma: backwardCompatibleVersions.angularV14.karmaVersion,
|
||||
'karma-chrome-launcher':
|
||||
backwardCompatibleVersions.angularV14.karmaChromeLauncherVersion,
|
||||
'karma-coverage':
|
||||
backwardCompatibleVersions.angularV14.karmaCoverageVersion,
|
||||
'karma-jasmine':
|
||||
backwardCompatibleVersions.angularV14.karmaJasmineVersion,
|
||||
'karma-jasmine-html-reporter':
|
||||
backwardCompatibleVersions.angularV14.karmaJasmineHtmlReporterVersion,
|
||||
'jasmine-core': backwardCompatibleVersions.angularV14.jasmineCoreVersion,
|
||||
'jasmine-spec-reporter':
|
||||
backwardCompatibleVersions.angularV14.jasmineSpecReporterVersion,
|
||||
'@types/jasmine':
|
||||
backwardCompatibleVersions.angularV14.typesJasmineVersion,
|
||||
'@types/node': backwardCompatibleVersions.angularV14.typesNodeVersion,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default karmaGenerator;
|
||||
@ -1,3 +0,0 @@
|
||||
export interface GeneratorOptions {
|
||||
skipPackageJson?: boolean;
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
import { convertNxGenerator } from '@nrwl/devkit';
|
||||
import { karmaGenerator } from './karma';
|
||||
|
||||
export default convertNxGenerator(karmaGenerator);
|
||||
@ -1,44 +0,0 @@
|
||||
// Karma configuration file, see link for more information
|
||||
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
||||
|
||||
const { join } = require('path');
|
||||
const { constants } = require('karma');
|
||||
|
||||
module.exports = () => {
|
||||
return {
|
||||
basePath: '',
|
||||
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
||||
plugins: [
|
||||
require('karma-jasmine'),
|
||||
require('karma-chrome-launcher'),
|
||||
require('karma-jasmine-html-reporter'),
|
||||
require('karma-coverage'),
|
||||
require('@angular-devkit/build-angular/plugins/karma'),
|
||||
],
|
||||
client: {
|
||||
jasmine: {
|
||||
// you can add configuration options for Jasmine here
|
||||
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
|
||||
// for example, you can disable the random execution with `random: false`
|
||||
// or set a specific seed with `seed: 4321`
|
||||
},
|
||||
clearContext: false, // leave Jasmine Spec Runner output visible in browser
|
||||
},
|
||||
jasmineHtmlReporter: {
|
||||
suppressAll: true, // removes the duplicated traces
|
||||
},
|
||||
coverageReporter: {
|
||||
dir: join(__dirname, './coverage'),
|
||||
subdir: '.',
|
||||
reporters: [{ type: 'html' }, { type: 'text-summary' }],
|
||||
},
|
||||
reporters: ['progress', 'kjhtml'],
|
||||
port: 9876,
|
||||
colors: true,
|
||||
logLevel: constants.LOG_INFO,
|
||||
autoWatch: true,
|
||||
browsers: ['Chrome'],
|
||||
singleRun: true,
|
||||
restartOnFileChange: true
|
||||
};
|
||||
};
|
||||
@ -1,84 +0,0 @@
|
||||
import * as devkit from '@nrwl/devkit';
|
||||
import { NxJsonConfiguration, readJson, updateJson } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { karmaGenerator } from './karma';
|
||||
|
||||
describe('karma', () => {
|
||||
let tree: devkit.Tree;
|
||||
|
||||
beforeEach(() => {
|
||||
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
||||
});
|
||||
|
||||
it('should do nothing when karma is already installed and karma.conf.js exists', async () => {
|
||||
jest.spyOn(devkit, 'generateFiles');
|
||||
jest.spyOn(devkit, 'addDependenciesToPackageJson');
|
||||
devkit.updateJson(tree, 'package.json', (json) => {
|
||||
json.devDependencies = { karma: '~5.0.0' };
|
||||
return json;
|
||||
});
|
||||
tree.write('karma.conf.js', '');
|
||||
await karmaGenerator(tree, {});
|
||||
|
||||
expect(devkit.generateFiles).not.toHaveBeenCalled();
|
||||
expect(devkit.addDependenciesToPackageJson).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should create karma.conf.js when karma is installed', async () => {
|
||||
jest.spyOn(devkit, 'generateFiles');
|
||||
jest.spyOn(devkit, 'addDependenciesToPackageJson');
|
||||
devkit.updateJson(tree, 'package.json', (json) => {
|
||||
json.devDependencies = { karma: '~5.0.0' };
|
||||
return json;
|
||||
});
|
||||
|
||||
await karmaGenerator(tree, {});
|
||||
|
||||
expect(devkit.generateFiles).toHaveBeenCalled();
|
||||
expect(devkit.addDependenciesToPackageJson).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should add karma dependencies', async () => {
|
||||
karmaGenerator(tree, {});
|
||||
|
||||
const { devDependencies } = devkit.readJson(tree, 'package.json');
|
||||
expect(devDependencies['karma']).toBeDefined();
|
||||
expect(devDependencies['karma-chrome-launcher']).toBeDefined();
|
||||
expect(devDependencies['karma-coverage']).toBeDefined();
|
||||
expect(devDependencies['karma-jasmine']).toBeDefined();
|
||||
expect(devDependencies['karma-jasmine-html-reporter']).toBeDefined();
|
||||
expect(devDependencies['jasmine-core']).toBeDefined();
|
||||
expect(devDependencies['jasmine-spec-reporter']).toBeDefined();
|
||||
expect(devDependencies['@types/jasmine']).toBeDefined();
|
||||
expect(devDependencies['@types/node']).toBeDefined();
|
||||
});
|
||||
|
||||
it('should add karma configuration', async () => {
|
||||
await karmaGenerator(tree, {});
|
||||
|
||||
expect(tree.exists('karma.conf.js')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should add inputs for test targets', async () => {
|
||||
updateJson<NxJsonConfiguration>(tree, 'nx.json', (json) => {
|
||||
json.namedInputs ??= {};
|
||||
json.namedInputs.production = ['default', '^production'];
|
||||
return json;
|
||||
});
|
||||
await karmaGenerator(tree, {});
|
||||
|
||||
const nxJson = readJson<NxJsonConfiguration>(tree, 'nx.json');
|
||||
expect(nxJson.namedInputs.production).toContain(
|
||||
'!{projectRoot}/karma.conf.js'
|
||||
);
|
||||
expect(nxJson.namedInputs.production).toContain(
|
||||
'!{projectRoot}/tsconfig.spec.json'
|
||||
);
|
||||
expect(nxJson.namedInputs.production).toContain(
|
||||
'!{projectRoot}/**/*.spec.[jt]s'
|
||||
);
|
||||
expect(nxJson.targetDefaults.test).toEqual({
|
||||
inputs: ['default', '^production', '{workspaceRoot}/karma.conf.js'],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,97 +0,0 @@
|
||||
import type { Tree } from '@nrwl/devkit';
|
||||
import {
|
||||
generateFiles,
|
||||
joinPathFragments,
|
||||
readJson,
|
||||
readNxJson,
|
||||
updateNxJson,
|
||||
} from '@nrwl/devkit';
|
||||
import { join } from 'path';
|
||||
import {
|
||||
jasmineCoreVersion,
|
||||
jasmineSpecReporterVersion,
|
||||
karmaChromeLauncherVersion,
|
||||
karmaCoverageVersion,
|
||||
karmaJasmineHtmlReporterVersion,
|
||||
karmaJasmineVersion,
|
||||
karmaVersion,
|
||||
typesJasmineVersion,
|
||||
typesNodeVersion,
|
||||
} from '../../utils/versions';
|
||||
import {
|
||||
addDependenciesToPackageJsonIfDontExist,
|
||||
getGeneratorDirectoryForInstalledAngularVersion,
|
||||
} from '../utils/version-utils';
|
||||
import { GeneratorOptions } from './schema';
|
||||
|
||||
function addTestInputs(tree: Tree) {
|
||||
const nxJson = readNxJson(tree);
|
||||
|
||||
const productionFileSet = nxJson.namedInputs?.production;
|
||||
if (productionFileSet) {
|
||||
productionFileSet.push(
|
||||
// Exclude spec files from production fileset
|
||||
'!{projectRoot}/**/*.spec.[jt]s',
|
||||
// Remove tsconfig.spec.json
|
||||
'!{projectRoot}/tsconfig.spec.json',
|
||||
// Remove karma.conf.js
|
||||
'!{projectRoot}/karma.conf.js'
|
||||
);
|
||||
// Dedupe and set
|
||||
nxJson.namedInputs.production = Array.from(new Set(productionFileSet));
|
||||
}
|
||||
|
||||
// Test targets depend on all their project's sources + production sources of dependencies
|
||||
nxJson.targetDefaults ??= {};
|
||||
nxJson.targetDefaults.test ??= {};
|
||||
nxJson.targetDefaults.test.inputs ??= [
|
||||
'default',
|
||||
productionFileSet ? '^production' : '^default',
|
||||
];
|
||||
nxJson.targetDefaults.test.inputs.push('{workspaceRoot}/karma.conf.js');
|
||||
|
||||
updateNxJson(tree, nxJson);
|
||||
}
|
||||
|
||||
export async function karmaGenerator(tree: Tree, options: GeneratorOptions) {
|
||||
const generatorDirectory =
|
||||
getGeneratorDirectoryForInstalledAngularVersion(tree);
|
||||
if (generatorDirectory) {
|
||||
let previousGenerator = await import(
|
||||
join(__dirname, generatorDirectory, 'karma')
|
||||
);
|
||||
await previousGenerator.default(tree, options);
|
||||
return;
|
||||
}
|
||||
const packageJson = readJson(tree, 'package.json');
|
||||
|
||||
if (!tree.exists('karma.conf.js')) {
|
||||
generateFiles(tree, joinPathFragments(__dirname, 'files'), '.', {
|
||||
tmpl: '',
|
||||
});
|
||||
|
||||
addTestInputs(tree);
|
||||
}
|
||||
|
||||
if (options.skipPackageJson || packageJson.devDependencies['karma']) {
|
||||
return () => {};
|
||||
}
|
||||
|
||||
return addDependenciesToPackageJsonIfDontExist(
|
||||
tree,
|
||||
{},
|
||||
{
|
||||
karma: karmaVersion,
|
||||
'karma-chrome-launcher': karmaChromeLauncherVersion,
|
||||
'karma-coverage': karmaCoverageVersion,
|
||||
'karma-jasmine': karmaJasmineVersion,
|
||||
'karma-jasmine-html-reporter': karmaJasmineHtmlReporterVersion,
|
||||
'jasmine-core': jasmineCoreVersion,
|
||||
'jasmine-spec-reporter': jasmineSpecReporterVersion,
|
||||
'@types/jasmine': typesJasmineVersion,
|
||||
'@types/node': typesNodeVersion,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default karmaGenerator;
|
||||
@ -1,97 +0,0 @@
|
||||
import * as devkit from '@nrwl/devkit';
|
||||
import { NxJsonConfiguration, readJson, updateJson } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { karmaGenerator } from './karma';
|
||||
|
||||
describe('karma', () => {
|
||||
let tree: devkit.Tree;
|
||||
|
||||
beforeEach(() => {
|
||||
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
||||
updateJson(tree, 'package.json', (json) => ({
|
||||
...json,
|
||||
dependencies: {
|
||||
...json.dependencies,
|
||||
'@angular/core': '14.1.0',
|
||||
},
|
||||
}));
|
||||
});
|
||||
|
||||
describe('support angular v14', () => {
|
||||
it('should do nothing when karma is already installed and karma.conf.js exists', async () => {
|
||||
jest.spyOn(devkit, 'generateFiles');
|
||||
jest.spyOn(devkit, 'addDependenciesToPackageJson');
|
||||
devkit.updateJson(tree, 'package.json', (json) => {
|
||||
json.devDependencies = { karma: '~5.0.0' };
|
||||
return json;
|
||||
});
|
||||
tree.write('karma.conf.js', '');
|
||||
await karmaGenerator(tree, {});
|
||||
|
||||
expect(devkit.generateFiles).not.toHaveBeenCalled();
|
||||
expect(devkit.addDependenciesToPackageJson).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should create karma.conf.js when karma is installed', async () => {
|
||||
jest.spyOn(devkit, 'generateFiles');
|
||||
jest.spyOn(devkit, 'addDependenciesToPackageJson');
|
||||
devkit.updateJson(tree, 'package.json', (json) => {
|
||||
json.devDependencies = { karma: '~5.0.0' };
|
||||
return json;
|
||||
});
|
||||
|
||||
await karmaGenerator(tree, {});
|
||||
|
||||
expect(devkit.generateFiles).toHaveBeenCalled();
|
||||
expect(devkit.addDependenciesToPackageJson).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should add karma dependencies', async () => {
|
||||
await karmaGenerator(tree, {});
|
||||
|
||||
const { dependencies, devDependencies } = devkit.readJson(
|
||||
tree,
|
||||
'package.json'
|
||||
);
|
||||
expect(devDependencies['karma']).toBeDefined();
|
||||
expect(devDependencies['karma-chrome-launcher']).toBeDefined();
|
||||
expect(devDependencies['karma-coverage']).toBeDefined();
|
||||
expect(devDependencies['karma-jasmine']).toBeDefined();
|
||||
expect(devDependencies['karma-jasmine-html-reporter']).toBeDefined();
|
||||
expect(devDependencies['jasmine-core']).toBeDefined();
|
||||
expect(devDependencies['jasmine-spec-reporter']).toBeDefined();
|
||||
expect(devDependencies['@types/jasmine']).toBeDefined();
|
||||
expect(devDependencies['@types/node']).toBeDefined();
|
||||
expect(dependencies['@angular/core']).toEqual('14.1.0');
|
||||
});
|
||||
|
||||
it('should add karma configuration', async () => {
|
||||
await karmaGenerator(tree, {});
|
||||
|
||||
expect(tree.exists('karma.conf.js')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should add inputs for test targets', async () => {
|
||||
updateJson<NxJsonConfiguration>(tree, 'nx.json', (json) => {
|
||||
json.namedInputs ??= {};
|
||||
json.namedInputs.production = ['default', '^production'];
|
||||
return json;
|
||||
});
|
||||
await karmaGenerator(tree, {});
|
||||
|
||||
const nxJson = readJson<NxJsonConfiguration>(tree, 'nx.json');
|
||||
expect(nxJson.namedInputs.production).toContain(
|
||||
'!{projectRoot}/karma.conf.js'
|
||||
);
|
||||
expect(nxJson.namedInputs.production).toContain(
|
||||
'!{projectRoot}/tsconfig.spec.json'
|
||||
);
|
||||
expect(nxJson.namedInputs.production).toContain(
|
||||
'!{projectRoot}/**/*.spec.[jt]s'
|
||||
);
|
||||
expect(nxJson.targetDefaults.test).toEqual({
|
||||
inputs: ['default', '^production', '{workspaceRoot}/karma.conf.js'],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,3 +0,0 @@
|
||||
export interface GeneratorOptions {
|
||||
skipPackageJson?: boolean;
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/schema",
|
||||
"$id": "NxAngularKarmaGenerator",
|
||||
"title": "Add Karma Configuration to the workspace.",
|
||||
"description": "Add Karma configuration to an Nx workspace.",
|
||||
"cli": "nx",
|
||||
"type": "object",
|
||||
"examples": [
|
||||
{
|
||||
"command": "nx g @nrwl/angular:karma",
|
||||
"description": "Add a base karma configuration to the workspace."
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"skipPackageJson": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Do not add dependencies to `package.json`.",
|
||||
"x-priority": "internal"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": []
|
||||
}
|
||||
@ -359,21 +359,6 @@ describe('lib', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should leave the excludes alone when unitTestRunner is karma', async () => {
|
||||
// ACT
|
||||
await runLibraryGeneratorWithOpts({
|
||||
unitTestRunner: UnitTestRunner.Karma,
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
const tsconfigJson = readJson(tree, 'libs/my-lib/tsconfig.lib.json');
|
||||
expect(tsconfigJson.exclude).toEqual([
|
||||
'src/**/*.spec.ts',
|
||||
'jest.config.ts',
|
||||
'src/**/*.test.ts',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should remove the excludes when unitTestRunner is none', async () => {
|
||||
// ACT
|
||||
await runLibraryGeneratorWithOpts({
|
||||
|
||||
@ -15,7 +15,6 @@ import init from '../../generators/init/init';
|
||||
import { E2eTestRunner } from '../../utils/test-runners';
|
||||
import { getPkgVersionForAngularMajorVersion } from '../../utils/version-utils';
|
||||
import addLintingGenerator from '../add-linting/add-linting';
|
||||
import karmaProjectGenerator from '../karma-project/karma-project';
|
||||
import setupTailwindGenerator from '../setup-tailwind/setup-tailwind';
|
||||
import { getInstalledAngularVersionInfo } from '../utils/version-utils';
|
||||
import { addBuildableLibrariesPostCssDependencies } from '../utils/dependencies';
|
||||
@ -153,11 +152,6 @@ async function addUnitTestRunner(
|
||||
skipFormat: true,
|
||||
skipPackageJson: options.skipPackageJson,
|
||||
});
|
||||
} else if (options.unitTestRunner === 'karma') {
|
||||
await karmaProjectGenerator(host, {
|
||||
project: options.name,
|
||||
skipFormat: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
"title": "Create a library",
|
||||
"description": "Creates an Angular library.",
|
||||
"type": "object",
|
||||
|
||||
"cli": "nx",
|
||||
"properties": {
|
||||
"name": {
|
||||
@ -96,7 +95,7 @@
|
||||
},
|
||||
"unitTestRunner": {
|
||||
"type": "string",
|
||||
"enum": ["karma", "jest", "none"],
|
||||
"enum": ["jest", "none"],
|
||||
"description": "Test runner to use for unit tests.",
|
||||
"default": "jest"
|
||||
},
|
||||
|
||||
@ -99,7 +99,7 @@
|
||||
},
|
||||
"unitTestRunner": {
|
||||
"type": "string",
|
||||
"enum": ["karma", "jest", "none"],
|
||||
"enum": ["jest", "none"],
|
||||
"description": "Test runner to use for unit tests.",
|
||||
"default": "jest"
|
||||
},
|
||||
|
||||
@ -19,9 +19,18 @@ describe('Migration to update target and add useDefineForClassFields', () => {
|
||||
});
|
||||
await applicationGenerator(tree, {
|
||||
name: 'karma',
|
||||
unitTestRunner: UnitTestRunner.Karma,
|
||||
unitTestRunner: UnitTestRunner.None,
|
||||
});
|
||||
|
||||
const karmaProject = readProjectConfiguration(tree, 'karma');
|
||||
karmaProject.targets.test = {
|
||||
executor: '@angular-devkit/build-angular:karma',
|
||||
options: {
|
||||
tsConfig: 'apps/karma/tsconfig.spec.json',
|
||||
},
|
||||
};
|
||||
updateProjectConfiguration(tree, 'karma', karmaProject);
|
||||
|
||||
// Create tsconfigs
|
||||
const compilerOptions = { target: 'es2015', module: 'es2020' };
|
||||
const configWithExtends = {
|
||||
|
||||
@ -34,11 +34,6 @@ export const backwardCompatibleVersions: Record<
|
||||
tsNodeVersion: '10.9.1',
|
||||
jestPresetAngularVersion: '~12.2.3',
|
||||
protractorVersion: '~7.0.0',
|
||||
karmaVersion: '~6.4.0',
|
||||
karmaChromeLauncherVersion: '~3.1.0',
|
||||
karmaCoverageVersion: '~2.2.0',
|
||||
karmaJasmineVersion: '~5.1.0',
|
||||
karmaJasmineHtmlReporterVersion: '~2.0.0',
|
||||
jasmineCoreVersion: '~4.2.0',
|
||||
jasmineSpecReporterVersion: '~7.0.0',
|
||||
typesJasmineVersion: '~4.0.0',
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
export enum UnitTestRunner {
|
||||
Karma = 'karma',
|
||||
Jest = 'jest',
|
||||
None = 'none',
|
||||
}
|
||||
|
||||
export enum E2eTestRunner {
|
||||
/**
|
||||
* @deprecated Protractor is no longer maintained. Support for generating
|
||||
|
||||
@ -25,11 +25,6 @@ export const tsNodeVersion = '10.9.1';
|
||||
|
||||
export const jestPresetAngularVersion = '~13.0.0';
|
||||
export const protractorVersion = '~7.0.0';
|
||||
export const karmaVersion = '~6.4.0';
|
||||
export const karmaChromeLauncherVersion = '~3.1.0';
|
||||
export const karmaCoverageVersion = '~2.2.0';
|
||||
export const karmaJasmineVersion = '~5.1.0';
|
||||
export const karmaJasmineHtmlReporterVersion = '~2.0.0';
|
||||
export const jasmineCoreVersion = '~4.2.0';
|
||||
export const jasmineSpecReporterVersion = '~7.0.0';
|
||||
export const typesJasmineVersion = '~4.0.0';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user