Skip to content

Commit

Permalink
fix(testing): add root karma config if one isn't present when using k…
Browse files Browse the repository at this point in the history
…arma-project generator

when using the karma-project generator directory ensure the karma generator (install deps/root
config) is called if the root karma config isn't present

ISSUES CLOSED: #9234
  • Loading branch information
barbados-clemens committed Mar 23, 2022
1 parent d5102f0 commit e0ecb96
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/generated/api-angular/generators/karma-project.md
Expand Up @@ -42,3 +42,11 @@ Default: `false`
Type: `boolean`

Skip formatting files.

### skipPackageJson

Default: `false`

Type: `boolean`

Skip updating package.json.
Expand Up @@ -41,11 +41,13 @@ describe('karmaProject', () => {
});

it('should generate files', async () => {
expect(tree.exists('karma.conf.js')).toBeFalsy();
await karmaProjectGenerator(tree, { project: 'lib1' });

expect(tree.exists('/libs/lib1/karma.conf.js')).toBeTruthy();
expect(tree.exists('/libs/lib1/tsconfig.spec.json')).toBeTruthy();
expect(tree.exists('/libs/lib1/src/test.ts')).toBeTruthy();
expect(tree.exists('karma.conf.js')).toBeTruthy();
});

it('should create a karma.conf.js', async () => {
Expand Down
Expand Up @@ -5,11 +5,15 @@ 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
) {
if (!tree.exists('karma.conf.js')) {
karmaGenerator(tree, options);
}
checkProjectTestTarget(tree, options.project);
generateKarmaProjectFiles(tree, options.project);
updateTsConfigs(tree, options.project);
Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/generators/karma-project/schema.d.ts
@@ -1,4 +1,5 @@
export interface KarmaProjectOptions {
project: string;
skipFormat?: boolean;
skipPackageJson?: boolean;
}
5 changes: 5 additions & 0 deletions packages/angular/src/generators/karma-project/schema.json
Expand Up @@ -16,6 +16,11 @@
"description": "Skip formatting files.",
"type": "boolean",
"default": false
},
"skipPackageJson": {
"description": "Skip updating package.json.",
"type": "boolean",
"default": false
}
},
"additionalProperties": false,
Expand Down

0 comments on commit e0ecb96

Please sign in to comment.