File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed
packages/core/src/runtime/worker Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ import { expect , it } from '@rstest/core' ;
2+
3+ it ( 'should test json file correctly' , async ( ) => {
4+ const jsonPath = './test.json' ;
5+ // will external and load json file in runtime
6+ const json = await import ( jsonPath ) ;
7+ // will bundle json file during build
8+ const jsonA = await import ( './test.json' ) ;
9+
10+ expect ( json . value ) . toBe ( 123 ) ;
11+ expect ( json ) . toEqual ( jsonA ) ;
12+ } ) ;
Original file line number Diff line number Diff line change 1+ {
2+ "value" : 123
3+ }
Original file line number Diff line number Diff line change @@ -82,6 +82,21 @@ const defineRstestDynamicImport =
8282 delete importAttributes . with . rstest ;
8383 }
8484
85+ if ( modulePath . endsWith ( '.json' ) ) {
86+ // const json = await import(jsonPath);
87+ // should return { default: jsonExports, ...jsonExports }
88+ const importedModule = await import ( modulePath , {
89+ with : { type : 'json' } ,
90+ } ) ;
91+
92+ return returnModule
93+ ? asModule ( importedModule . default , importedModule . default )
94+ : {
95+ ...importedModule . default ,
96+ default : importedModule . default ,
97+ } ;
98+ }
99+
85100 const importedModule = await import ( modulePath , importAttributes ) ;
86101
87102 if (
You can’t perform that action at this time.
0 commit comments