Skip to content

Commit 373232e

Browse files
committed
fix: add jest resolver to fix unit tests
1 parent bd8927e commit 373232e

6 files changed

Lines changed: 463 additions & 231 deletions

File tree

__e2e__/default.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import {runCLI, getTempDirectory, cleanup, writeFiles} from '../jest/helpers';
1+
import { runCLI, getTempDirectory, cleanup, writeFiles } from "../jest/helpers";
22

3-
const DIR = getTempDirectory('test_default_behavior');
3+
const DIR = getTempDirectory("test_default_behavior");
44

55
beforeEach(() => {
6-
cleanup(DIR);
7-
writeFiles(DIR, {});
6+
cleanup(DIR);
7+
writeFiles(DIR, {});
88
});
99
afterEach(() => {
10-
cleanup(DIR);
10+
cleanup(DIR);
1111
});
1212

13-
test('shows up help information without passing in any args', () => {
14-
const {stderr} = runCLI(DIR);
15-
expect(stderr).toMatchSnapshot();
13+
test("shows up help information without passing in any args", () => {
14+
const { stderr } = runCLI(DIR, [], { expectedFailure: true });
15+
expect(stderr).toMatchSnapshot();
1616
});
1717

18-
test('does not pass --platform-name by default', () => {
19-
const {stderr} = runCLI(DIR);
20-
expect(stderr).not.toContain("unknown option '--platform-name'");
18+
test("does not pass --platform-name by default", () => {
19+
const { stderr } = runCLI(DIR, [], { expectedFailure: true });
20+
expect(stderr).not.toContain("unknown option '--platform-name'");
2121
});

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const common = {
22
testEnvironment: 'node',
33
snapshotSerializers: [require.resolve('jest-snapshot-serializer-raw')],
44
testRunner: 'jest-circus/runner',
5+
resolver: '<rootDir>/jest/resolver.js',
56
};
67

78
module.exports = {

jest/resolver.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = (request, options) => {
2+
// strip 'node:' prefix from built-in modules
3+
if (request.startsWith('node:')) {
4+
return options.defaultResolver(request.slice(5), options);
5+
}
6+
7+
return options.defaultResolver(request, options);
8+
};

jest/setupUnitTests.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// mock node: prefixed built-in modules for Jest 26 compatibility
2+
jest.mock('node:zlib', () => require('zlib'), { virtual: true });
3+
14
jest.mock('@react-native-community/cli-tools', () => {
25
return {
36
...jest.requireActual('@react-native-community/cli-tools'),

packages/cli-server-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"dependencies": {
1010
"@react-native-community/cli-tools": "20.1.1",
11-
"body-parser": "^1.20.3",
11+
"body-parser": "^2.2.2",
1212
"compression": "^1.7.1",
1313
"connect": "^3.6.5",
1414
"errorhandler": "^1.5.1",

0 commit comments

Comments
 (0)