@@ -16,7 +16,7 @@ import {
1616} from '../setup' ;
1717
1818describeBuilder ( execute , UNIT_TEST_BUILDER_INFO , ( harness ) => {
19- xdescribe ( 'Option: "setupFiles"' , ( ) => {
19+ describe ( 'Option: "setupFiles"' , ( ) => {
2020 beforeEach ( async ( ) => {
2121 setupApplicationTarget ( harness ) ;
2222 } ) ;
@@ -27,19 +27,20 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
2727 setupFiles : [ 'src/setup.ts' ] ,
2828 } ) ;
2929
30- const { result, error } = await harness . executeOnce ( { outputLogsOnFailure : false } ) ;
31- expect ( result ) . toBeUndefined ( ) ;
32- expect ( error ?. message ) . toMatch ( `The specified setup file "src/setup.ts" does not exist.` ) ;
30+ const { result } = await harness . executeOnce ( ) ;
31+ expect ( result ?. success ) . toBeFalse ( ) ;
32+ // TODO: Re-enable once Vite logs are remapped through build system
33+ // expectLog(logs, `The specified setup file "src/setup.ts" does not exist.`);
3334 } ) ;
3435
3536 it ( 'should include the setup files' , async ( ) => {
3637 await harness . writeFiles ( {
37- 'src/setup.ts' : `console.log('Hello from setup.ts') ;` ,
38+ 'src/setup.ts' : `(globalThis as any).setupLoaded = true ;` ,
3839 'src/app/app.component.spec.ts' : `
3940 import { describe, expect, test } from 'vitest'
4041 describe('AppComponent', () => {
4142 test('should create the app', () => {
42- expect(true ).toBe(true);
43+ expect((globalThis as any).setupLoaded ).toBe(true);
4344 });
4445 });` ,
4546 } ) ;
@@ -49,9 +50,45 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
4950 setupFiles : [ 'src/setup.ts' ] ,
5051 } ) ;
5152
52- const { result, logs } = await harness . executeOnce ( ) ;
53+ const { result } = await harness . executeOnce ( ) ;
54+ expect ( result ?. success ) . toBeTrue ( ) ;
55+ } ) ;
56+
57+ it ( 'should allow setup files to configure testing module' , async ( ) => {
58+ pending ( 'failing' ) ;
59+ await harness . writeFiles ( {
60+ 'src/setup.ts' : `
61+ import { TestBed } from '@angular/core/testing';
62+ import { SETUP_LOADED_TOKEN } from './setup-loaded-token';
63+
64+ TestBed.configureTestingModule({
65+ providers: [{provide: SETUP_LOADED_TOKEN, useValue: true}],
66+ });
67+ ` ,
68+ 'src/setup-loaded-token.ts' : `
69+ import { InjectionToken } from '@angular/core';
70+
71+ export const SETUP_LOADED_TOKEN = new InjectionToken<boolean>('SETUP_LOADED_TOKEN');
72+ ` ,
73+ 'src/app/app.component.spec.ts' : `
74+ import { describe, expect, test } from 'vitest';
75+ import { TestBed } from '@angular/core/testing';
76+ import { SETUP_LOADED_TOKEN } from '../setup-loaded-token';
77+
78+ describe('AppComponent', () => {
79+ test('should create the app', () => {
80+ expect(TestBed.inject(SETUP_LOADED_TOKEN)).toBe(true);
81+ });
82+ });` ,
83+ } ) ;
84+
85+ harness . useTarget ( 'test' , {
86+ ...BASE_OPTIONS ,
87+ setupFiles : [ 'src/setup.ts' ] ,
88+ } ) ;
89+
90+ const { result } = await harness . executeOnce ( ) ;
5391 expect ( result ?. success ) . toBeTrue ( ) ;
54- expectLog ( logs , 'Hello from setup.ts' ) ;
5592 } ) ;
5693 } ) ;
5794} ) ;
0 commit comments