Skip to content

Commit

Permalink
test: enable CircleCI's "re-run failed tests only" feature (#38178)
Browse files Browse the repository at this point in the history
* test: enable CircleCI rerun failed *tests* only

* .

* .

* console.log never fails 🤷

* normalize the filtered paths
circleci gives us a list of absolute paths here

* remove test output check
sometimes rerunning only failed tests results in some runners having
no tests to run, and thus no output

* keep relative paths the same

* error for when no tests match

* cleanup

* .
  • Loading branch information
clavin authored and pull[bot] committed Apr 15, 2024
1 parent e2184f1 commit 5492605
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
15 changes: 3 additions & 12 deletions .circleci/config/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ step-get-more-space-on-mac: &step-get-more-space-on-mac
fi
background: true

# On macOS delete all .git directories under src/ expect for
# On macOS delete all .git directories under src/ except for
# third_party/angle/ and third_party/dawn/ because of build time generation of files
# gen/angle/commit.h depends on third_party/angle/.git/HEAD
# https://chromium-review.googlesource.com/c/angle/angle/+/2074924
Expand Down Expand Up @@ -1492,7 +1492,7 @@ commands:
export LLVM_SYMBOLIZER_PATH=$PWD/third_party/llvm-build/Release+Asserts/bin/llvm-symbolizer
export MOCHA_TIMEOUT=180000
echo "Piping output to ASAN_SYMBOLIZE ($ASAN_SYMBOLIZE)"
(cd electron && node script/yarn test --runners=main --trace-uncaught --enable-logging --files $(circleci tests glob spec/*-spec.ts | circleci tests split --split-by=timings)) 2>&1 | $ASAN_SYMBOLIZE
(cd electron && (circleci tests glob "spec/*-spec.ts" | circleci tests run --command="xargs node script/yarn test --runners=main --trace-uncaught --enable-logging --files" --split-by=timings 2>&1)) | $ASAN_SYMBOLIZE
else
if [ "$TARGET_ARCH" == "arm" ] || [ "$TARGET_ARCH" == "arm64" ]; then
export ELECTRON_SKIP_NATIVE_MODULE_TESTS=true
Expand All @@ -1501,18 +1501,9 @@ commands:
if [ "$TARGET_ARCH" == "ia32" ]; then
npm_config_arch=x64 node electron/node_modules/dugite/script/download-git.js
fi
(cd electron && node script/yarn test --runners=main --trace-uncaught --enable-logging --files $(circleci tests glob spec/*-spec.ts | circleci tests split --split-by=timings))
(cd electron && (circleci tests glob "spec/*-spec.ts" | circleci tests run --command="xargs node script/yarn test --runners=main --trace-uncaught --enable-logging --files" --split-by=timings))
fi
fi
- run:
name: Check test results existence
command: |
cd src
# Check if test results exist and are not empty.
if [ ! -s "junit/test-results-main.xml" ]; then
exit 1
fi
- store_test_results:
path: src/junit

Expand Down
14 changes: 12 additions & 2 deletions spec/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ app.whenReady().then(async () => {
if (argv.grep) mocha.grep(argv.grep);
if (argv.invert) mocha.invert();

const baseElectronDir = path.resolve(__dirname, '..');
const validTestPaths = argv.files && argv.files.map(file =>
path.isAbsolute(file)
? path.relative(baseElectronDir, file)
: file);
const filter = (file) => {
if (!/-spec\.[tj]s$/.test(file)) {
return false;
Expand All @@ -121,8 +126,7 @@ app.whenReady().then(async () => {
return false;
}

const baseElectronDir = path.resolve(__dirname, '..');
if (argv.files && !argv.files.includes(path.relative(baseElectronDir, file))) {
if (validTestPaths && !validTestPaths.includes(path.relative(baseElectronDir, file))) {
return false;
}

Expand All @@ -135,6 +139,12 @@ app.whenReady().then(async () => {
mocha.addFile(file);
});

if (validTestPaths && validTestPaths.length > 0 && testFiles.length === 0) {
console.error('Test files were provided, but they did not match any searched files');
console.error('provided file paths (relative to electron/):', validTestPaths);
process.exit(1);
}

const cb = () => {
// Ensure the callback is called after runner is defined
process.nextTick(() => {
Expand Down

0 comments on commit 5492605

Please sign in to comment.