@tryghost/jest-snapshot 2.0.3 → 2.2.0

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/README.md CHANGED
@@ -8,8 +8,7 @@ Tools for using jest snapshot without jest
8
8
 
9
9
  or
10
10
 
11
- `yarn add @tryghost/jest-snapshot`
12
-
11
+ `pnpm add @tryghost/jest-snapshot`
13
12
 
14
13
  ## Purpose
15
14
 
@@ -17,29 +16,24 @@ Snapshot assertion utilities and state management for Jest-style snapshots in no
17
16
 
18
17
  ## Usage
19
18
 
20
-
21
19
  ## Develop
22
20
 
23
- This is a mono repository, managed with [lerna](https://lernajs.io/).
21
+ This is a mono repository, managed with [Nx](https://nx.dev).
24
22
 
25
23
  Follow the instructions for the top-level repo.
26
- 1. `git clone` this repo & `cd` into it as usual
27
- 2. Run `yarn` to install top-level dependencies.
28
24
 
25
+ 1. `git clone` this repo & `cd` into it as usual
26
+ 2. Run `pnpm install` to install top-level dependencies.
29
27
 
30
28
  ## Run
31
29
 
32
- - `yarn dev`
33
-
30
+ - `pnpm dev`
34
31
 
35
32
  ## Test
36
33
 
37
- - `yarn lint` run just eslint
38
- - `yarn test` run lint and tests
39
-
40
-
41
-
34
+ - `pnpm lint` runs oxlint
35
+ - `pnpm test` runs lint and tests
42
36
 
43
- # Copyright & License
37
+ # Copyright & License
44
38
 
45
- Copyright (c) 2013-2026 Ghost Foundation - Released under the [MIT license](LICENSE).
39
+ Copyright (c) 2013-2026 Ghost Foundation - Released under the [MIT license](LICENSE).
@@ -1,9 +1,9 @@
1
- const {SnapshotState, toMatchSnapshot, EXTENSION} = require('jest-snapshot');
1
+ const { SnapshotState, toMatchSnapshot, EXTENSION } = require('jest-snapshot');
2
2
  const errors = require('@tryghost/errors');
3
3
  const utils = require('@jest/expect-utils');
4
4
  const assert = require('assert');
5
5
  const path = require('path');
6
- const {makeMessageFromMatchMessage} = require('./utils');
6
+ const { makeMessageFromMatchMessage } = require('./utils');
7
7
 
8
8
  const DOT_EXTENSION = `.${EXTENSION}`;
9
9
 
@@ -12,12 +12,11 @@ const DOT_EXTENSION = `.${EXTENSION}`;
12
12
  * @returns {string} e.g. 'all' or 'new'
13
13
  */
14
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
- );
15
+ const updateSnapshots =
16
+ process.env.SNAPSHOT_UPDATE ||
17
+ process.env.UPDATE_SNAPSHOT ||
18
+ process.env.SNAPSHOTS_UPDATE ||
19
+ process.env.UPDATE_SNAPSHOTS;
21
20
 
22
21
  return updateSnapshots ? 'all' : 'new';
23
22
  }
