@tryghost/jest-snapshot 0.5.17 → 0.5.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/SnapshotManager.js +23 -23
- package/package.json +8 -4
package/lib/SnapshotManager.js
CHANGED
|
@@ -7,26 +7,29 @@ const {makeMessageFromMatchMessage} = require('./utils');
|
|
|
7
7
|
|
|
8
8
|
const DOT_EXTENSION = `.${EXTENSION}`;
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Determines whether to update all snapshots or only new ones
|
|
12
|
+
* @returns {string} e.g. 'all' or 'new'
|
|
13
|
+
*/
|
|
14
|
+
function willUpdate() {
|
|
15
|
+
const updateSnapshots = (
|
|
16
|
+
process.env.SNAPSHOT_UPDATE
|
|
17
|
+
|| process.env.UPDATE_SNAPSHOT
|
|
18
|
+
|| process.env.SNAPSHOTS_UPDATE
|
|
19
|
+
|| process.env.UPDATE_SNAPSHOTS
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return updateSnapshots ? 'all' : 'new';
|
|
23
|
+
}
|
|
24
|
+
|
|
10
25
|
class SnapshotManager {
|
|
11
26
|
constructor() {
|
|
12
27
|
this.registry = {};
|
|
13
28
|
this.currentTest = {};
|
|
14
29
|
this.defaultSnapshotRoot = '__snapshots__';
|
|
15
|
-
}
|
|
16
30
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* @returns {string} e.g. 'all' or 'new'
|
|
20
|
-
*/
|
|
21
|
-
_willUpdate() {
|
|
22
|
-
const updateSnapshots = (
|
|
23
|
-
process.env.SNAPSHOT_UPDATE
|
|
24
|
-
|| process.env.UPDATE_SNAPSHOT
|
|
25
|
-
|| process.env.SNAPSHOTS_UPDATE
|
|
26
|
-
|| process.env.UPDATE_SNAPSHOTS
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
return updateSnapshots ? 'all' : 'new';
|
|
31
|
+
// Set willUpdate once, as it can't change whilst we are running
|
|
32
|
+
this.willUpdate = willUpdate();
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
/**
|
|
@@ -79,12 +82,9 @@ class SnapshotManager {
|
|
|
79
82
|
const {testPath, testTitle} = this.currentTest;
|
|
80
83
|
|
|
81
84
|
const snapshotName = this._getNameForSnapshot(testPath, testTitle);
|
|
82
|
-
const willUpdate = this._willUpdate();
|
|
83
|
-
|
|
84
|
-
// Set full path
|
|
85
85
|
const snapshotPath = this._resolveSnapshotFilePath(testPath);
|
|
86
86
|
|
|
87
|
-
return {snapshotPath, snapshotName
|
|
87
|
+
return {snapshotPath, snapshotName};
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/**
|
|
@@ -116,14 +116,13 @@ class SnapshotManager {
|
|
|
116
116
|
/**
|
|
117
117
|
* Gets a SnapshotState instance for the current test
|
|
118
118
|
* @param {string} snapshotPath e.g. 'test/__snapshots__/my-fake.test.js.snap'
|
|
119
|
-
* @param {string} willUpdate e.g. 'new'
|
|
120
119
|
* @returns {SnapshotState}
|
|
121
120
|
*/
|
|
122
|
-
getSnapshotState(snapshotPath
|
|
121
|
+
getSnapshotState(snapshotPath) {
|
|
123
122
|
// Initialize the SnapshotState, it’s responsible for actually matching
|
|
124
123
|
// actual snapshot with expected one and storing results
|
|
125
124
|
return new SnapshotState(snapshotPath, {
|
|
126
|
-
updateSnapshot: willUpdate
|
|
125
|
+
updateSnapshot: this.willUpdate
|
|
127
126
|
});
|
|
128
127
|
}
|
|
129
128
|
|
|
@@ -182,9 +181,10 @@ class SnapshotManager {
|
|
|
182
181
|
* @returns {Object} result of the match
|
|
183
182
|
*/
|
|
184
183
|
match(received, properties = {}, hint) {
|
|
185
|
-
const {snapshotPath, snapshotName
|
|
184
|
+
const {snapshotPath, snapshotName} = this._getConfig();
|
|
185
|
+
|
|
186
|
+
const snapshotState = this.getSnapshotState(snapshotPath);
|
|
186
187
|
|
|
187
|
-
const snapshotState = this.getSnapshotState(snapshotPath, willUpdate);
|
|
188
188
|
const matcher = toMatchSnapshot.bind({
|
|
189
189
|
snapshotState,
|
|
190
190
|
currentTestName: snapshotName,
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/jest-snapshot",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"repository":
|
|
3
|
+
"version": "0.5.18",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/TryGhost/framework.git",
|
|
7
|
+
"directory": "packages/jest-snapshot"
|
|
8
|
+
},
|
|
5
9
|
"author": "Ghost Foundation",
|
|
6
10
|
"license": "MIT",
|
|
7
11
|
"main": "index.js",
|
|
@@ -27,8 +31,8 @@
|
|
|
27
31
|
"dependencies": {
|
|
28
32
|
"@jest/expect": "^28.0.1",
|
|
29
33
|
"@jest/expect-utils": "^28.0.1",
|
|
30
|
-
"@tryghost/errors": "^1.3.
|
|
34
|
+
"@tryghost/errors": "^1.3.8",
|
|
31
35
|
"jest-snapshot": "^29.0.0"
|
|
32
36
|
},
|
|
33
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "e395f1d79edee4aecc36e572bb402016a8ba9273"
|
|
34
38
|
}
|