Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deterministic snapshot files, declaration-ordered snapshot reports
Ensures that *.snap files are deterministic by sorting entry blocks by the hash of their test name or id. Ensures that *.md snapshot report files are sorted in as close to declaration order as is reasonably possible. Closes #2311 Closes #2324 Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com> Co-authored-by: Mark Wubben <mark@novemberborn.net>
- Loading branch information
1 parent
73015e5
commit e66b54c
Showing
17 changed files
with
547 additions
and
14 deletions.
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
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
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 @@ | ||
{} |
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,35 @@ | ||
const test = require('ava'); | ||
|
||
const reverse = process.env.INTERTEST_ORDER_REVERSE; | ||
|
||
// Functions which resolve the corresponding promise to undefined | ||
let resolveOne; | ||
let resolveTwo; | ||
|
||
// Promises with triggerable resolution | ||
const one = new Promise(resolve => { | ||
resolveOne = resolve; | ||
}); | ||
|
||
const two = new Promise(resolve => { | ||
resolveTwo = resolve; | ||
}); | ||
|
||
// Test cases which await the triggerable promises | ||
test('one', async t => { | ||
await one; | ||
t.snapshot('one'); | ||
resolveTwo(); | ||
}); | ||
test('two', async t => { | ||
await two; | ||
t.snapshot('two'); | ||
resolveOne(); | ||
}); | ||
|
||
// Start resolution | ||
if (reverse) { | ||
resolveTwo(); | ||
} else { | ||
resolveOne(); | ||
} |
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 @@ | ||
{} |
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,67 @@ | ||
const test = require('ava'); | ||
|
||
const id = index => `index: ${index}`; | ||
const randomDelay = () => new Promise(resolve => { | ||
setTimeout(resolve, Math.random() * 1000); | ||
}); | ||
|
||
test.before(async t => { | ||
await randomDelay(); | ||
t.snapshot(id(-2), 'in a before hook'); | ||
}); | ||
|
||
test.beforeEach(async t => { | ||
await randomDelay(); | ||
t.snapshot(id(-1.5), 'in a beforeEach hook'); | ||
}); | ||
|
||
test.afterEach(async t => { | ||
await randomDelay(); | ||
t.snapshot(id(-1), 'in an afterEach hook'); | ||
}); | ||
|
||
test.afterEach.always(async t => { | ||
await randomDelay(); | ||
t.snapshot(id(-0.5), 'in an afterEachAlways hook'); | ||
}); | ||
|
||
test('B - declare some snapshots', async t => { | ||
await randomDelay(); | ||
t.snapshot(id(0)); | ||
t.snapshot(id(1), 'has a message'); | ||
t.snapshot(id(2), 'also has a message'); | ||
t.snapshot(id(3), {id: 'has an ID'}); | ||
}); | ||
|
||
test('A - declare some more snapshots', async t => { | ||
await randomDelay(); | ||
t.snapshot(id(4)); | ||
}); | ||
|
||
test('C - declare some snapshots in a try()', async t => { | ||
await randomDelay(); | ||
t.snapshot(id(5), 'outer'); | ||
(await t.try('trying', t => { | ||
t.snapshot(id(6), 'inner'); | ||
})).commit(); | ||
t.snapshot(id(7), 'outer again'); | ||
}); | ||
|
||
test('E - discard some snapshots in a try()', async t => { | ||
await randomDelay(); | ||
t.snapshot(id(8), 'outer'); | ||
(await t.try('trying', t => { | ||
t.snapshot(id(9), 'inner'); | ||
})).discard(); | ||
t.snapshot(id(10), 'outer again'); | ||
}); | ||
|
||
test('D - more snapshots with IDs', async t => { | ||
await randomDelay(); | ||
t.snapshot(id(11), {id: 'the first in test D'}); | ||
t.snapshot(id(12)); | ||
// These have to be reported in reverse declaration order, because they can't | ||
// be reported under the same header | ||
t.snapshot(id(14), {id: 'the second-to-last in test D'}); | ||
t.snapshot(id(13)); | ||
}); |
Oops, something went wrong.