Skip to content

Commit a302813

Browse files
committed
Release 2.0.0-0
1 parent 57bce56 commit a302813

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mattapperson/slapshot",
3-
"version": "1.4.3",
3+
"version": "2.0.0-0",
44
"main": "lib/index.js",
55
"description": "Mock method calls with snapshots, run your intigation tests online or offline!",
66
"license": "MIT",

src/__snapshots__/memorize.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ exports[`nested APIs with functions throw an error when called unless mocked man
4040

4141
exports[`resolves from disk on 2nd hit - c -- 0`] = `{"results":{"foo":"bar"}}`;
4242

43-
exports[`thrown errors are replayed - error -- 0`] = `{"results":null,"thrownError":"{\\"type\\":\\"Error\\",\\"message\\":\\"foo\\",\\"name\\":\\"Error\\",\\"stack\\":\\"Error: foo\\\\n at memorize_1.memorize (/home/coder/projects/slapshot/src/memorize.test.ts:279:13)\\\\n at Object.memorize (/home/coder/projects/slapshot/src/memorize.ts:61:29)\\\\n at expect (/home/coder/projects/slapshot/src/memorize.test.ts:278:5)\\\\n at Object.<anonymous> (/home/coder/projects/slapshot/node_modules/expect/build/toThrowMatchers.js:81:11)\\\\n at Object.throwingMatcher [as toThrowError] (/home/coder/projects/slapshot/node_modules/expect/build/index.js:342:33)\\\\n at /home/coder/projects/slapshot/src/memorize.test.ts:281:6\\\\n at Generator.next (<anonymous>)\\\\n at /home/coder/projects/slapshot/node_modules/tslib/tslib.js:110:75\\\\n at new Promise (<anonymous>)\\\\n at Object.__awaiter (/home/coder/projects/slapshot/node_modules/tslib/tslib.js:106:16)\\\\n at Object.<anonymous>.test (/home/coder/projects/slapshot/src/memorize.test.ts:272:47)\\\\n at Object.asyncJestTest (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:102:37)\\\\n at resolve (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:43:12)\\\\n at new Promise (<anonymous>)\\\\n at mapper (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:26:19)\\\\n at promise.then (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:73:41)\\"}"}`;
43+
exports[`thrown errors are replayed - error -- 0`] = `{"results":null,"thrownError":"{\\"type\\":\\"Error\\",\\"message\\":\\"foo\\",\\"name\\":\\"Error\\",\\"stack\\":\\"Error: foo\\\\n at memorize_1.memorize (/home/coder/projects/slapshot/src/memorize.test.ts:279:13)\\\\n at Object.memorize (/home/coder/projects/slapshot/src/memorize.ts:62:29)\\\\n at expect (/home/coder/projects/slapshot/src/memorize.test.ts:278:5)\\\\n at Object.<anonymous> (/home/coder/projects/slapshot/node_modules/expect/build/toThrowMatchers.js:81:11)\\\\n at Object.throwingMatcher [as toThrowError] (/home/coder/projects/slapshot/node_modules/expect/build/index.js:342:33)\\\\n at /home/coder/projects/slapshot/src/memorize.test.ts:281:6\\\\n at Generator.next (<anonymous>)\\\\n at /home/coder/projects/slapshot/node_modules/tslib/tslib.js:110:75\\\\n at new Promise (<anonymous>)\\\\n at Object.__awaiter (/home/coder/projects/slapshot/node_modules/tslib/tslib.js:106:16)\\\\n at Object.<anonymous>.test (/home/coder/projects/slapshot/src/memorize.test.ts:272:47)\\\\n at Object.asyncJestTest (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:102:37)\\\\n at resolve (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:43:12)\\\\n at new Promise (<anonymous>)\\\\n at mapper (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:26:19)\\\\n at promise.then (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:73:41)\\"}"}`;
4444

45-
exports[`thrown errors are replayed with custom properties - error -- 0`] = `{"results":null,"thrownError":"{\\"type\\":\\"Error\\",\\"message\\":\\"foo\\",\\"name\\":\\"Error\\",\\"stack\\":\\"Error: foo\\\\n at memorize_1.memorize (/home/coder/projects/slapshot/src/memorize.test.ts:307:13)\\\\n at Object.memorize (/home/coder/projects/slapshot/src/memorize.ts:61:29)\\\\n at expect (/home/coder/projects/slapshot/src/memorize.test.ts:306:5)\\\\n at Object.<anonymous> (/home/coder/projects/slapshot/node_modules/expect/build/toThrowMatchers.js:81:11)\\\\n at Object.throwingMatcher [as toThrowError] (/home/coder/projects/slapshot/node_modules/expect/build/index.js:342:33)\\\\n at /home/coder/projects/slapshot/src/memorize.test.ts:309:6\\\\n at Generator.next (<anonymous>)\\\\n at /home/coder/projects/slapshot/node_modules/tslib/tslib.js:110:75\\\\n at new Promise (<anonymous>)\\\\n at Object.__awaiter (/home/coder/projects/slapshot/node_modules/tslib/tslib.js:106:16)\\\\n at Object.<anonymous>.test (/home/coder/projects/slapshot/src/memorize.test.ts:292:70)\\\\n at Object.asyncJestTest (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:102:37)\\\\n at resolve (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:43:12)\\\\n at new Promise (<anonymous>)\\\\n at mapper (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:26:19)\\\\n at promise.then (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:73:41)\\",\\"customProp\\":\\"bar\\"}"}`;
45+
exports[`thrown errors are replayed with custom properties - error -- 0`] = `{"results":null,"thrownError":"{\\"type\\":\\"Error\\",\\"message\\":\\"foo\\",\\"name\\":\\"Error\\",\\"stack\\":\\"Error: foo\\\\n at memorize_1.memorize (/home/coder/projects/slapshot/src/memorize.test.ts:307:13)\\\\n at Object.memorize (/home/coder/projects/slapshot/src/memorize.ts:62:29)\\\\n at expect (/home/coder/projects/slapshot/src/memorize.test.ts:306:5)\\\\n at Object.<anonymous> (/home/coder/projects/slapshot/node_modules/expect/build/toThrowMatchers.js:81:11)\\\\n at Object.throwingMatcher [as toThrowError] (/home/coder/projects/slapshot/node_modules/expect/build/index.js:342:33)\\\\n at /home/coder/projects/slapshot/src/memorize.test.ts:309:6\\\\n at Generator.next (<anonymous>)\\\\n at /home/coder/projects/slapshot/node_modules/tslib/tslib.js:110:75\\\\n at new Promise (<anonymous>)\\\\n at Object.__awaiter (/home/coder/projects/slapshot/node_modules/tslib/tslib.js:106:16)\\\\n at Object.<anonymous>.test (/home/coder/projects/slapshot/src/memorize.test.ts:292:70)\\\\n at Object.asyncJestTest (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:102:37)\\\\n at resolve (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:43:12)\\\\n at new Promise (<anonymous>)\\\\n at mapper (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:26:19)\\\\n at promise.then (/home/coder/projects/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:73:41)\\",\\"customProp\\":\\"bar\\"}"}`;
4646

4747
exports[`throws error of non-matching snap when validateSnapshot is set to true - validateSnapshot -- 0`] = `{"results":22,"thrownError":null}`;
4848

src/get_from_jest_context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const getFromJestContext = (snapshotName: string, pure: boolean) => {
4646
addSnapshot: jestContext.addSnapshot as (
4747
testName: string,
4848
value: string
49-
) => void
49+
) => void,
50+
markSnapAsUsed: jestContext.markSnapAsUsed
5051
};
5152
};

src/hack_context.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ expect.extend({
1515
addSnapshot: (testName: string, value: string) => {
1616
// @ts-ignore
1717
this.snapshotState._addSnapshot(testName, value, { isInline: false });
18+
},
19+
markSnapAsUsed: (snapName: string) => {
20+
(this as any).snapshotState._uncheckedKeys.delete(snapName);
1821
}
1922
});
2023
return { pass: true, message: () => "expected the slapshot hack to work" };

src/memorize.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export function memorize<ReturnedData = any>(
5353
}
5454

5555
if (!runInOnlineMode()) {
56+
testData.markSnapAsUsed(testData.fullSnapshotName);
5657
return returnValues(safeSnapshot(snap, false));
5758
}
5859

@@ -120,7 +121,7 @@ function resolveData(
120121
if (typeof methodResultsToCompare === "object") {
121122
methodResultsToCompare = JSON.stringify(methodResultsToCompare);
122123
}
123-
console.log(methodResultsToCompare, snapDataToCompare);
124+
124125
if (
125126
(snap.results || snap.thrownError) &&
126127
methodResultsToCompare !== snapDataToCompare
@@ -147,14 +148,14 @@ function resolveData(
147148
}
148149
}
149150
}
150-
151+
testData.markSnapAsUsed(testData.fullSnapshotName);
151152
return returnValues(methodResults);
152153
}
153154

154155
testData.addSnapshot(
155156
fullSnapshotName,
156157
JSON.stringify(safeSnapshot(methodResults))
157158
);
158-
159+
testData.markSnapAsUsed(testData.fullSnapshotName);
159160
return returnValues(methodResults);
160161
}

0 commit comments

Comments
 (0)