Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
refactor(expo-cli): make spawn failures in eject-test.ts visible
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Dec 22, 2023
1 parent 29cc31b commit 467f610
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
16 changes: 12 additions & 4 deletions packages/expo-cli/e2e/TestUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ExpoConfig } from '@expo/config';
import JsonFile from '@expo/json-file';
import spawnAsync, { SpawnOptions, SpawnResult } from '@expo/spawn-async';
import spawnAsync, { SpawnOptions, SpawnPromise, SpawnResult } from '@expo/spawn-async';
import fs from 'fs';
import path from 'path';

Expand All @@ -14,8 +14,14 @@ function isSpawnResult(errorOrResult: Error): errorOrResult is Error & SpawnResu

export async function runAsync(args: string[], options?: SpawnOptions): Promise<SpawnResult> {
const promise = spawnAsync(EXPO_CLI, args, options);
promise.child.stdout.pipe(process.stdout);
promise.child.stderr.pipe(process.stderr);

promise.child.stdout?.pipe(process.stdout);
promise.child.stderr?.pipe(process.stderr);

return await handleSpawnResult(promise);
}

export async function handleSpawnResult(promise: SpawnPromise<SpawnResult>): Promise<SpawnResult> {
try {
return await promise;
} catch (error: any) {
Expand Down Expand Up @@ -90,7 +96,9 @@ export async function createMinimalProjectAsync(

// TODO(Bacon): We shouldn't need this
// Install the packages so eject can infer the versions
await spawnAsync('yarn', [], { cwd: projectRoot, stdio: ['ignore', 'inherit', 'inherit'] });
await handleSpawnResult(
spawnAsync('yarn', [], { cwd: projectRoot, stdio: ['ignore', 'inherit', 'inherit'] })
);

return projectRoot;
}
19 changes: 10 additions & 9 deletions packages/expo-cli/e2e/__tests__/eject-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
EXPO_CLI,
getBasicExpoConfig,
getBasicPackageJson,
handleSpawnResult,
} from '../TestUtils';

const tempDir = temporary.directory();
Expand All @@ -32,16 +33,16 @@ beforeAll(async () => {

function executeDefaultAsync(cwd: string, args: string[]) {
const promise = spawnAsync(EXPO_CLI, args, { cwd });
promise.child.stdout.pipe(process.stdout);
promise.child.stderr.pipe(process.stderr);
promise.child.stdout?.pipe(process.stdout);
promise.child.stderr?.pipe(process.stderr);

// When the test is prompted to use git, skip message
// TODO(Bacon): this shouldn't be blocking in non-interactive
promise.child.stdout.on('data', data => {
promise.child.stdout?.on('data', data => {
const stdout = data.toString();
// Skip dirty git
if (/Would you like to proceed/.test(stdout)) {
promise.child.stdin.write('\n');
promise.child.stdin?.write('\n');
}
});

Expand All @@ -59,7 +60,7 @@ it(`can eject a minimal project`, async () => {
const res = executeDefaultAsync(projectRoot, ['eject']);

// This shouldn't fail
await res;
await handleSpawnResult(res);

// Test that native folders were generated
expect(fileExists(projectName, 'ios/hworld.xcodeproj')).toBe(true);
Expand All @@ -74,11 +75,11 @@ it(`can eject a minimal project`, async () => {
// Remove main
expect(outputPkgJson.main).toBe(undefined);
// Scripts should be rewritten to use react-native-community/cli
expect(outputPkgJson.scripts['ios']).toBe('expo run:ios');
expect(outputPkgJson.scripts['android']).toBe('expo run:android');
expect(outputPkgJson.scripts['web']).toBe('expo start --web');
expect(outputPkgJson.scripts?.['ios']).toBe('expo run:ios');
expect(outputPkgJson.scripts?.['android']).toBe('expo run:android');
expect(outputPkgJson.scripts?.['web']).toBe('expo start --web');
// Ensure the react-native version doesn't change
expect(outputPkgJson.dependencies['react-native']).toBe(
expect(outputPkgJson.dependencies?.['react-native']).toBe(
getBasicPackageJson().dependencies['react-native']
);
});
Expand Down

0 comments on commit 467f610

Please sign in to comment.