@@ -61,7 +60,7 @@ class SnapshotManager {
61
60
  _resolveSnapshotFilePath(testPath) {
62
61
  return path.join(
63
62
  path.join(path.dirname(testPath), this.defaultSnapshotRoot),
64
- path.basename(testPath) + DOT_EXTENSION
63
+ path.basename(testPath) + DOT_EXTENSION,
65
64
  );
66
65
  }
67
66
 
@@ -74,17 +73,18 @@ class SnapshotManager {
74
73
  if (!this.currentTest.testPath || !this.currentTest.testTitle) {
75
74
  throw new errors.IncorrectUsageError({
76
75
  message: 'Unable to run snapshot tests, current test was not configured',
77
- context: 'Snapshot testing requires current test filename and nameTemplate to be set for each test',
78
- help: 'Did you forget to do export.mochaHooks?'
76
+ context:
77
+ 'Snapshot testing requires current test filename and nameTemplate to be set for each test',
78
+ help: 'Did you forget to do export.mochaHooks?',
79
79
  });
80
80
  }
81
81
 
82
- const {testPath, testTitle} = this.currentTest;
82
+ const { testPath, testTitle } = this.currentTest;
83
83
 
84
84
  const snapshotName = this._getNameForSnapshot(testPath, testTitle);
85
85
  const snapshotPath = this._resolveSnapshotFilePath(testPath);
86
86
 
87
- return {snapshotPath, snapshotName};
87
+ return { snapshotPath, snapshotName };
88
88
  }
89
89
 
90
90
  /**
@@ -98,7 +98,7 @@ class SnapshotManager {
98
98
  * Resets the registry for the current test only
99
99
  */
100
100
  resetRegistryForCurrentTest() {
101
- const {testPath, testTitle} = this.currentTest;
101
+ const { testPath, testTitle } = this.currentTest;
102
102
  if (testPath in this.registry && testTitle in this.registry[testPath]) {
103
103
  delete this.registry[testPath][testTitle];
104
104
  }
@@ -122,7 +122,7 @@ class SnapshotManager {
122
122
  // Initialize the SnapshotState, it’s responsible for actually matching
123
123
  // actual snapshot with expected one and storing results
124
124
  return new SnapshotState(snapshotPath, {
125
- updateSnapshot: this.willUpdate
125
+ updateSnapshot: this.willUpdate,
126
126
  });
127
127
  }
128
128
 
@@ -134,7 +134,7 @@ class SnapshotManager {
134
134
  * @param {{properties: Object, field: string, error: Object, hint: string}} assertion
135
135
  */
136
136
  assertSnapshot(response, assertion) {
137
- const {properties, field, error} = assertion;
137
+ const { properties, field, error } = assertion;
138
138
 
139
139
  if (!response[field]) {
140
140
  error.message = `Unable to match snapshot on undefined field ${field} ${error.contextString}`;
@@ -181,7 +181,7 @@ class SnapshotManager {
181
181
  * @returns {Object} result of the match
182
182
  */
183
183
  match(received, properties = {}, hint) {
184
- const {snapshotPath, snapshotName} = this._getConfig();
184
+ const { snapshotPath, snapshotName } = this._getConfig();
185
185
 
186
186
  const snapshotState = this.getSnapshotState(snapshotPath);
187
187
 
@@ -189,7 +189,7 @@ class SnapshotManager {
189
189
  snapshotState,
190
190
  currentTestName: snapshotName,
191
191
  utils,
192
- equals: utils.equals
192
+ equals: utils.equals,
193
193
  });
194
194
 
195
195
  // Execute the matcher
@@ -1,9 +1,9 @@
1
- const {jestExpect} = require('@jest/expect');
1
+ const { jestExpect } = require('@jest/expect');
2
2
  const SnapshotManager = require('./SnapshotManager');
3
3
  const snapshotManager = new SnapshotManager();
4
4
 
5
5
  function matchSnapshotAssertion(properties) {
6
- this.params = {operator: 'to match a stored snapshot'};
6
+ this.params = { operator: 'to match a stored snapshot' };
7
7
 
8
8
  const result = snapshotManager.match(this.obj, properties);
9
9
 
@@ -12,7 +12,6 @@ function matchSnapshotAssertion(properties) {
12
12
  }
13
13
 
14
14
  const mochaHooks = {
15
-
16
15
  /**
17
16
  * Runs before all tests
18
17
  * Resets the registry so we start with a clean slate
@@ -27,7 +26,7 @@ const mochaHooks = {
27
26
  * If we're running a retry, reset the registry for this test only
28
27
  */
29
28
  beforeEach() {
30
- const {currentTest} = this;
29
+ const { currentTest } = this;
31
30
 
32
31
  if (currentTest.currentRetry() > 0) {
33
32
  // Reset registry for this test only
@@ -36,12 +35,12 @@ const mochaHooks = {
36
35
 
37
36
  snapshotManager.setCurrentTest({
38
37
  testPath: currentTest.file,
39
- testTitle: currentTest.fullTitle()
38
+ testTitle: currentTest.fullTitle(),
40
39
  });
41
- }
40
+ },
42
41
  };
43
42
 
44
- const {any, anything, stringMatching} = jestExpect;
43
+ const { any, anything, stringMatching } = jestExpect;
45
44
 
46
45
  module.exports = {
47
46
  mochaHooks,
@@ -49,5 +48,5 @@ module.exports = {
49
48
  matchSnapshotAssertion,
50
49
  any,
51
50
  anything,
52
- stringMatching
51
+ stringMatching,
53
52
  };
package/lib/utils.js CHANGED
@@ -4,7 +4,10 @@
4
4
  * @param {String} errorMessage
5
5
  * @returns {String}
6
6
  */
7
- module.exports.makeMessageFromMatchMessage = function makeMessageFromMatchMessage(message, errorMessage) {
7
+ module.exports.makeMessageFromMatchMessage = function makeMessageFromMatchMessage(
8
+ message,
9
+ errorMessage,
10
+ ) {
8
11
  const messageLines = message.split('\n');
9
12
  messageLines.splice(0, 1, errorMessage);
10
13
  return messageLines.join('\n');
package/package.json CHANGED
@@ -1,34 +1,34 @@
1
1
  {
2
2
  "name": "@tryghost/jest-snapshot",
3
- "version": "2.0.3",
3
+ "version": "2.2.0",
4
+ "license": "MIT",
5
+ "author": "Ghost Foundation",
4
6
  "repository": {
5
7
  "type": "git",
6
8
  "url": "git+https://github.com/TryGhost/framework.git",
7
9
  "directory": "packages/jest-snapshot"
8
10
  },
9
- "author": "Ghost Foundation",
10
- "license": "MIT",
11
- "main": "index.js",
12
- "scripts": {
13
- "dev": "echo \"Implement me!\"",
14
- "test": "NODE_ENV=testing vitest run --coverage --config ../../vitest.config.ts",
15
- "lint": "eslint . --ext .js --cache",
16
- "posttest": "yarn lint"
17
- },
18
11
  "files": [
19
12
  "index.js",
20
13
  "lib"
21
14
  ],
15
+ "main": "index.js",
22
16
  "publishConfig": {
23
17
  "access": "public"
24
18
  },
25
- "devDependencies": {
26
- "sinon": "21.0.2"
27
- },
28
19
  "dependencies": {
29
20
  "@jest/expect": "30.3.0",
30
21
  "@jest/expect-utils": "30.3.0",
31
- "@tryghost/errors": "^3.0.3",
32
- "jest-snapshot": "30.3.0"
22
+ "jest-snapshot": "30.3.0",
23
+ "@tryghost/errors": "3.2.0"
24
+ },
25
+ "devDependencies": {
26
+ "sinon": "21.1.2"
27
+ },
28
+ "scripts": {
29
+ "dev": "echo \"Implement me!\"",
30
+ "test": "NODE_ENV=testing vitest run --coverage",
31
+ "lint": "oxlint -c ../../.oxlintrc.json .",
32
+ "posttest": "pnpm run lint"
33
33
  }
34
- }
34
+ }