File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ import { applyJestBuilder } from '../../utils/jest' ;
2+ import { ng } from '../../utils/process' ;
3+
4+ export default async function ( ) : Promise < void > {
5+ await applyJestBuilder ( ) ;
6+
7+ const { stderr } = await ng ( 'test' ) ;
8+
9+ if ( ! stderr . includes ( 'Jest builder is currently EXPERIMENTAL' ) ) {
10+ throw new Error ( `No experimental notice in stderr.\nSTDERR:\n\n${ stderr } ` ) ;
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ import { silentNpm } from './process' ;
2+ import { updateJsonFile } from './project' ;
3+
4+ /** Updates the `test` builder in the current workspace to use Jest with the given options. */
5+ export async function applyJestBuilder (
6+ options : { } = {
7+ tsConfig : 'tsconfig.spec.json' ,
8+ polyfills : [ 'zone.js' , 'zone.js/testing' ] ,
9+ } ,
10+ ) : Promise < void > {
11+ await silentNpm ( 'install' , 'jest@29.5.0' , 'jest-environment-jsdom@29.5.0' , '--save-dev' ) ;
12+
13+ await updateJsonFile ( 'angular.json' , ( json ) => {
14+ const projects = Object . values ( json [ 'projects' ] ) ;
15+ if ( projects . length !== 1 ) {
16+ throw new Error (
17+ `Expected exactly one project but found ${ projects . length } projects named ${ Object . keys (
18+ json [ 'projects' ] ,
19+ ) . join ( ', ' ) } `,
20+ ) ;
21+ }
22+ const project = projects [ 0 ] ! as any ;
23+
24+ // Update to Jest builder.
25+ const test = project [ 'architect' ] [ 'test' ] ;
26+ test [ 'builder' ] = '@angular-devkit/build-angular:jest' ;
27+ test [ 'options' ] = options ;
28+ } ) ;
29+ }
You can’t perform that action at this time.
0 commit comments