-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Add snapshot version support #2896
Changes from 1 commit
02e65fb
77d282e
b6339c0
1cd8bee
3c04d8b
280d442
6c327a6
263fd38
165e0a6
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// Jest Snapshot v1 | ||
|
||
exports[`renders correctly 1`] = ` | ||
<View | ||
style={ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// Jest Snapshot v1 | ||
|
||
exports[`renders correctly 1`] = ` | ||
<p> | ||
1482363367.071 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// Jest Snapshot v1 | ||
|
||
exports[`changes the class when hovered 1`] = ` | ||
<a | ||
className="normal" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// Jest Snapshot v1 | ||
|
||
exports[`console printing 1`] = ` | ||
" PASS __tests__/console-test.js | ||
● Console | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// Jest Snapshot v1 | ||
|
||
exports[`basic test constructs 1`] = ` | ||
" PASS __tests__/basic-test-constructs-test.js | ||
✓ it | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,7 @@ describe('multiple-transformers', () => { | |
}); | ||
|
||
it('transforms dependencies using specific transformers', () => { | ||
const {json, stderr} = runJest.json(dir, ['--no-cache']); | ||
const {json, stderr} = runJest.json(dir, ['--no-cache', '-u']); | ||
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. Had to add that, so the snapshot version is updated, otherwise it fails. 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. hm. can't you update snapshot in the underlying test directory? 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. Oh I know what happened, I've updated it manually before this change #2896 (comment), so it wasn't updated. You're totally right and fix is already applied, thanks! |
||
|
||
expect(stderr).toMatch(/PASS/); | ||
expect(json.numTotalTests).toBe(1); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// Jest Snapshot v1 | ||
|
||
exports[`Watch mode flows Pressing "P" enters pattern mode 1`] = ` | ||
" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// Jest Snapshot v1 | ||
|
||
exports[`Watch mode flows Runs Jest once by default and shows usage 1`] = ` | ||
Array [ | ||
" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// Jest Snapshot v1 | ||
|
||
exports[`trimAndFormatPath() does not trim anything 1`] = `"[2m1234567890/1234567890/[22m[1m1234.js[22m"`; | ||
|
||
exports[`trimAndFormatPath() split at the path.sep index 1`] = `"[2m.../[22m[1m1234.js[22m"`; | ||
|
@@ -8,9 +10,9 @@ exports[`trimAndFormatPath() trims dirname 1`] = `"[2m...234567890/[22m[1m123 | |
|
||
exports[`trimAndFormatPath() trims dirname and basename 1`] = `"[1m...1234.js[22m"`; | ||
|
||
exports[`wrapAnsiString() returns the string unaltered if given a terminal width of zero 1`] = `"This string shouldn\'t cause you any trouble"`; | ||
exports[`wrapAnsiString() returns the string unaltered if given a terminal width of zero 1`] = `"This string shouldn't cause you any trouble"`; | ||
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. Shouldn't this be fixed? 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. omg yes. Not sure what is going on here? 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. Can you remove this snapshot and run the test again and use the result of that? 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. Wait, actually this is correct now. I don't understand why it wasn't updated before. cc @vjeux. 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. Maybe because before it was checking the unserialized state so they were both the same and therefore didn't needed an update? idk |
||
|
||
exports[`wrapAnsiString() returns the string unaltered if given a terminal width of zero 2`] = `"This string shouldn\'t cause you any trouble"`; | ||
exports[`wrapAnsiString() returns the string unaltered if given a terminal width of zero 2`] = `"This string shouldn't cause you any trouble"`; | ||
|
||
exports[`wrapAnsiString() wraps a long string containing ansi chars 1`] = ` | ||
"abcde [31m[1mred- | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// Jest Snapshot v1 | ||
|
||
exports[`collapses big diffs to patch format 1`] = ` | ||
"[32m- Expected[39m | ||
[31m+ Received[39m | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// Jest Snapshot v1 | ||
|
||
exports[`is available globally 1`] = `"expected 15 to be divisible by 2"`; | ||
|
||
exports[`is ok if there is no message specified 1`] = `"[31mNo message was specified for this matcher.[39m"`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ class SnapshotState { | |
) { | ||
this._dirty = false; | ||
this._snapshotPath = snapshotPath || getSnapshotPath(testPath); | ||
this._snapshotData = getSnapshotData(this._snapshotPath); | ||
this._snapshotData = getSnapshotData(this._snapshotPath, update); | ||
this._uncheckedKeys = new Set(Object.keys(this._snapshotData)); | ||
this._counters = new Map(); | ||
this._index = 0; | ||
|
@@ -83,7 +83,7 @@ class SnapshotState { | |
|
||
const isEmpty = Object.keys(this._snapshotData).length === 0; | ||
|
||
if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) { | ||
if ((this._dirty || this._uncheckedKeys.size || update) && !isEmpty) { | ||
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. This is added because otherwise 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. Can we make this so we only write the file if update is given & the snapshot header is either missing or there is a mismatch? I wanna prevent writes from happening if we don't need them. 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. Updated. I'm making snapshot "dirty" if it is in update mode and would throw invalid version error. I'm not very happy with returning a tuple from |
||
saveSnapshotFile(this._snapshotData, this._snapshotPath); | ||
status.saved = true; | ||
} else if (isEmpty && fileExists(this._snapshotPath)) { | ||
|
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.
Let's do:
// Jest Snapshot v1, https://goo.gl/fbAQLP
which links to our snapshot testing guide.
cc @kentcdodds who will be pleased.
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.
Added the link