Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 12 additions & 21 deletions lib/cli/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ import { Logger } from '../logger';
import * as configHelpers from './config';
import * as run from './run';
import * as reportHelpers from '../report';
import * as websocketHelpers from '../websocket';

describe('run.ts', () => {
const logger = new Logger();
const bundleIdIOS = 'org.reactjs.native.example.RNDemo';
const mockBundleIdResponse = { stdout: bundleIdIOS } as ExecaReturnValue<any>;
const mockStartWebSocketServer = jest
.spyOn(websocketHelpers, 'startWebSocketServer')
.mockResolvedValue(undefined!);

describe('runOS', () => {
const execMock = jest.spyOn(execa, 'command').mockImplementation();
const execKillMock = {
kill: jest.fn(),
} as unknown as execa.ExecaChildProcess<any>;
const execMock = jest.spyOn(execa, 'command').mockImplementation();

beforeEach(() => {
execMock.mockReset();
});
beforeEach(() => {
execMock.mockReset().mockReturnValue(execKillMock);
});

describe('runOS', () => {
it('runs an iOS project - with the default build command', async () => {
const cwd = path.join(
process.cwd(),
Expand Down Expand Up @@ -116,12 +115,6 @@ describe('run.ts', () => {
'/android/app/build/outputs/apk/debug'
);

const execMock = jest.spyOn(execa, 'command').mockImplementation();

beforeEach(() => {
execMock.mockReset();
});

it('runs an Android project - with the default build command', async () => {
const appPath = path.join(cwd, 'app-debug.apk');

Expand Down Expand Up @@ -214,7 +207,6 @@ describe('run.ts', () => {
beforeEach(() => {
commandSyncMock.mockReset();
mockGenerateReport.mockReset();
mockStartWebSocketServer.mockReset();
});

it('runs an iOS project', async () => {
Expand Down Expand Up @@ -273,15 +265,14 @@ describe('run.ts', () => {
});
});

it('runs the createWebSocketServer helper', async () => {
it('runs the scripts/websocket-server.js script', async () => {
jest.spyOn(configHelpers, 'getConfig').mockResolvedValueOnce(config);

const mockRunIOS = jest.spyOn(run, 'runIOS').mockResolvedValueOnce();

await run.runHandler({ ...args });

await expect(mockRunIOS).toHaveBeenCalled();
await expect(mockStartWebSocketServer).toHaveBeenCalledTimes(1);
await expect(execMock.mock.calls[0][0]).toEqual(
'node scripts/websocket-server.js'
);
});

it('runs generates the report if the config is set to on', async () => {
Expand Down
11 changes: 9 additions & 2 deletions lib/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { CliRunOptions, Config } from '../types';
import { generateReport } from '../report';
import { getConfig } from './config';
import { Logger } from '../logger';
import { startWebSocketServer } from '../websocket';

export const runIOS = async (config: Config, logger: Logger) => {
const stdio = config.debug ? 'inherit' : 'ignore';
Expand Down Expand Up @@ -73,7 +72,13 @@ export const runHandler = async (args: CliRunOptions) => {
const runProject = args.platform === 'ios' ? runIOS : runAndroid;

logger.print(`[OWL] Starting websocket server.`);
await startWebSocketServer(logger);
const webSocketProcess = execa.command('node scripts/websocket-server.js', {
stdio: 'inherit',
cwd: path.join(__dirname, '..', '..'),
env: {
OWL_DEBUG: String(!!config.debug),
},
});

logger.print(`[OWL] Running tests on ${args.platform}.`);
await runProject(config, logger);
Expand Down Expand Up @@ -107,6 +112,8 @@ export const runHandler = async (args: CliRunOptions) => {
}

throw err;
} finally {
webSocketProcess.kill();
}

logger.print(`[OWL] Tests completed on ${args.platform}.`);
Expand Down
14 changes: 14 additions & 0 deletions scripts/websocket-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { startWebSocketServer } = require('../dist/websocket');
const { Logger } = require('../dist/logger');

const debug = process.env.OWL_DEBUG === 'true';
const logger = new Logger(!!debug);

(async function () {
try {
await startWebSocketServer(logger);
} catch (e) {
logger.error(`[OWL] Websocket server failed to start: ${e}`);
process.exit(1);
}
})();