Skip to content

Commit

Permalink
feat(testrunner): take the first argument as the test root dir (#3423)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelEinbinder authored Aug 13, 2020
1 parent f2088e0 commit d367735
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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*"
Expand Down Expand Up @@ -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*"
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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*"
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down
11 changes: 7 additions & 4 deletions test/runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down Expand Up @@ -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'))
Expand All @@ -103,4 +105,5 @@ function collectFiles(dir, filters, files) {
}
}
}
return files;
}

0 comments on commit d367735

Please sign in to comment.