Skip to content

Commit

Permalink
Merge pull request #503 from qawolf/default-to-headed
Browse files Browse the repository at this point in the history
Improve cli
  • Loading branch information
jperl committed Mar 10, 2020
2 parents 11df539 + 8ec0dd5 commit f75f889
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ program.usage('<command> [options]').version(pkg.version);
addCiCommands({ program, qawolf: true });

program
.command('create <url> [name]')
.command('create [url] [name]')
.option('-d, --device <device>', 'emulate using a playwright.device')
.option('--name [name]', 'name', '')
.option(
'-r, --rootDir <rootDir>',
'directory where test or script will be saved',
Expand All @@ -29,11 +30,13 @@ program
'--statePath <statePath>',
'path where state data (cookies, localStorage, sessionStorage) is saved',
)
.option('--url [url]', 'url', 'http://example.org')
.description('create a test from browser actions')

.action(async (urlArgument, optionalName, cmd) => {
const url = parseUrl(urlArgument);
const name = optionalName || (url.hostname || '').replace(/\..*/g, '');
.action(async (urlArgument, nameArgument, cmd) => {
const url = parseUrl(cmd.url || urlArgument);
const name =
cmd.name || nameArgument || (url.hostname || '').replace(/\..*/g, '');

const codePath = await saveTemplate({
device: cmd.device,
Expand Down Expand Up @@ -80,6 +83,7 @@ program
.option('--all-browsers', 'run tests on chromium, firefox, and webkit')
.option('--chromium', 'run tests on chromium')
.option('--firefox', 'run tests on firefox')
.option('--headless', 'run tests headless')
.option('--repl', 'open a REPL when repl() is called')
.option('--webkit', 'run tests on webkit')
.description('run a test with Jest')
Expand All @@ -89,6 +93,7 @@ program
'--all-browsers',
'--chromium',
'--firefox',
'--headless',
'--repl',
'--webkit',
]);
Expand All @@ -110,6 +115,7 @@ program
try {
runJest(args, {
browsers,
headless: !!cmd.headless,
repl: !!cmd.repl,
rootDir: cmd.rootDir,
});
Expand Down
9 changes: 8 additions & 1 deletion src/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type RunJestOptions = {
browsers?: BrowserName[];
config?: string;
env?: NodeJS.ProcessEnv;
headless?: boolean;
repl?: boolean;
rootDir?: string;
};
Expand Down Expand Up @@ -32,7 +33,13 @@ export const runJest = (
/**
* Returns exit code. 0 for success, 1 for failed.
*/
let command = `npx jest`;
let command = '';

if (!options.headless) {
command += 'QAW_HEADLESS=false ';
}

command += `npx jest`;

if (!args.some(arg => arg.startsWith('--config'))) {
// prevent using the local jest config
Expand Down

0 comments on commit f75f889

Please sign in to comment.