diff --git a/docs/docs/cli.md b/docs/docs/cli.md index 31339a7b3..c5e7bcd5d 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. 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. @@ -34,18 +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 [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:

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..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 } from "./utils"; +import { omitArgs, parseUrl } from "./utils"; const pkg = require("../package"); updateNotifier({ pkg }).notify(); @@ -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 }); @@ -47,10 +49,15 @@ 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 args = omitArgs(process.argv.slice(3), ["-p", "--path"]); + + const code = runJest(args, { + path: cmd.path + }); process.exit(code); }); diff --git a/packages/cli/src/runJest.ts b/packages/cli/src/runJest.ts index c470a1a09..c70537dd1 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..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);