File tree Expand file tree Collapse file tree 4 files changed +57
-0
lines changed Expand file tree Collapse file tree 4 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -37,11 +37,13 @@ ESBUILD_TESTS = [
3737 "tests/commands/serve/ssr-http-requests-assets.js" ,
3838 "tests/i18n/**" ,
3939 "tests/vite/**" ,
40+ "tests/vitest/**" ,
4041 "tests/test/**" ,
4142]
4243
4344WEBPACK_IGNORE_TESTS = [
4445 "tests/vite/**" ,
46+ "tests/vitest/**" ,
4547 "tests/build/app-shell/**" ,
4648 "tests/i18n/ivy-localize-app-shell.js" ,
4749 "tests/i18n/ivy-localize-app-shell-service-worker.js" ,
Original file line number Diff line number Diff line change 1+ import assert from 'node:assert/strict' ;
2+ import { applyVitestBuilder } from '../../utils/vitest' ;
3+ import { ng } from '../../utils/process' ;
4+
5+ export default async function ( ) : Promise < void > {
6+ await applyVitestBuilder ( ) ;
7+
8+ const { stderr } = await ng ( 'test' ) ;
9+
10+ assert . match (
11+ stderr ,
12+ / N O T E : T h e " u n i t - t e s t " b u i l d e r i s c u r r e n t l y E X P E R I M E N T A L / ,
13+ 'Expected stderr to include the experimental notice.' ,
14+ ) ;
15+ }
Original file line number Diff line number Diff line change 1+ import assert from 'node:assert/strict' ;
2+ import { applyVitestBuilder } from '../../utils/vitest' ;
3+ import { ng } from '../../utils/process' ;
4+
5+ export default async function ( ) : Promise < void > {
6+ await applyVitestBuilder ( ) ;
7+ await ng ( 'generate' , 'component' , 'my-comp' ) ;
8+
9+ const { stdout } = await ng ( 'test' ) ;
10+
11+ assert . match ( stdout , / 2 p a s s e d / , 'Expected 2 tests to pass.' ) ;
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 Vitest. */
5+ export async function applyVitestBuilder ( ) : Promise < void > {
6+ await silentNpm ( 'install' , '[email protected] ' , '[email protected] ' , '--save-dev' ) ; 7+
8+ await updateJsonFile ( 'angular.json' , ( json ) => {
9+ const projects = Object . values ( json [ 'projects' ] ) ;
10+ if ( projects . length !== 1 ) {
11+ throw new Error (
12+ `Expected exactly one project but found ${ projects . length } projects named ${ Object . keys (
13+ json [ 'projects' ] ,
14+ ) . join ( ', ' ) } `,
15+ ) ;
16+ }
17+ const project = projects [ 0 ] ! as any ;
18+
19+ // Update to Vitest builder.
20+ const test = project [ 'architect' ] [ 'test' ] ;
21+ test [ 'builder' ] = '@angular/build:unit-test' ;
22+ test [ 'options' ] = {
23+ tsConfig : test [ 'options' ] [ 'tsConfig' ] ,
24+ buildTarget : '::development' ,
25+ runner : 'vitest' ,
26+ } ;
27+ } ) ;
28+ }
You can’t perform that action at this time.
0 commit comments