Skip to content

Commit cf58f68

Browse files
committed
fix: allow native fs access (#19)
1 parent 8afdcfc commit cf58f68

File tree

7 files changed

+30
-11
lines changed

7 files changed

+30
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"dependencies": {
4545
"aggregate-error": "^3.1.0",
4646
"ansi-escapes": "^4.3.2",
47-
"fs-require": "^1.0.0",
47+
"fs-require": "^1.1.0",
4848
"memfs": "^3.2.2",
4949
"minimist": "^1.2.5",
5050
"source-map-support": "^0.5.19",

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/memfs.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ sourceMapSupport.install({
1717
},
1818
});
1919

20-
export const mRequire = (modulePath: string): any => createFsRequire(mfs)(modulePath);
20+
export const mRequire = (modulePath: string): any => (
21+
createFsRequire(mfs, {
22+
fs: true,
23+
})(modulePath)
24+
);

tests/fixture/tests/passing-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import assert from 'assert';
2+
import fs from 'fs';
23
import { last } from 'lodash-es';
34
import { add } from '~/add';
45

@@ -15,3 +16,11 @@ it('should load esm', () => {
1516
'should be 3',
1617
);
1718
});
19+
20+
it('should access fs', () => {
21+
const dirFiles = fs.readdirSync(__dirname);
22+
assert(
23+
dirFiles.includes('passing-test.js'),
24+
'should find self',
25+
);
26+
});

tests/fixture/webpack.config.function.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ function createFunction() {
55
/** @type {import('webpack').Configuration} */
66
const config = {
77
mode: 'production',
8+
node: {
9+
__dirname: true,
10+
},
811
resolve: {
912
alias: {
1013
'~': path.resolve(__dirname, 'src/'),

tests/fixture/webpack.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const path = require('path');
33
/** @type {import('webpack').Configuration} */
44
const baseConfig = {
55
mode: 'production',
6+
node: {
7+
__dirname: true,
8+
},
69
resolve: {
710
alias: {
811
'~': path.resolve(__dirname, 'src/'),

tests/instant-mocha.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe.each([
3333
cwd: path.resolve('tests/fixture'),
3434
}).catch(error => error);
3535

36-
expect(stdout).toMatch('2 passing');
36+
expect(stdout).toMatch('3 passing');
3737
expect(exitCode).toBe(0);
3838
});
3939

@@ -110,7 +110,7 @@ describe.each([
110110
cwd: path.resolve('tests/fixture'),
111111
}).catch(error => error);
112112

113-
expect(stdout).toMatch('2 passing');
113+
expect(stdout).toMatch('3 passing');
114114
expect(exitCode).toBe(0);
115115
});
116116

@@ -133,20 +133,20 @@ describe.each([
133133
});
134134

135135
const stdoutPassing = await collectStdout(stdoutBuffers);
136-
expect(stdoutPassing).toMatch('2 passing');
136+
expect(stdoutPassing).toMatch('3 passing');
137137

138138
const passingTestPath = './tests/fixture/tests/passing-test.js';
139139
const passingTestSource = (await fs.promises.readFile(passingTestPath)).toString();
140140

141141
await fs.promises.writeFile(passingTestPath, passingTestSource.replace('=== 3', '=== 4'));
142142

143143
const stdoutFailing = await collectStdout(stdoutBuffers);
144-
expect(stdoutFailing).toMatch('1 passing');
144+
expect(stdoutFailing).toMatch('2 passing');
145145

146146
await fs.promises.writeFile(passingTestPath, passingTestSource);
147147

148148
const stdoutPassing2 = await collectStdout(stdoutBuffers);
149-
expect(stdoutPassing2).toMatch('2 passing');
149+
expect(stdoutPassing2).toMatch('3 passing');
150150

151151
instantMochaWatch.cancel();
152152
}, 20000);

0 commit comments

Comments
 (0)