|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +'use strict'; |
| 4 | + |
| 5 | +const {spawn} = require('child_process'); |
| 6 | +const {join} = require('path'); |
| 7 | + |
| 8 | +const ROOT_PATH = join(__dirname, '..', '..'); |
| 9 | + |
| 10 | +let serverProcess = null; |
| 11 | +let testProcess = null; |
| 12 | + |
| 13 | +function runTestShell() { |
| 14 | + const shellPackagePath = join(ROOT_PATH, 'packages', 'react-devtools-shell'); |
| 15 | + |
| 16 | + const timeoutID = setTimeout(() => { |
| 17 | + // Assume the test shell server failed to start. |
| 18 | + console.error('Testing shell server failed to start'); |
| 19 | + exitWithCode(1); |
| 20 | + }, 30000); |
| 21 | + |
| 22 | + console.log('Starting testing shell server'); |
| 23 | + |
| 24 | + serverProcess = spawn('yarn', ['start'], {cwd: shellPackagePath}); |
| 25 | + serverProcess.stdout.on('data', data => { |
| 26 | + if (`${data}`.includes('Compiled successfully.')) { |
| 27 | + console.log('Testing shell server running'); |
| 28 | + |
| 29 | + clearTimeout(timeoutID); |
| 30 | + |
| 31 | + runEndToEndTests(); |
| 32 | + } |
| 33 | + }); |
| 34 | + serverProcess.stderr.on('data', data => { |
| 35 | + // Mostly non-fatal errors like Babel optimization warnings etc. |
| 36 | + // But we do need to handle the case where the port is already in use. |
| 37 | + console.error(`${data}`); |
| 38 | + if (`${data}`.includes('EADDRINUSE')) { |
| 39 | + console.log('Free up the port and re-run tests:'); |
| 40 | + console.log(' kill -9 $(lsof -ti:8080)'); |
| 41 | + |
| 42 | + exitWithCode(1); |
| 43 | + } |
| 44 | + }); |
| 45 | +} |
| 46 | + |
| 47 | +async function runEndToEndTests() { |
| 48 | + const inlinePackagePath = join( |
| 49 | + ROOT_PATH, |
| 50 | + 'packages', |
| 51 | + 'react-devtools-inline' |
| 52 | + ); |
| 53 | + |
| 54 | + console.log('Running e2e tests'); |
| 55 | + |
| 56 | + testProcess = spawn('yarn', ['test:e2e'], {cwd: inlinePackagePath}); |
| 57 | + testProcess.stdout.on('data', data => { |
| 58 | + console.log(`${data}`); |
| 59 | + }); |
| 60 | + testProcess.stderr.on('data', data => { |
| 61 | + console.error(`${data}`); |
| 62 | + exitWithCode(1); |
| 63 | + }); |
| 64 | + testProcess.on('close', code => { |
| 65 | + console.log(`Tests completed with code: ${code}`); |
| 66 | + exitWithCode(code); |
| 67 | + }); |
| 68 | +} |
| 69 | + |
| 70 | +function exitWithCode(code) { |
| 71 | + if (serverProcess !== null) { |
| 72 | + try { |
| 73 | + console.log('Shutting down shell server process'); |
| 74 | + serverProcess.kill(); |
| 75 | + } catch (error) { |
| 76 | + console.error(error); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + if (testProcess !== null) { |
| 81 | + try { |
| 82 | + console.log('Shutting down test process'); |
| 83 | + testProcess.kill(); |
| 84 | + } catch (error) { |
| 85 | + console.error(error); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + process.exit(code); |
| 90 | +} |
| 91 | + |
| 92 | +runTestShell(); |
0 commit comments