Skip to content

Commit

Permalink
feat: add option to enable wdio watch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Roozenboom committed Apr 14, 2023
1 parent 6a853b2 commit 03789b7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/webdriverio/src/executors/e2e/lib/run-wdio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ import { unlink } from 'node:fs/promises';
import type { NormalizedSchema } from '../schema';

export async function runWdio(options: NormalizedSchema) {
const { projectRoot, configFile, spec, suite } = options;
const { projectRoot, configFile, spec, suite, watch } = options;

let command = `${getPackageManagerCommand().exec} wdio ${configFile}`;
if (spec) command += ` --spec=${spec}`;
if (suite) command += ` --suite=${suite}`;
if (watch) command += ` --watch`;

await new Promise((resolve, reject) => {
exec(command, { cwd: projectRoot }, (error, stdout, stderr) => {
error ? reject(error) : resolve({ stdout, stderr });
}).stdout.pipe(process.stdout);

if (watch) {
process.on('SIGINT', () => resolve({}));
process.on('SIGTERM', () => resolve({}));
}
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/webdriverio/src/executors/e2e/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface Schema extends WdioOptions {
wdioConfig?: string;
devServerTarget?: string;
skipServe?: boolean;
watch?: boolean;
}

export interface NormalizedSchema extends Schema {
Expand Down
9 changes: 9 additions & 0 deletions packages/webdriverio/src/executors/e2e/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@
"type": "boolean",
"description": "Skip dev server target execution.",
"default": false
},
"watch": {
"type": "boolean",
"description": "Watch for file changes and automatically rerun tests",
"default": false
},
"filesToWatch": {
"type": "array",
"description": "Add files to watch (e.g. application code or page objects) when running `wdio` command with `--watch` flag. Globbing is supported."
}
},
"required": []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# @rbnx/webdriverio - auto-generated configuration file
wdio.generated.config.ts
1 change: 1 addition & 0 deletions packages/webdriverio/src/wdio/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface WdioOptions {
specFileRetries?: number;
specFileRetriesDelay?: number;
specFileRetriesDeferred?: boolean;
filesToWatch?: string;
}

type wdioOptsKeys = keyof WdioOptions;
Expand Down

0 comments on commit 03789b7

Please sign in to comment.