cli: refactor e2e-test to use runPlain with fix for windows
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user