From 674625c901885f3ed52e44d5e5894a6c6921dccc Mon Sep 17 00:00:00 2001 From: Hironori Akaishi Date: Sun, 19 Jan 2020 15:36:02 +0900 Subject: [PATCH 1/7] Add path option to create command --- packages/cli/src/create.ts | 3 ++- packages/cli/src/index.ts | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/create.ts b/packages/cli/src/create.ts index 85f7cf2c6..e4b06b272 100644 --- a/packages/cli/src/create.ts +++ b/packages/cli/src/create.ts @@ -10,6 +10,7 @@ type RecordOptions = { debug?: boolean; device?: string; name: string; + path?: string; test?: boolean; url: Url; }; @@ -27,7 +28,7 @@ export const create = async (options: RecordOptions): Promise => { url: options.url.href }); - const qawolfPath = `${process.cwd()}/.qawolf`; + const qawolfPath = options.path || `${process.cwd()}/.qawolf`; const saveJson = (type: string, data: any) => { const path = `${qawolfPath}/${type}/${name}.json`; diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index b0f2816d5..8d7df134f 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -22,6 +22,7 @@ program .alias("record") .option("--debug", "save events and workflow json for debugging") .option("-d, --device ", "emulate using a puppeteer.device") + .option("-p, --path ", "path to save the file") .option("-s, --script", "create a script instead of a test") .description("create a test from browser actions") .action(async (urlArgument, optionalName, cmd) => { @@ -40,6 +41,7 @@ program debug: cmd.debug, device: cmd.device, name, + path: cmd.path, test: !cmd.script, url }); From 58d14ad718abd5dbe89017f59ba872b36ba039fe Mon Sep 17 00:00:00 2001 From: Hironori Akaishi Date: Sun, 19 Jan 2020 18:59:40 +0900 Subject: [PATCH 2/7] Add path option to test command --- packages/cli/src/index.ts | 12 +++++++++--- packages/cli/src/runJest.ts | 10 ++++++++-- packages/cli/src/utils.ts | 6 ++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 8d7df134f..78c9ef367 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -9,7 +9,7 @@ import { saveCiTemplate } from "./ci"; import { create } from "./create"; import { howl } from "./howl"; import { runJest } from "./runJest"; -import { parseUrl } from "./utils"; +import { parseUrl, getUnknownOptions } from "./utils"; const pkg = require("../package"); updateNotifier({ pkg }).notify(); @@ -49,10 +49,16 @@ program program .command("test") + .option("-p, --path ", "path to test code") .description("run a test with Jest") .allowUnknownOption(true) - .action(() => { - const code = runJest(process.argv.slice(3)); + .action(cmd => { + const options = ["-p", "--path"]; + const unknownOption = getUnknownOptions(process.argv.slice(3), options); + + const code = runJest(unknownOption, { + path: cmd.path + }); process.exit(code); }); diff --git a/packages/cli/src/runJest.ts b/packages/cli/src/runJest.ts index c470a1a09..c677505b0 100644 --- a/packages/cli/src/runJest.ts +++ b/packages/cli/src/runJest.ts @@ -1,13 +1,19 @@ import { execSync } from "child_process"; -export const runJest = (args: string[] = []) => { +type RunJestOptions = { + path?: string; +}; + +export const runJest = (args: string[] = [], options: RunJestOptions) => { /** * Returns exit code. 0 for success, 1 for failed. */ + const rootDir = options.path || ".qawolf"; + // jest-fail-fast preset overrides the transform, and configures the jasmine-fail-fast plugin // --config={} prevents using the local jest config - let command = `npx jest --preset="@qawolf/jest-fail-fast" --rootDir=.qawolf --testTimeout=60000 --config={}`; + let command = `npx jest --preset="@qawolf/jest-fail-fast" --rootDir=${rootDir} --testTimeout=60000 --config={}`; // pass through other arguments to jest if (args.length) { diff --git a/packages/cli/src/utils.ts b/packages/cli/src/utils.ts index ba596c8c2..7067285a6 100644 --- a/packages/cli/src/utils.ts +++ b/packages/cli/src/utils.ts @@ -14,3 +14,9 @@ export const parseUrl = (urlString: string) => { return url; }; + +export const getUnknownOptions = (args: string[], allowOptions: string[]) => { + return args.filter( + arg => !allowOptions.some(option => arg.startsWith(option)) + ); +}; From 8222ecd4c8ec3f9fd424bece00b049f034b75d63 Mon Sep 17 00:00:00 2001 From: Hironori Akaishi Date: Sun, 19 Jan 2020 19:16:38 +0900 Subject: [PATCH 3/7] Change docs --- docs/docs/cli.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/docs/cli.md b/docs/docs/cli.md index 31339a7b3..b6e5aa275 100644 --- a/docs/docs/cli.md +++ b/docs/docs/cli.md @@ -22,6 +22,7 @@ See all commands and options. ### npx qawolf create \[name] - `--device ` (optional): Emulate a [device](https://github.com/puppeteer/puppeteer/blob/5e63254e62fb9aedfd4503c632228c3334c70293/lib/DeviceDescriptors.js). +- `--path ` (optional): Specify the path to create the test. If path is not provided, path is `.qawolf`. - `--script` (optional): Create a node script instead of a [Jest](https://jestjs.io) test. - `url` (required): visit this URL to begin your test. - `name` (optional): Your file will be saved to `.qawolf/tests/name.test.js` or `.qawolf/scripts/name.js`. The name defaults to the URL hostname if not provided. `name` will be converted to camel case. @@ -37,6 +38,7 @@ npx qawolf create --script google.com ### npx qawolf test \[name] - `name` (optional) If `name` is not provided, QA Wolf will run all of your tests. If `name` is provided, QA Wolf will run that specific test. +- `--path ` (optional): Specify the path of the test file. If path is not provided, path is `.qawolf`. Run a specific test or all tests with Jest. This calls `npx jest` and all arguments are passed through to the [Jest CLI](https://jestjs.io/docs/en/cli). From 7eaab263dede012d8bee3ac192be63e3efde5ef6 Mon Sep 17 00:00:00 2001 From: Hironori Akaishi Date: Sun, 19 Jan 2020 21:42:15 +0900 Subject: [PATCH 4/7] fix runJest test --- packages/cli/tests/runJest.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/tests/runJest.test.ts b/packages/cli/tests/runJest.test.ts index db2d6e64b..1afa07502 100644 --- a/packages/cli/tests/runJest.test.ts +++ b/packages/cli/tests/runJest.test.ts @@ -1,11 +1,11 @@ import { runJest } from "../src/runJest"; it("runs successful test", async () => { - const exitCode = runJest(["success"]); + const exitCode = runJest(["success"], {}); expect(exitCode).toEqual(0); }); it("ignores error for failed test", async () => { - const exitCode = runJest(["failure"]); + const exitCode = runJest(["failure"], {}); expect(exitCode).toEqual(1); }); From d30ce28d3bb21a291ab92b908c092a12f2afd979 Mon Sep 17 00:00:00 2001 From: Jon Perl Date: Sun, 19 Jan 2020 07:49:17 -0700 Subject: [PATCH 5/7] docs: minor tweaks --- docs/docs/cli.md | 19 +++++++++++-------- docs/docs/run_a_test_locally.md | 2 +- docs/src/components/GetStarted.js | 4 +++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/docs/docs/cli.md b/docs/docs/cli.md index b6e5aa275..c5e7bcd5d 100644 --- a/docs/docs/cli.md +++ b/docs/docs/cli.md @@ -22,7 +22,7 @@ See all commands and options. ### npx qawolf create \[name] - `--device ` (optional): Emulate a [device](https://github.com/puppeteer/puppeteer/blob/5e63254e62fb9aedfd4503c632228c3334c70293/lib/DeviceDescriptors.js). -- `--path ` (optional): Specify the path to create the test. If path is not provided, path is `.qawolf`. +- `--path ` (optional): Specify the path to create the test. Defaults to `.qawolf`. - `--script` (optional): Create a node script instead of a [Jest](https://jestjs.io) test. - `url` (required): visit this URL to begin your test. - `name` (optional): Your file will be saved to `.qawolf/tests/name.test.js` or `.qawolf/scripts/name.js`. The name defaults to the URL hostname if not provided. `name` will be converted to camel case. @@ -35,19 +35,22 @@ npx qawolf create --device="iPhone 7" google.com npx qawolf create --script google.com ``` -### npx qawolf test \[name] +### npx qawolf test \[...options] -- `name` (optional) If `name` is not provided, QA Wolf will run all of your tests. If `name` is provided, QA Wolf will run that specific test. -- `--path ` (optional): Specify the path of the test file. If path is not provided, path is `.qawolf`. +- `--path ` (optional): Specify the [root directory](https://jestjs.io/docs/en/configuration#rootdir-string) that Jest should scan for tests. Defaults to `.qawolf`. +- `...options` (optional) Options for the [Jest CLI](https://jestjs.io/docs/en/cli). -Run a specific test or all tests with Jest. This calls `npx jest` and all arguments are passed through to the [Jest CLI](https://jestjs.io/docs/en/cli). +Run tests with Jest. ```bash -// use runInBand from the Jest CLI to run tests serially -npx qawolf test --runInBand +// run all tests +npx qawolf test -// run a specific test +// run one test npx qawolf test myTest + +// use runInBand from the Jest CLI to run tests serially +npx qawolf test --runInBand ``` ### npx qawolf azure diff --git a/docs/docs/run_a_test_locally.md b/docs/docs/run_a_test_locally.md index 954b14795..99fcc8151 100644 --- a/docs/docs/run_a_test_locally.md +++ b/docs/docs/run_a_test_locally.md @@ -7,7 +7,7 @@ In the [previous section](create_a_test) we created our first browser test for [ ## Run a test locally -Let's run our test to confirm it works locally. In the command line, run the following [command](cli#npx-qawolf-test-name). If applicable, replace `myFirstTest` with your test name. +Let's run our test to confirm it works locally. In the command line, run the following [command](cli#npx-qawolf-test-options). If applicable, replace `myFirstTest` with your test name. ```bash npx qawolf test myFirstTest diff --git a/docs/src/components/GetStarted.js b/docs/src/components/GetStarted.js index bcab54a79..ce4bb924d 100644 --- a/docs/src/components/GetStarted.js +++ b/docs/src/components/GetStarted.js @@ -50,7 +50,9 @@ function GetStarted() {

3. Run your test

Use the{" "} - CLI{" "} + + CLI + {" "} to run your tests locally:

From a953b75f9fe764cebe028407e2391983e4a37369 Mon Sep 17 00:00:00 2001 From: Jon Perl Date: Sun, 19 Jan 2020 07:55:05 -0700 Subject: [PATCH 6/7] rename getUnknownOptions -> omitArgs --- packages/cli/src/index.ts | 7 +++---- packages/cli/src/utils.ts | 10 ++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 78c9ef367..3c47265c4 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -9,7 +9,7 @@ import { saveCiTemplate } from "./ci"; import { create } from "./create"; import { howl } from "./howl"; import { runJest } from "./runJest"; -import { parseUrl, getUnknownOptions } from "./utils"; +import { omitArgs, parseUrl } from "./utils"; const pkg = require("../package"); updateNotifier({ pkg }).notify(); @@ -53,10 +53,9 @@ program .description("run a test with Jest") .allowUnknownOption(true) .action(cmd => { - const options = ["-p", "--path"]; - const unknownOption = getUnknownOptions(process.argv.slice(3), options); + const args = omitArgs(process.argv.slice(3), ["-p", "--path"]); - const code = runJest(unknownOption, { + const code = runJest(args, { path: cmd.path }); process.exit(code); diff --git a/packages/cli/src/utils.ts b/packages/cli/src/utils.ts index 7067285a6..5041607a4 100644 --- a/packages/cli/src/utils.ts +++ b/packages/cli/src/utils.ts @@ -1,5 +1,9 @@ import { parse } from "url"; +export const omitArgs = (args: string[], argsToOmit: string[]) => { + return args.filter(arg => !argsToOmit.some(skip => arg.startsWith(skip))); +}; + export const parseUrl = (urlString: string) => { let url = parse(urlString); @@ -14,9 +18,3 @@ export const parseUrl = (urlString: string) => { return url; }; - -export const getUnknownOptions = (args: string[], allowOptions: string[]) => { - return args.filter( - arg => !allowOptions.some(option => arg.startsWith(option)) - ); -}; From ae6c1adc8585882418c391e4b6aa99b469f4c0dc Mon Sep 17 00:00:00 2001 From: Jon Perl Date: Sun, 19 Jan 2020 07:59:12 -0700 Subject: [PATCH 7/7] Make runJest options optional --- packages/cli/src/runJest.ts | 2 +- packages/cli/tests/runJest.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/runJest.ts b/packages/cli/src/runJest.ts index c677505b0..c70537dd1 100644 --- a/packages/cli/src/runJest.ts +++ b/packages/cli/src/runJest.ts @@ -4,7 +4,7 @@ type RunJestOptions = { path?: string; }; -export const runJest = (args: string[] = [], options: RunJestOptions) => { +export const runJest = (args: string[] = [], options: RunJestOptions = {}) => { /** * Returns exit code. 0 for success, 1 for failed. */ diff --git a/packages/cli/tests/runJest.test.ts b/packages/cli/tests/runJest.test.ts index 1afa07502..db2d6e64b 100644 --- a/packages/cli/tests/runJest.test.ts +++ b/packages/cli/tests/runJest.test.ts @@ -1,11 +1,11 @@ import { runJest } from "../src/runJest"; it("runs successful test", async () => { - const exitCode = runJest(["success"], {}); + const exitCode = runJest(["success"]); expect(exitCode).toEqual(0); }); it("ignores error for failed test", async () => { - const exitCode = runJest(["failure"], {}); + const exitCode = runJest(["failure"]); expect(exitCode).toEqual(1); });