-
Notifications
You must be signed in to change notification settings - Fork 632
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
feat(testing): Implement "assertSnapshot" #2039
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
73467da
wip: Implement assertSnapshot
hyp3rflow 4d8bf6c
wip: Get full ident from recursive getName function
hyp3rflow 4833857
format
hyp3rflow 31abdb8
Apply bcheidemann's review
hyp3rflow 418cc43
proposal: Use `Deno.args` for update and `globalThis.onunload` instea…
hyp3rflow 58df39e
Add count
hyp3rflow f191dd3
jest snapshot style
hyp3rflow 9acd82c
add test case
hyp3rflow ea2479f
refactor: apply review comments 1
bcheidemann 2b717b6
refactor: remove duplicate format calls
bcheidemann 46b0b9a
feat: show number of snapshots updated
bcheidemann a199814
fix: only call writeSnapshotFileSync once per test
bcheidemann d36765c
refactor: format files
bcheidemann 9df0184
fix: output snapshots to __snapshots__ directory
bcheidemann 2538887
fix: handle missing snapshot file
bcheidemann c710140
refactor: group variables into assert snapshot context
bcheidemann c53bb73
refactor: use maps
bcheidemann 140bd96
refactor: tidyup
bcheidemann b6d55e3
docs: add documentation for assertSnapshot
bcheidemann d024982
refactor: move code to be adjacent to other asserts
bcheidemann da8e582
fix: single line snapshots captured correctly
bcheidemann 03b250e
fix: escape characters correctly
bcheidemann f4b4174
fix: type fix for assertSnapshot example
bcheidemann 063261b
Merge branch 'main' of github.com:denoland/deno_std into feat/assertS…
bcheidemann a4bf357
Merge branch 'feat/assertSnapshot' of github.com:hyp3rflow/deno_std i…
bcheidemann 6ca3bd1
refactor: format files
bcheidemann 5ec8e41
fix: snapshot path to match Jest
bcheidemann 2f0cc55
fix: improve assertSnapshot output
bcheidemann 9e4390c
docs: add better documentation for assertSnapshot
bcheidemann fe87cfa
Merge branch 'main' of github.com:denoland/deno_std into feat/assertS…
bcheidemann b1782f8
docs: add link to Snapshot Testing section
bcheidemann 21b96d0
test: add test data to map
bcheidemann 7ad5a8b
refactor: move assertSnapshot to snapshot.ts
bcheidemann 666f32d
fix: snapshot import on windows
bcheidemann 3902ec7
docs: use "t" instead of "test" for assertSnapshot example
bcheidemann e13af8a
docs: use "t" instead of "test" for assertSnapshot example
bcheidemann 158b8d5
docs: fix typescript issues in docs
bcheidemann c3264dd
fix: write snapshot file to correct path
bcheidemann e1155a0
fix: add training new line to snapshot files
bcheidemann fddf34d
refactor: use addEventListener for snapshot teardown
bcheidemann 24f1868
test: add tests for assertSnapshot update flag
bcheidemann 9c34b02
refactor: fromat files
bcheidemann 03d2a4c
docs: fix snapshot test examples
bcheidemann 0a66471
docs: fix assertSnapshot example and
bcheidemann 4542ea9
test(node): update global var leak detection
kt3k faeb691
fix: fix snapshot assertions in --update testing
kt3k 26aba27
fix: mask more timing notations
kt3k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ let knownGlobals = [ | |
getParent, | ||
window, | ||
self, | ||
reportError, | ||
]; | ||
|
||
if (global.AbortController) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
export const snapshot = {}; | ||
|
||
snapshot[`Snapshot Test 1`] = ` | ||
{ | ||
a: 1, | ||
b: 2, | ||
} | ||
`; | ||
|
||
snapshot[`Snapshot Test 2`] = ` | ||
TestClass { | ||
a: 1, | ||
b: 2, | ||
} | ||
`; | ||
|
||
snapshot[`Snapshot Test 3`] = ` | ||
Map { | ||
"Hello" => "World!", | ||
1 => 2, | ||
[Function] => "World!", | ||
} | ||
`; | ||
|
||
snapshot[`Snapshot Test 4`] = ` | ||
Set { | ||
1, | ||
2, | ||
3, | ||
} | ||
`; | ||
|
||
snapshot[`Snapshot Test 5`] = ` | ||
{ | ||
fn: [Function: fn], | ||
} | ||
`; | ||
|
||
snapshot[`Snapshot Test 6`] = `[Function: fn]`; | ||
|
||
snapshot[`Snapshot Test 7`] = ` | ||
[ | ||
1, | ||
2, | ||
3, | ||
] | ||
`; | ||
|
||
snapshot[`Snapshot Test 8`] = `"hello world"`; | ||
|
||
snapshot[`Snapshot Test - step 1`] = ` | ||
{ | ||
a: 1, | ||
b: 2, | ||
} | ||
`; | ||
|
||
snapshot[`Snapshot Test - step > Nested 1`] = ` | ||
TestClass { | ||
a: 1, | ||
b: 2, | ||
} | ||
`; | ||
|
||
snapshot[`Snapshot Test - step > Nested 2`] = ` | ||
Map { | ||
"Hello" => "World!", | ||
1 => 2, | ||
[Function] => "World!", | ||
} | ||
`; | ||
|
||
snapshot[`Snapshot Test - step > Nested > Nested Nested 1`] = ` | ||
Set { | ||
1, | ||
2, | ||
3, | ||
} | ||
`; | ||
|
||
snapshot[`Snapshot Test - step > Nested > Nested Nested 2`] = ` | ||
{ | ||
fn: [Function: fn], | ||
} | ||
`; | ||
|
||
snapshot[`Snapshot Test - step > Nested > Nested Nested 3`] = `[Function: fn]`; | ||
|
||
snapshot[`Snapshot Test - step > Nested 3`] = ` | ||
[ | ||
1, | ||
2, | ||
3, | ||
] | ||
`; | ||
|
||
snapshot[`Snapshot Test - step 2`] = `"hello world"`; | ||
|
||
snapshot[`Snapshot Test - Adverse String \\ \` \${} 1`] = `"\\\\ \` \${}"`; | ||
|
||
snapshot[`Snapshot Test - Failed Assertion > Object 1`] = ` | ||
[ | ||
1, | ||
2, | ||
3, | ||
] | ||
`; | ||
|
||
snapshot[`Snapshot Test - Failed Assertion > Object 2`] = ` | ||
[ | ||
"Snapshot does not match:", | ||
"", | ||
"", | ||
" [Diff] Actual / Expected", | ||
"", | ||
"", | ||
" [", | ||
" 1,", | ||
" 2,", | ||
"+ 3,", | ||
" ]", | ||
"", | ||
] | ||
`; | ||
|
||
snapshot[`Snapshot Test - Failed Assertion > String 1`] = `"Hello World!"`; | ||
|
||
snapshot[`Snapshot Test - Failed Assertion > String 2`] = ` | ||
[ | ||
"Snapshot does not match:", | ||
"", | ||
"", | ||
" [Diff] Actual / Expected", | ||
"", | ||
"", | ||
'- "Hello!"', | ||
'+ "Hello World!"', | ||
"", | ||
"", | ||
] | ||
`; | ||
|
||
snapshot[`Snapshot Test - Update 1`] = ` | ||
[ | ||
"running 1 test from ./testing/.tmp/test.ts", | ||
"Snapshot Test - Update ... ok (--ms)", | ||
"", | ||
" > 1 snapshots updated.", | ||
"", | ||
"test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (--ms)", | ||
"", | ||
"", | ||
] | ||
`; | ||
|
||
snapshot[`Snapshot Test - Update 2`] = ` | ||
[ | ||
"running 1 test from ./testing/.tmp/test.ts", | ||
"Snapshot Test - Update ... ok (--ms)", | ||
"", | ||
"test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (--ms)", | ||
"", | ||
"", | ||
] | ||
`; | ||
|
||
snapshot[`Snapshot Test - Update 3`] = ` | ||
[ | ||
"running 1 test from ./testing/.tmp/test.ts", | ||
"Snapshot Test - Update ... ok (--ms)", | ||
"", | ||
" > 1 snapshots updated.", | ||
"", | ||
"test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (--ms)", | ||
"", | ||
"", | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Great docs, could you also open a PR to https://github.com/denoland/manual that adds "Snapshot testing" page to "Testing" chapter?
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.
Done 🙂 denoland/manual#294