-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Deterministic snaphot files, declaration-ordered snapshot reports #2610
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
Merged
Merged
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
47a0015
Test .snap is independent of test resolution order
ninevra 6d6e211
Sort snapshots before encoding them
ninevra bec3485
Move intertest-order fixture to subdirectory
ninevra 2b22330
Minor changes to intertest-order test
ninevra c2b7dff
Test that reports are sorted in declaration order
ninevra 93bf925
Test report order of snapshots in hooks
ninevra 342ec6b
Sort reports by approximate declaration order
ninevra 69f4d7f
Pass through snapshotCount as a fallback sort key
ninevra 52b4b29
Refactor to include ordering data in entries map
ninevra 4585a11
Polyfill matchAll()
ninevra cd29d35
Stabilize sort of *Each* hook snapshot reports
ninevra d6b25db
Test more *Each hooks
ninevra 72d78bb
Update package.json
sindresorhus 5b78ddf
Update package.json
ninevra 8fe455b
Expand abbreviations
ninevra f15a7a6
Prefer destructuring
ninevra 244cdfc
Fix capitalization
ninevra c7f63c4
Force not-ci in snapshot-order tests
ninevra 7dcb928
Test behavior with existing unsorted snapshots
ninevra 67bb529
Clean up transient snapshots after tests
ninevra dcd84dc
Use t.teardown() for cleanup
ninevra 5afacb4
Add a larger test case
ninevra 241b170
Organize tests into separate files
ninevra ce77f43
Merge branch 'master' of https://github.com/avajs/ava into determinis…
ninevra 9f05271
Prefer writing over copying when files are in memory
ninevra c2153e9
Add a snapshot message for clarity
ninevra 49ff55f
Remove unmaintainable backwards-compatibility tests
ninevra 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,119 @@ | ||
| const test = require('@ava/test'); | ||
| const exec = require('../helpers/exec'); | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const getSnapshotIds = require('./helpers/get-snapshot-ids'); | ||
|
|
||
| const unsortedSnapshotPath = path.join(__dirname, 'fixtures', 'backwards-compatibility', 'unsorted', 'test.js.snap'); | ||
| const unsortedReportPath = path.join(__dirname, 'fixtures', 'backwards-compatibility', 'unsorted', 'test.js.md'); | ||
|
|
||
| const unsortedSnapshot = fs.readFileSync(unsortedSnapshotPath); | ||
| const unsortedReport = fs.readFileSync(unsortedReportPath); | ||
|
|
||
| test('unsorted snapshots are unchanged when checking', async t => { | ||
| const options = { | ||
| cwd: exec.cwd('backwards-compatibility', 'check-only'), | ||
| env: { | ||
| AVA_FORCE_CI: 'not-ci' | ||
| } | ||
| }; | ||
|
|
||
| // Schedule snapshot cleanup | ||
| t.teardown(() => { | ||
| fs.unlinkSync(snapshotPath); | ||
| fs.unlinkSync(reportPath); | ||
| }); | ||
|
|
||
| const snapshotPath = path.join(options.cwd, 'test.js.snap'); | ||
| const reportPath = path.join(options.cwd, 'test.js.md'); | ||
|
|
||
| // Install a known-unsorted snapshot, report | ||
| fs.copyFileSync(unsortedSnapshotPath, snapshotPath); | ||
| fs.copyFileSync(unsortedReportPath, reportPath); | ||
|
|
||
| // Run test | ||
| await exec.fixture([], options); | ||
|
|
||
| // Assert snapshot, report are unchanged | ||
| const snapshot = fs.readFileSync(snapshotPath); | ||
| const report = fs.readFileSync(reportPath); | ||
|
|
||
| t.deepEqual(snapshot, unsortedSnapshot); | ||
| t.deepEqual(report, unsortedReport); | ||
| }); | ||
|
|
||
| test('unsorted snapshots are changed when appending', async t => { | ||
| const options = { | ||
| cwd: exec.cwd('backwards-compatibility', 'append-only'), | ||
| env: { | ||
| AVA_FORCE_CI: 'not-ci' | ||
| } | ||
| }; | ||
|
|
||
| const snapshotPath = path.join(options.cwd, 'test.js.snap'); | ||
| const reportPath = path.join(options.cwd, 'test.js.md'); | ||
|
|
||
| // Schedule snapshot cleanup | ||
| t.teardown(() => { | ||
| fs.unlinkSync(snapshotPath); | ||
| fs.unlinkSync(reportPath); | ||
| }); | ||
|
|
||
| // Install a known-unsorted snapshot, report | ||
| fs.copyFileSync(unsortedSnapshotPath, snapshotPath); | ||
| fs.copyFileSync(unsortedReportPath, reportPath); | ||
novemberborn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Run test | ||
| await exec.fixture([], options); | ||
|
|
||
| // Assert snapshot, report are changed | ||
| const snapshot = fs.readFileSync(snapshotPath); | ||
| const report = fs.readFileSync(reportPath); | ||
|
|
||
| t.notDeepEqual(snapshot, unsortedSnapshot); | ||
| t.notDeepEqual(report, unsortedReport); | ||
|
|
||
| // Assert entries appended to report are sorted | ||
| const textReport = report.toString(); | ||
| const ids = getSnapshotIds(textReport); | ||
|
|
||
| t.deepEqual(ids, [2, 1, 3, 4]); | ||
| }); | ||
|
|
||
| test('unsorted snapshots are changed when updating', async t => { | ||
| const options = { | ||
| cwd: exec.cwd('backwards-compatibility', 'updating'), | ||
| env: { | ||
| AVA_FORCE_CI: 'not-ci' | ||
| } | ||
| }; | ||
|
|
||
| // Schedule snapshot cleanup | ||
| t.teardown(() => { | ||
| fs.unlinkSync(snapshotPath); | ||
| fs.unlinkSync(reportPath); | ||
| }); | ||
|
|
||
| const snapshotPath = path.join(options.cwd, 'test.js.snap'); | ||
| const reportPath = path.join(options.cwd, 'test.js.md'); | ||
|
|
||
| // Install a known-unsorted snapshot, report | ||
| fs.copyFileSync(unsortedSnapshotPath, snapshotPath); | ||
| fs.copyFileSync(unsortedReportPath, reportPath); | ||
novemberborn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Run test | ||
| await exec.fixture(['--update-snapshots'], options); | ||
|
|
||
| // Assert snapshot, report are changed | ||
| const snapshot = fs.readFileSync(snapshotPath); | ||
| const report = fs.readFileSync(reportPath); | ||
|
|
||
| t.notDeepEqual(snapshot, unsortedSnapshot); | ||
| t.notDeepEqual(report, unsortedReport); | ||
|
|
||
| // Assert report is sorted | ||
| const textReport = report.toString(); | ||
| const ids = getSnapshotIds(textReport); | ||
|
|
||
| t.deepEqual(ids, [1, 2]); | ||
| }); | ||
1 change: 1 addition & 0 deletions
1
test/snapshot-order/fixtures/backwards-compatibility/append-only/package.json
This file contains hidden or 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 @@ | ||
| {} |
26 changes: 26 additions & 0 deletions
26
test/snapshot-order/fixtures/backwards-compatibility/append-only/test.js
This file contains hidden or 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,26 @@ | ||
| const test = require('ava'); | ||
|
|
||
| const id = index => `index: ${index}`; | ||
|
|
||
| let resolveDelay; | ||
| const delay = new Promise(resolve => { | ||
| resolveDelay = resolve; | ||
| }); | ||
|
|
||
| test('B - declared first, resolves second', async t => { | ||
| await delay; | ||
| t.snapshot(id(1)); | ||
| }); | ||
|
|
||
| test('A - declared second, resolves first', t => { | ||
| t.snapshot(id(2)); | ||
| resolveDelay(); | ||
| }); | ||
|
|
||
| test('D - a new test, declared third', t => { | ||
| t.snapshot(id(3)); | ||
| }); | ||
|
|
||
| test('C - another new test, declared fourth', t => { | ||
| t.snapshot(id(4)); | ||
| }); |
1 change: 1 addition & 0 deletions
1
test/snapshot-order/fixtures/backwards-compatibility/check-only/package.json
This file contains hidden or 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 @@ | ||
| {} |
18 changes: 18 additions & 0 deletions
18
test/snapshot-order/fixtures/backwards-compatibility/check-only/test.js
This file contains hidden or 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,18 @@ | ||
| const test = require('ava'); | ||
|
|
||
| const id = index => `index: ${index}`; | ||
|
|
||
| let resolveDelay; | ||
| const delay = new Promise(resolve => { | ||
| resolveDelay = resolve; | ||
| }); | ||
|
|
||
| test('B - declared first, resolves second', async t => { | ||
| await delay; | ||
| t.snapshot(id(1)); | ||
| }); | ||
|
|
||
| test('A - declared second, resolves first', t => { | ||
| t.snapshot(id(2)); | ||
| resolveDelay(); | ||
| }); |
17 changes: 17 additions & 0 deletions
17
test/snapshot-order/fixtures/backwards-compatibility/unsorted/test.js.md
This file contains hidden or 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,17 @@ | ||
| # Snapshot report for `test.js` | ||
|
|
||
| The actual snapshot is saved in `test.js.snap`. | ||
|
|
||
| Generated by [AVA](https://avajs.dev). | ||
|
|
||
| ## A - declared second, resolves first | ||
|
|
||
| > Snapshot 1 | ||
|
|
||
| 'index: 2' | ||
|
|
||
| ## B - declared first, resolves second | ||
|
|
||
| > Snapshot 1 | ||
|
|
||
| 'index: 1' |
Binary file added
BIN
+127 Bytes
test/snapshot-order/fixtures/backwards-compatibility/unsorted/test.js.snap
Binary file not shown.
1 change: 1 addition & 0 deletions
1
test/snapshot-order/fixtures/backwards-compatibility/updating/package.json
This file contains hidden or 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 @@ | ||
| {} |
18 changes: 18 additions & 0 deletions
18
test/snapshot-order/fixtures/backwards-compatibility/updating/test.js
This file contains hidden or 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,18 @@ | ||
| const test = require('ava'); | ||
|
|
||
| const id = index => `index: ${index}`; | ||
|
|
||
| let resolveDelay; | ||
| const delay = new Promise(resolve => { | ||
| resolveDelay = resolve; | ||
| }); | ||
|
|
||
| test('B - declared first, resolves second', async t => { | ||
| await delay; | ||
| t.snapshot(id(1)); | ||
| }); | ||
|
|
||
| test('A - declared second, resolves first', t => { | ||
| t.snapshot(id(2)); | ||
| resolveDelay(); | ||
| }); |
This file contains hidden or 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 @@ | ||
| {} |
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.
Uh oh!
There was an error while loading. Please reload this page.