Skip to content

Commit

Permalink
Merge pull request #335 from qawolf/path
Browse files Browse the repository at this point in the history
feat(cli): Add path option
  • Loading branch information
jperl committed Jan 19, 2020
2 parents 248bd75 + ae6c1ad commit c11bb66
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 14 deletions.
17 changes: 11 additions & 6 deletions docs/docs/cli.md
Expand Up @@ -22,6 +22,7 @@ See all commands and options.
### npx qawolf create <url\> \[name]

- `--device <device>` (optional): Emulate a [device](https://github.com/puppeteer/puppeteer/blob/5e63254e62fb9aedfd4503c632228c3334c70293/lib/DeviceDescriptors.js).
- `--path <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.
Expand All @@ -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 <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
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/run_a_test_locally.md
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion docs/src/components/GetStarted.js
Expand Up @@ -50,7 +50,9 @@ function GetStarted() {
<h3>3. Run your test</h3>
<p className={styles.stepDirection}>
Use the{" "}
<Link href={useBaseUrl("docs/cli#npx-qawolf-test-name")}>CLI</Link>{" "}
<Link href={useBaseUrl("docs/cli#npx-qawolf-test-options")}>
CLI
</Link>{" "}
to run your tests locally:
</p>
<CodeBlock value="npx qawolf test" />
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/create.ts
Expand Up @@ -10,6 +10,7 @@ type RecordOptions = {
debug?: boolean;
device?: string;
name: string;
path?: string;
test?: boolean;
url: Url;
};
Expand All @@ -27,7 +28,7 @@ export const create = async (options: RecordOptions): Promise<void> => {
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`;
Expand Down
13 changes: 10 additions & 3 deletions packages/cli/src/index.ts
Expand Up @@ -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();
Expand All @@ -22,6 +22,7 @@ program
.alias("record")
.option("--debug", "save events and workflow json for debugging")
.option("-d, --device <device>", "emulate using a puppeteer.device")
.option("-p, --path <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) => {
Expand All @@ -40,17 +41,23 @@ program
debug: cmd.debug,
device: cmd.device,
name,
path: cmd.path,
test: !cmd.script,
url
});
});

program
.command("test")
.option("-p, --path <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);
});

Expand Down
10 changes: 8 additions & 2 deletions 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) {
Expand Down
4 changes: 4 additions & 0 deletions 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);

Expand Down

0 comments on commit c11bb66

Please sign in to comment.