UNPKG

appwright

Version:

E2E mobile app testing done right, with the Playwright test runner

54 lines (53 loc) 1.71 kB
#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const child_process_1 = require("child_process"); const logger_1 = require("../logger"); function cmd(command, options) { let errorLogs = []; return new Promise((resolveFunc, rejectFunc) => { let p = (0, child_process_1.spawn)(command[0], command.slice(1), { env: { ...process.env, ...options.env }, }); p.stdout.on("data", (x) => { const log = x.toString(); if (log.includes("Error")) { errorLogs.push(log); } process.stdout.write(log); }); p.stderr.on("data", (x) => { const log = x.toString(); process.stderr.write(x.toString()); errorLogs.push(log); }); p.on("exit", (code) => { if (code != 0) { // assuming last log is the error message before exiting rejectFunc(errorLogs.slice(-3).join("\n")); } else { resolveFunc(code); } }); }); } async function runPlaywrightCmd(args) { const pwRunCmd = `npx playwright ${args}`; return cmd(pwRunCmd.split(" "), {}); } (async function main() { const defaultConfigFile = `appwright.config.ts`; const pwOptions = process.argv.slice(2); if (!pwOptions.includes("--config")) { pwOptions.push(`--config`); pwOptions.push(defaultConfigFile); } try { await runPlaywrightCmd(pwOptions.join(" ")); } catch (error) { logger_1.logger.error(`Error while running playwright test: ${error}`); process.exit(1); } })();