Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

feat(testrunner): take the first argument as the test root dir (#3423)

Joel Einbinderd3677357b85d
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index c55aac3858..39cc24c679 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -38,7 +38,7 @@ jobs:
# XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR
# Wrap `npm run` in a subshell to redirect STDERR to file.
# Enable core dumps in the subshell.
- - run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && node test/runner --jobs=1 --forbid-only --timeout=30000 && npm run coverage"
+ - run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && node test/runner test/ --jobs=1 --forbid-only --timeout=30000 && npm run coverage"
env:
BROWSER: ${{ matrix.browser }}
DEBUG: "pw:*,-pw:wrapped*,-pw:test*"
@@ -69,7 +69,7 @@ jobs:
- uses: microsoft/playwright-github-action@v1
- run: npm ci
- run: npm run build
- - run: node test/runner --jobs=1 --forbid-only --timeout=30000
+ - run: node test/runner test/ --jobs=1 --forbid-only --timeout=30000
env:
BROWSER: ${{ matrix.browser }}
DEBUG: "pw:*,-pw:wrapped*,-pw:test*"
@@ -103,7 +103,7 @@ jobs:
- uses: microsoft/playwright-github-action@v1
- run: npm ci
- run: npm run build
- - run: node test/runner --jobs=1 --forbid-only --timeout=30000
+ - run: node test/runner test/ --jobs=1 --forbid-only --timeout=30000
shell: bash
env:
BROWSER: ${{ matrix.browser }}
@@ -160,7 +160,7 @@ jobs:
# XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR
# Wrap `npm run` in a subshell to redirect STDERR to file.
# Enable core dumps in the subshell.
- - run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && node test/runner --jobs=1 --forbid-only --timeout=30000"
+ - run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && node test/runner test/ --jobs=1 --forbid-only --timeout=30000"
if: ${{ always() }}
env:
BROWSER: ${{ matrix.browser }}
@@ -194,7 +194,7 @@ jobs:
# XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR
# Wrap `npm run` in a subshell to redirect STDERR to file.
# Enable core dumps in the subshell.
- - run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && node test/runner --jobs=1 --forbid-only --timeout=30000"
+ - run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && node test/runner test/ --jobs=1 --forbid-only --timeout=30000"
env:
BROWSER: ${{ matrix.browser }}
DEBUG: "pw:*,-pw:wrapped*,-pw:test*"
diff --git a/package.json b/package.json
index 4135bdb4d2..76850f280a 100644
--- a/package.json
+++ b/package.json
@@ -9,9 +9,9 @@
"node": ">=10.15.0"
},
"scripts": {
- "ctest": "cross-env BROWSER=chromium node test/runner",
- "ftest": "cross-env BROWSER=firefox node test/runner",
- "wtest": "cross-env BROWSER=webkit node test/runner",
+ "ctest": "cross-env BROWSER=chromium node test/runner test/",
+ "ftest": "cross-env BROWSER=firefox node test/runner test/",
+ "wtest": "cross-env BROWSER=webkit node test/runner test/",
"test": "npm run ctest && npm run ftest && npm run wtest",
"eslint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe --ext js,ts ./src || eslint --ext js,ts ./src",
"tsc": "tsc -p .",
diff --git a/test/runner/index.js b/test/runner/index.js
index 716412191b..7d58e3da37 100644
--- a/test/runner/index.js
+++ b/test/runner/index.js
@@ -34,8 +34,7 @@ program
.option('--timeout <timeout>', 'Specify test timeout threshold (in milliseconds), default: 10000', 10000)
.action(async (command) => {
// Collect files
- const files = [];
- collectFiles(path.join(process.cwd(), 'test'), command.args, files);
+ const files = collectFiles(path.join(process.cwd(), command.args[0]), command.args.slice(1));
const rootSuite = new Mocha.Suite('', new Mocha.Context(), true);
console.log(`Parsing ${files.length} test files`);
@@ -84,10 +83,13 @@ program
program.parse(process.argv);
-function collectFiles(dir, filters, files) {
+function collectFiles(dir, filters) {
+ if (fs.statSync(dir).isFile())
+ return [dir];
+ const files = [];
for (const name of fs.readdirSync(dir)) {
if (fs.lstatSync(path.join(dir, name)).isDirectory()) {
- collectFiles(path.join(dir, name), filters, files);
+ files.push(...collectFiles(path.join(dir, name), filters));
continue;
}
if (!name.includes('spec'))
@@ -103,4 +105,5 @@ function collectFiles(dir, filters, files) {
}
}
}
+ return files;
}