1- import * as configFactory from './vitest-config-factory.js' ;
2- import {
3- createE2ETestConfig ,
4- createIntTestConfig ,
5- createUnitTestConfig ,
6- } from './vitest-setup-presets.js' ;
7-
8- vi . mock ( './vitest-config-factory.js' , ( ) => ( {
1+ const configFactoryMock = vi . hoisted ( ( ) => ( {
92 createVitestConfig : vi . fn ( ) . mockReturnValue ( 'mocked-config' ) ,
103} ) ) ;
114
5+ vi . mock ( './vitest-config-factory.js' , ( ) => configFactoryMock ) ;
6+
127const MOCK_PROJECT_KEY = 'test-package' ;
138
149describe ( 'vitest-setup-presets' , ( ) => {
15- beforeEach ( ( ) => {
10+ let createUnitTestConfig : typeof import ( './vitest-setup-presets.js' ) . createUnitTestConfig ;
11+ let createIntTestConfig : typeof import ( './vitest-setup-presets.js' ) . createIntTestConfig ;
12+ let createE2ETestConfig : typeof import ( './vitest-setup-presets.js' ) . createE2ETestConfig ;
13+
14+ beforeEach ( async ( ) => {
1615 vi . clearAllMocks ( ) ;
16+ ( { createUnitTestConfig, createIntTestConfig, createE2ETestConfig } =
17+ await import ( './vitest-setup-presets.js' ) ) ;
1718 } ) ;
1819
1920 describe ( 'createUnitTestConfig' , ( ) => {
2021 it ( 'should call createVitestConfig with unit kind' , ( ) => {
2122 const result = createUnitTestConfig ( MOCK_PROJECT_KEY ) ;
2223
23- expect ( configFactory . createVitestConfig ) . toHaveBeenCalledWith (
24+ expect ( configFactoryMock . createVitestConfig ) . toHaveBeenCalledWith (
2425 MOCK_PROJECT_KEY ,
2526 'unit' ,
2627 ) ;
@@ -30,7 +31,7 @@ describe('vitest-setup-presets', () => {
3031 it ( 'should handle different project names' , ( ) => {
3132 createUnitTestConfig ( 'my-custom-package' ) ;
3233
33- expect ( configFactory . createVitestConfig ) . toHaveBeenCalledWith (
34+ expect ( configFactoryMock . createVitestConfig ) . toHaveBeenCalledWith (
3435 'my-custom-package' ,
3536 'unit' ,
3637 ) ;
@@ -39,15 +40,18 @@ describe('vitest-setup-presets', () => {
3940 it ( 'should handle empty projectKey' , ( ) => {
4041 createUnitTestConfig ( '' ) ;
4142
42- expect ( configFactory . createVitestConfig ) . toHaveBeenCalledWith ( '' , 'unit' ) ;
43+ expect ( configFactoryMock . createVitestConfig ) . toHaveBeenCalledWith (
44+ '' ,
45+ 'unit' ,
46+ ) ;
4347 } ) ;
4448 } ) ;
4549
4650 describe ( 'createIntTestConfig' , ( ) => {
4751 it ( 'should call createVitestConfig with int kind' , ( ) => {
4852 const result = createIntTestConfig ( MOCK_PROJECT_KEY ) ;
4953
50- expect ( configFactory . createVitestConfig ) . toHaveBeenCalledWith (
54+ expect ( configFactoryMock . createVitestConfig ) . toHaveBeenCalledWith (
5155 MOCK_PROJECT_KEY ,
5256 'int' ,
5357 ) ;
@@ -57,7 +61,7 @@ describe('vitest-setup-presets', () => {
5761 it ( 'should handle different project names' , ( ) => {
5862 createIntTestConfig ( 'integration-package' ) ;
5963
60- expect ( configFactory . createVitestConfig ) . toHaveBeenCalledWith (
64+ expect ( configFactoryMock . createVitestConfig ) . toHaveBeenCalledWith (
6165 'integration-package' ,
6266 'int' ,
6367 ) ;
@@ -68,7 +72,7 @@ describe('vitest-setup-presets', () => {
6872 it ( 'should call createVitestConfig with e2e kind and no options' , ( ) => {
6973 const result = createE2ETestConfig ( MOCK_PROJECT_KEY ) ;
7074
71- expect ( configFactory . createVitestConfig ) . toHaveBeenCalledWith (
75+ expect ( configFactoryMock . createVitestConfig ) . toHaveBeenCalledWith (
7276 MOCK_PROJECT_KEY ,
7377 'e2e' ,
7478 undefined ,
@@ -83,7 +87,7 @@ describe('vitest-setup-presets', () => {
8387
8488 createE2ETestConfig ( MOCK_PROJECT_KEY , options ) ;
8589
86- expect ( configFactory . createVitestConfig ) . toHaveBeenCalledWith (
90+ expect ( configFactoryMock . createVitestConfig ) . toHaveBeenCalledWith (
8791 MOCK_PROJECT_KEY ,
8892 'e2e' ,
8993 options ,
@@ -93,7 +97,7 @@ describe('vitest-setup-presets', () => {
9397 it ( 'should handle testTimeout option' , ( ) => {
9498 createE2ETestConfig ( MOCK_PROJECT_KEY , { testTimeout : 30_000 } ) ;
9599
96- expect ( configFactory . createVitestConfig ) . toHaveBeenCalledWith (
100+ expect ( configFactoryMock . createVitestConfig ) . toHaveBeenCalledWith (
97101 MOCK_PROJECT_KEY ,
98102 'e2e' ,
99103 { testTimeout : 30_000 } ,
@@ -115,17 +119,17 @@ describe('vitest-setup-presets', () => {
115119 createIntTestConfig ( 'pkg2' ) ;
116120 createE2ETestConfig ( 'pkg3' ) ;
117121
118- expect ( configFactory . createVitestConfig ) . toHaveBeenNthCalledWith (
122+ expect ( configFactoryMock . createVitestConfig ) . toHaveBeenNthCalledWith (
119123 1 ,
120124 'pkg1' ,
121125 'unit' ,
122126 ) ;
123- expect ( configFactory . createVitestConfig ) . toHaveBeenNthCalledWith (
127+ expect ( configFactoryMock . createVitestConfig ) . toHaveBeenNthCalledWith (
124128 2 ,
125129 'pkg2' ,
126130 'int' ,
127131 ) ;
128- expect ( configFactory . createVitestConfig ) . toHaveBeenNthCalledWith (
132+ expect ( configFactoryMock . createVitestConfig ) . toHaveBeenNthCalledWith (
129133 3 ,
130134 'pkg3' ,
131135 'e2e' ,
@@ -140,7 +144,7 @@ describe('vitest-setup-presets', () => {
140144 e2e : { test : 'e2e-config' } ,
141145 } ;
142146
143- vi . mocked ( configFactory . createVitestConfig )
147+ vi . mocked ( configFactoryMock . createVitestConfig )
144148 . mockReturnValueOnce ( mockConfigs . unit as any )
145149 . mockReturnValueOnce ( mockConfigs . int as any )
146150 . mockReturnValueOnce ( mockConfigs . e2e as any ) ;
0 commit comments