@tryghost/jest-snapshot 0.5.17 → 0.5.19

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2013-2025 Ghost Foundation
3
+ Copyright (c) 2013-2026 Ghost Foundation
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -38,4 +38,4 @@ Follow the instructions for the top-level repo.
38
38
 
39
39
  # Copyright & License
40
40
 
41
- Copyright (c) 2013-2025 Ghost Foundation - Released under the [MIT license](LICENSE).
41
+ Copyright (c) 2013-2026 Ghost Foundation - Released under the [MIT license](LICENSE).
@@ -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
- * Determines whether to update all snapshots or only new ones
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, willUpdate};
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, willUpdate) {
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, willUpdate} = this._getConfig();
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.17",
4
- "repository": "https://github.com/TryGhost/framework/tree/main/packages/jest-snapshot",
3
+ "version": "0.5.19",
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",
@@ -20,15 +24,14 @@
20
24
  },
21
25
  "devDependencies": {
22
26
  "c8": "10.1.3",
23
- "mocha": "10.7.3",
27
+ "mocha": "11.7.5",
24
28
  "should": "13.2.3",
25
- "sinon": "18.0.0"
29
+ "sinon": "21.0.1"
26
30
  },
27
31
  "dependencies": {
28
32
  "@jest/expect": "^28.0.1",
29
33
  "@jest/expect-utils": "^28.0.1",
30
- "@tryghost/errors": "^1.3.7",
34
+ "@tryghost/errors": "^1.3.9",
31
35
  "jest-snapshot": "^29.0.0"
32
- },
33
- "gitHead": "b169bd1734b749c3abdaac134f030756b9a282bb"
36
+ }
34
37
  }