-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09bf88a
commit ee65b6d
Showing
8 changed files
with
251 additions
and
28 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,30 @@ | ||
'use strict'; | ||
var path = require('path'); | ||
var jestSnapshot = require('jest-snapshot'); | ||
var globals = require('./globals'); | ||
|
||
var x = module.exports; | ||
|
||
x.get = function (initializeState, globalsOptions) { | ||
if (!x.state) { | ||
// set defaults - this allows tests to mock deps easily | ||
var options = globalsOptions || globals.options; | ||
var initializeSnapshotState = initializeState || jestSnapshot.initializeSnapshotState; | ||
|
||
var filename = options.file; | ||
var dirname = path.dirname(filename); | ||
var snapshotFileName = path.basename(filename) + '.snap'; | ||
var snapshotsFolder = path.join(dirname, '__snapshots__', snapshotFileName); | ||
|
||
x.state = initializeSnapshotState( | ||
filename, | ||
options.updateSnapshots, | ||
snapshotsFolder, | ||
true | ||
); | ||
} | ||
|
||
return x.state; | ||
}; | ||
|
||
x.state = null; |
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,48 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var test = require('tap').test; | ||
var sinon = require('sinon'); | ||
var snapshotState = require('../lib/snapshot-state'); | ||
|
||
test('snapshot state gets created and returned', function (t) { | ||
var stateStub = sinon.stub().returns('state'); | ||
|
||
t.plan(3); | ||
|
||
t.doesNotThrow(function () { | ||
var result = snapshotState.get(stateStub, { | ||
file: path.join('hello', 'world.test.js'), | ||
updateSnapshots: false | ||
}); | ||
|
||
t.is(result, 'state'); | ||
}); | ||
|
||
t.ok(stateStub.calledWith( | ||
path.join('hello', 'world.test.js'), | ||
false, | ||
path.join('hello', '__snapshots__', 'world.test.js.snap'), | ||
true | ||
)); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('snapshot state is returned immediately if it already exists', function (t) { | ||
var stateSpy = sinon.spy(); | ||
|
||
t.plan(3); | ||
|
||
snapshotState.state = 'already made state'; | ||
|
||
t.doesNotThrow(function () { | ||
var result = snapshotState.get(stateSpy); | ||
|
||
t.is(result, 'already made state'); | ||
}); | ||
|
||
t.false(stateSpy.called); | ||
|
||
t.end(); | ||
}); |