Skip to content

Commit f8d6b75

Browse files
committed
run yarn link in a way that is a bit more reslilient across OS/filesystem combinations. it looks like there's a latent race in e2e tests where sometimes a directory doesn't exist yet, or was already removed. this isn't a new issue, so check for directory before removal. trim stdout/stderr in the test helpers, not just in one test.
1 parent 884c070 commit f8d6b75

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

__e2e__/config.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ beforeEach(() => {
5151
runCLI(DIR, ['init', 'TestProject', '--install-pods']);
5252

5353
// Link CLI to the project
54-
spawnScript('yarn', ['link', __dirname, '--all'], {
54+
const cliPath = path.resolve(__dirname, '../packages/cli');
55+
spawnScript('yarn', ['link'], {
56+
cwd: cliPath,
57+
});
58+
spawnScript('yarn', ['link', '@react-native-community/cli'], {
5559
cwd: path.join(DIR, 'TestProject'),
5660
});
5761
});
@@ -108,7 +112,8 @@ test('should log only valid JSON config if setting up env throws an error', () =
108112
? stderr
109113
.split('\n')
110114
.filter(
111-
(line) => !line.startsWith('warn Multiple Podfiles were found'),
115+
(line: string) =>
116+
!line.startsWith('warn Multiple Podfiles were found'),
112117
)
113118
.join('\n')
114119
: stderr;
@@ -199,7 +204,7 @@ test('should fail if using require() in ES module in react-native.config.mjs', (
199204
'test-command-esm',
200205
]);
201206
expect(stderr).toMatch('error Failed to load configuration of your project');
202-
expect(stdout).toMatch(/Cannot require\(\) ES Module/);
207+
expect(stdout).toMatch(/require is not defined in ES module scope/);
203208
});
204209

205210
test('should fail if using require() in ES module with "type": "module" in package.json', () => {

__e2e__/root.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ beforeAll(() => {
1919
runCLI(DIR, ['init', 'TestProject', `--pm`, 'npm', `--install-pods`]);
2020

2121
// Link CLI to the project
22-
spawnScript('yarn', ['link', __dirname, '--all'], {
22+
const cliPath = path.resolve(__dirname, '../packages/cli');
23+
spawnScript('yarn', ['link'], {
24+
cwd: cliPath,
25+
});
26+
spawnScript('yarn', ['link', '@react-native-community/cli'], {
2327
cwd: path.join(DIR, 'TestProject'),
2428
});
2529
});

jest/helpers.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export const makeTemplate =
4545
});
4646

4747
export const cleanup = (directory: string) => {
48-
fs.rmSync(directory, {recursive: true, force: true, maxRetries: 10});
48+
if (fs.existsSync(directory)) {
49+
fs.rmSync(directory, {recursive: true, force: true, maxRetries: 10});
50+
}
4951
};
5052

5153
/**
@@ -115,8 +117,8 @@ export const spawnScript: SpawnFunction<any> = (execPath, args, options) => {
115117
// Transform spawnSync result to match execa format
116118
const execaLikeResult = {
117119
exitCode: result.status || 0,
118-
stdout: result.stdout || '',
119-
stderr: result.stderr || '',
120+
stdout: result.stdout?.trim() || '',
121+
stderr: result.stderr?.trim() || '',
120122
failed: result.status !== 0,
121123
};
122124

0 commit comments

Comments
 (0)