From 2aca5bb6d45954966e29a87c95ffc90e458eead6 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 2 Jul 2020 09:56:17 +0200 Subject: [PATCH] cli: refactor e2e-test to use runPlain with fix for windows --- packages/cli/e2e-test/cli-e2e-test.js | 15 +++++++-------- packages/cli/e2e-test/helpers.js | 21 +++++++++++++++++++-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/packages/cli/e2e-test/cli-e2e-test.js b/packages/cli/e2e-test/cli-e2e-test.js index ff0e9193b0..b238c726a9 100644 --- a/packages/cli/e2e-test/cli-e2e-test.js +++ b/packages/cli/e2e-test/cli-e2e-test.js @@ -18,17 +18,15 @@ const os = require('os'); const fs = require('fs-extra'); const { resolve: resolvePath, join: joinPath } = require('path'); const Browser = require('zombie'); -const { execFile: execFileCb } = require('child_process'); -const { promisify } = require('util'); const { spawnPiped, + runPlain, handleError, waitForPageWithText, waitFor, waitForExit, print, } = require('./helpers'); -const execFile = promisify(execFileCb); async function main() { const rootDir = await fs.mkdtemp(resolvePath(os.tmpdir(), 'backstage-e2e-')); @@ -58,7 +56,8 @@ async function buildDistWorkspace(workspaceName, rootDir) { await fs.ensureDir(workspaceDir); print(`Preparing workspace`); - await execFile('yarn', [ + await runPlain([ + 'yarn', 'backstage-cli', 'build-workspace', workspaceDir, @@ -72,7 +71,7 @@ async function buildDistWorkspace(workspaceName, rootDir) { await pinYarnVersion(workspaceDir); print('Installing workspace dependencies'); - await execFile('yarn', ['install', '--production', '--frozen-lockfile'], { + await runPlain(['yarn', 'install', '--production', '--frozen-lockfile'], { cwd: workspaceDir, }); @@ -137,11 +136,11 @@ async function createApp(appName, workspaceDir, rootDir) { for (const cmd of ['install', 'tsc', 'build', 'lint:all', 'test:all']) { print(`Running 'yarn ${cmd}' in newly created app`); - await execFile('yarn', [cmd], { cwd: appDir }); + await runPlain(['yarn', cmd], { cwd: appDir }); } print(`Running 'yarn test:e2e:ci' in newly created app`); - await execFile('yarn', ['test:e2e:ci'], { + await runPlain(['yarn', 'test:e2e:ci'], { cwd: resolvePath(appDir, 'packages', 'app'), env: { ...process.env, @@ -202,7 +201,7 @@ async function createPlugin(pluginName, appDir) { const pluginDir = resolvePath(appDir, 'plugins', pluginName); for (const cmd of [['lint'], ['test', '--no-watch']]) { print(`Running 'yarn ${cmd.join(' ')}' in newly created plugin`); - await execFile('yarn', cmd, { cwd: pluginDir }); + await runPlain(['yarn', ...cmd], { cwd: pluginDir }); } return pluginName; diff --git a/packages/cli/e2e-test/helpers.js b/packages/cli/e2e-test/helpers.js index 1292ba19bf..4f5152e0b1 100644 --- a/packages/cli/e2e-test/helpers.js +++ b/packages/cli/e2e-test/helpers.js @@ -14,9 +14,10 @@ * limitations under the License. */ -const childProcess = require('child_process'); +const { spawn, execFile: execFileCb } = require('child_process'); +const { promisify } = require('util'); -const { spawn } = childProcess; +const execFile = promisify(execFileCb); const EXPECTED_LOAD_ERRORS = /ECONNREFUSED|ECONNRESET|did not get to load all resources/; @@ -57,6 +58,21 @@ function spawnPiped(cmd, options) { return child; } +async function runPlain(cmd, options) { + try { + const { stdout } = await execFile(cmd[0], cmd.slice(1), { + ...options, + shell: true, + }); + return stdout.trim(); + } catch (error) { + if (error.stderr) { + process.stderr.write(error.stderr); + } + throw error; + } +} + function handleError(err) { process.stdout.write(`${err.name}: ${err.stack || err.message}\n`); if (typeof err.code === 'number') { @@ -150,6 +166,7 @@ function print(msg) { module.exports = { spawnPiped, + runPlain, handleError, waitFor, waitForExit,