Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Fix test log debugging #236

Merged
merged 2 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ module.exports = config => config.set({
'test/**/*.test.js': ['rollupTestFiles']
},

// reports look better when not randomized
client: {
env: {
// used in the test helper to add failed test debug logs
DUMP_FAILED_TEST_LOGS: process.env.DUMP_FAILED_TEST_LOGS
},
// reports look better when not randomized
jasmine: {
random: false
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build:watch": "lerna run build --stream -- --watch",
"bump-version": "lerna version --no-git-tag-version --no-push",
"chromium-revision": "./scripts/chromium-revision",
"clean": "rm -rf packages/**/{dist,.nyc_output,coverage,oclif.manifest.json}",
"clean": "rm -rf packages/**/{dist,.nyc_output,coverage,oclif.manifest.json,.local-chromium}",
"lint": "eslint --ignore-path .gitignore .",
"readme": "lerna run --parallel readme",
"postinstall": "lerna run --stream postinstall",
Expand Down
8 changes: 1 addition & 7 deletions packages/core/test/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ beforeEach(() => {
mockAPI.start();
});

afterEach(function(done) {
// dump logs for failed tests when debugging
if (process.env.DEBUG_FAILING &&
this.currentTest.state === 'failed') {
logger.dump();
}

afterEach(done => {
// cleanup tmp files
rimraf(path.join(os.tmpdir(), 'percy'), () => done());
});
Expand Down
18 changes: 18 additions & 0 deletions scripts/test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,21 @@ beforeAll(() => {
})
});
});

// dump logs for failed tests when debugging
let DUMP_FAILED_TEST_LOGS = false;

// get the value from the env or from karma
try { ({ DUMP_FAILED_TEST_LOGS } = process.env); } catch (e) {}
try { ({ DUMP_FAILED_TEST_LOGS } = window.__karma__.config.env); } catch (e) {}

if (DUMP_FAILED_TEST_LOGS) {
// add a spec reporter to dump failed logs
jasmine.getEnv().addReporter({
specDone: ({ status }) => {
if (status === 'failed') {
require('@percy/logger/test/helper').dump();
}
}
});
}