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 retries that contain snapshots #8019
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import fs from 'fs'; | ||
|
||
import {EventHandler, TEST_TIMEOUT_SYMBOL} from './types'; | ||
|
||
import { | ||
|
@@ -147,7 +149,29 @@ const eventHandler: EventHandler = (event, state): void => { | |
break; | ||
} | ||
case 'test_retry': { | ||
// Clear errors so tests can be retried (and not immediately fail) | ||
event.test.errors = []; | ||
|
||
// Clear any snapshot data that occurred in previous test run | ||
const tmpSnapshotState = global.expect.getState().snapshotState; | ||
|
||
if (tmpSnapshotState) { | ||
if ( | ||
tmpSnapshotState._snapshotPath && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey! Please feel free to work on it :) It's all of our code not my code. Ultimately the issue this PR tries to fix is the fact that a snapshot file for a test will contain n-copies depending on how many times it's rerun. So this was one way we could fix that by removing the snapshot file before new data is written. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome! I'll keep working on it and update the PR once I have something 😄 |
||
fs.existsSync(tmpSnapshotState._snapshotPath) | ||
) { | ||
fs.unlinkSync(tmpSnapshotState._snapshotPath); | ||
} | ||
global.expect.getState().snapshotState._snapshotData = {}; | ||
global.expect.getState().snapshotState._inlineSnapshots = []; | ||
global.expect.getState().snapshotState._counters = new Map([]); | ||
global.expect.getState().snapshotState._index = 0; | ||
global.expect.getState().snapshotState.added = 0; | ||
global.expect.getState().snapshotState.matched = 0; | ||
global.expect.getState().snapshotState.unmatched = 0; | ||
global.expect.getState().snapshotState.updated = 0; | ||
} | ||
|
||
break; | ||
} | ||
case 'run_start': { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make sense for
global.expect
to exposeclearState
, call it here and let it do the job of cleaning upThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree. I should have some time this week to look at this some more.