File tree Expand file tree Collapse file tree 4 files changed +28
-2
lines changed
e2e/projects/fixtures/packages/node
packages/core/src/core/plugins Expand file tree Collapse file tree 4 files changed +28
-2
lines changed Original file line number Diff line number Diff line change
1
+ // we can also use `import`, but then
2
+ // every export should be explicitly defined
3
+
4
+ const { fs } = require ( 'memfs' ) ;
5
+
6
+ module . exports = fs ;
Original file line number Diff line number Diff line change
1
+ import { readFileSync } from 'node:fs' ;
2
+
3
+ export function readSomeFile ( path : string ) {
4
+ return readFileSync ( path , 'utf-8' ) ;
5
+ }
Original file line number Diff line number Diff line change
1
+ import { expect , it , rs } from '@rstest/core' ;
2
+ import { fs } from 'memfs' ;
3
+ import { readSomeFile } from '../src/readSomeFile' ;
4
+
5
+ rs . mock ( 'node:fs' ) ;
6
+
7
+ it ( 'should return correct text' , ( ) => {
8
+ const path = '/hello-world.txt' ;
9
+ fs . writeFileSync ( path , 'hello world' ) ;
10
+
11
+ const text = readSomeFile ( path ) ;
12
+ expect ( text ) . toBe ( 'hello world' ) ;
13
+ } ) ;
Original file line number Diff line number Diff line change @@ -20,7 +20,9 @@ export const pluginBasic: (context: RstestContext) => RsbuildPlugin = (
20
20
tools,
21
21
performance,
22
22
dev,
23
+ testEnvironment,
23
24
} ,
25
+ rootPath,
24
26
} = context . projects . find ( ( p ) => p . environmentName === name ) ! ;
25
27
return mergeEnvironmentConfig (
26
28
config ,
@@ -63,7 +65,7 @@ export const pluginBasic: (context: RstestContext) => RsbuildPlugin = (
63
65
injectModulePathName : true ,
64
66
importMetaPathName : true ,
65
67
hoistMockModule : true ,
66
- manualMockRoot : path . resolve ( context . rootPath , '__mocks__' ) ,
68
+ manualMockRoot : path . resolve ( rootPath , '__mocks__' ) ,
67
69
} ) ,
68
70
) ;
69
71
@@ -90,7 +92,7 @@ export const pluginBasic: (context: RstestContext) => RsbuildPlugin = (
90
92
config . resolve . extensionAlias [ '.js' ] = [ '.js' , '.ts' , '.tsx' ] ;
91
93
config . resolve . extensionAlias [ '.jsx' ] = [ '.jsx' , '.tsx' ] ;
92
94
93
- if ( context . normalizedConfig . testEnvironment === 'node' ) {
95
+ if ( testEnvironment === 'node' ) {
94
96
// skip `module` field in Node.js environment.
95
97
// ESM module resolved by module field is not always a native ESM module
96
98
config . resolve . mainFields = config . resolve . mainFields ?. filter (
You can’t perform that action at this time.
0 commit comments