Skip to content

Commit

Permalink
Release 2.0.0-0
Browse files Browse the repository at this point in the history
  • Loading branch information
mattapperson committed Oct 15, 2019
1 parent 57bce56 commit a302813
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mattapperson/slapshot",
"version": "1.4.3",
"version": "2.0.0-0",
"main": "lib/index.js",
"description": "Mock method calls with snapshots, run your intigation tests online or offline!",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/__snapshots__/memorize.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ exports[`nested APIs with functions throw an error when called unless mocked man

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

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)\\"}"}`;
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)\\"}"}`;

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\\"}"}`;
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\\"}"}`;

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

Expand Down
3 changes: 2 additions & 1 deletion src/get_from_jest_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const getFromJestContext = (snapshotName: string, pure: boolean) => {
addSnapshot: jestContext.addSnapshot as (
testName: string,
value: string
) => void
) => void,
markSnapAsUsed: jestContext.markSnapAsUsed
};
};
3 changes: 3 additions & 0 deletions src/hack_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ expect.extend({
addSnapshot: (testName: string, value: string) => {
// @ts-ignore
this.snapshotState._addSnapshot(testName, value, { isInline: false });
},
markSnapAsUsed: (snapName: string) => {
(this as any).snapshotState._uncheckedKeys.delete(snapName);
}
});
return { pass: true, message: () => "expected the slapshot hack to work" };
Expand Down
7 changes: 4 additions & 3 deletions src/memorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function memorize<ReturnedData = any>(
}

if (!runInOnlineMode()) {
testData.markSnapAsUsed(testData.fullSnapshotName);
return returnValues(safeSnapshot(snap, false));
}

Expand Down Expand Up @@ -120,7 +121,7 @@ function resolveData(
if (typeof methodResultsToCompare === "object") {
methodResultsToCompare = JSON.stringify(methodResultsToCompare);
}
console.log(methodResultsToCompare, snapDataToCompare);

if (
(snap.results || snap.thrownError) &&
methodResultsToCompare !== snapDataToCompare
Expand All @@ -147,14 +148,14 @@ function resolveData(
}
}
}

testData.markSnapAsUsed(testData.fullSnapshotName);
return returnValues(methodResults);
}

testData.addSnapshot(
fullSnapshotName,
JSON.stringify(safeSnapshot(methodResults))
);

testData.markSnapAsUsed(testData.fullSnapshotName);
return returnValues(methodResults);
}

0 comments on commit a302813

Please sign in to comment.