Skip to content

Commit 555b834

Browse files
authored
fix(tests): mock node:zlib (#2761)
* fix: add jest resolver to fix unit tests * chore: lint * chore: fix lint warnings * chore: remove resolver
1 parent 6140100 commit 555b834

File tree

7 files changed

+451
-225
lines changed

7 files changed

+451
-225
lines changed

__e2e__/default.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ afterEach(() => {
1111
});
1212

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

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

__e2e__/init.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ test('init supports --pm yarn together with --skip-install', () => {
191191
});
192192

193193
// react-native-macos stopped shipping `template.config.js` for 0.75, so this test is disabled. in future releases we should re-enable once `template.config.js` will be there again.
194+
// eslint-disable-next-line jest/no-disabled-tests
194195
test.skip('init --platform-name should work for out of tree platform', () => {
195196
createCustomTemplateFiles();
196197
const outOfTreePlatformName = 'react-native-macos';

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-doctor/src/tools/healthchecks/androidStudio.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ export default {
5454
`studio${archSuffix}.exe`,
5555
).replace(/\\/g, '\\\\');
5656
try {
57-
const {stdout} = await executeCommand(
57+
const {stdout: fallbackStdout} = await executeCommand(
5858
`wmic datafile where name="${fallbackPath}" get Version`,
5959
);
60-
version = stdout.replace(/(\r\n|\n|\r)/gm, '').trim();
60+
version = fallbackStdout.replace(/(\r\n|\n|\r)/gm, '').trim();
6161
} catch {
6262
version = '';
6363
}

packages/cli-platform-apple/src/commands/runCommand/getBuildSettings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ export async function getBuildSettings(
4141
.filter((setting: any) => setting.buildSettings.WRAPPER_EXTENSION === 'app')
4242
.map(({target: settingsTarget}: any) => settingsTarget);
4343

44-
if (applicationTargets.length === 0) return null;
44+
if (applicationTargets.length === 0) {
45+
return null;
46+
}
4547

4648
let selectedTarget = applicationTargets[0];
4749

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)