Skip to content

Commit

Permalink
Release 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mattapperson committed Oct 26, 2019
1 parent 499cff5 commit 595d656
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 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": "2.0.0-0",
"version": "2.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 @@ -38,9 +38,9 @@ exports[`Test: nested APIs with functions throw an error when called unless mock

exports[`Test: resolves from disk on 2nd hit | Memorized Name: c | Call iteration: 0`] = `{"results":{"foo":"bar"}}`;

exports[`Test: thrown errors are replayed | Memorized Name: error | Call iteration: 0`] = `{"results":null,"thrownError":"{\\"type\\":\\"Error\\",\\"message\\":\\"foo\\",\\"name\\":\\"Error\\",\\"stack\\":\\"Error: foo\\\\n at memorize_1.memorize (/Users/mattapperson/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.153/projects/75caf8bc3401eff7/instrumented/src/memorize.test.js:362:27)\\\\n at Object.memorize (/Users/mattapperson/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.153/projects/75caf8bc3401eff7/instrumented/src/memorize.js:51:46)\\\\n at expect (/Users/mattapperson/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.153/projects/75caf8bc3401eff7/instrumented/src/memorize.test.js:358:38)\\\\n at Object.<anonymous> (/Users/mattapperson/Development/slapshot/node_modules/expect/build/toThrowMatchers.js:81:11)\\\\n at Object.throwingMatcher [as toThrowError] (/Users/mattapperson/Development/slapshot/node_modules/expect/build/index.js:342:33)\\\\n at Object.<anonymous> (/Users/mattapperson/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.153/projects/75caf8bc3401eff7/instrumented/src/memorize.test.js:365:12)\\\\n at Generator.next (<anonymous>)\\\\n at /Users/mattapperson/Development/slapshot/node_modules/tslib/tslib.js:110:75\\\\n at new Promise (<anonymous>)\\\\n at Object.__awaiter (/Users/mattapperson/Development/slapshot/node_modules/tslib/tslib.js:106:16)\\\\n at Object.<anonymous>.test (/Users/mattapperson/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.153/projects/75caf8bc3401eff7/instrumented/src/memorize.test.js:351:34)\\\\n at Object.e.length.arguments.(anonymous function) (/Users/mattapperson/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.153/wallaby/runners/node/[email protected]/jasmine2Initializer.js:14:1786)\\\\n at Object.asyncJestTest (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:102:37)\\\\n at resolve (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:43:12)\\\\n at new Promise (<anonymous>)\\\\n at mapper (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:26:19)\\\\n at promise.then (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:73:41)\\"}"}`;
exports[`Test: thrown errors are replayed | Memorized Name: error | Call iteration: 0`] = `{"results":null,"thrownError":"{\\"type\\":\\"Error\\",\\"message\\":\\"foo\\",\\"name\\":\\"Error\\",\\"stack\\":\\"Error: foo\\\\n at memorize_1.memorize (/Users/mattapperson/Development/slapshot/src/memorize.test.ts:319:13)\\\\n at Object.memorize (/Users/mattapperson/Development/slapshot/src/memorize.ts:62:29)\\\\n at expect (/Users/mattapperson/Development/slapshot/src/memorize.test.ts:318:5)\\\\n at Object.<anonymous> (/Users/mattapperson/Development/slapshot/node_modules/expect/build/toThrowMatchers.js:81:11)\\\\n at Object.throwingMatcher [as toThrowError] (/Users/mattapperson/Development/slapshot/node_modules/expect/build/index.js:342:33)\\\\n at /Users/mattapperson/Development/slapshot/src/memorize.test.ts:321:6\\\\n at Generator.next (<anonymous>)\\\\n at /Users/mattapperson/Development/slapshot/node_modules/tslib/tslib.js:110:75\\\\n at new Promise (<anonymous>)\\\\n at Object.__awaiter (/Users/mattapperson/Development/slapshot/node_modules/tslib/tslib.js:106:16)\\\\n at Object.<anonymous>.test (/Users/mattapperson/Development/slapshot/src/memorize.test.ts:311:47)\\\\n at Object.asyncJestTest (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:102:37)\\\\n at resolve (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:43:12)\\\\n at new Promise (<anonymous>)\\\\n at mapper (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:26:19)\\\\n at promise.then (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:73:41)\\"}"}`;

exports[`Test: thrown errors are replayed with custom properties | Memorized Name: error | Call iteration: 0`] = `{"results":null,"thrownError":"{\\"type\\":\\"Error\\",\\"message\\":\\"foo\\",\\"name\\":\\"Error\\",\\"stack\\":\\"Error: foo\\\\n at memorize_1.memorize (/Users/mattapperson/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.153/projects/75caf8bc3401eff7/instrumented/src/memorize.test.js:395:27)\\\\n at Object.memorize (/Users/mattapperson/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.153/projects/75caf8bc3401eff7/instrumented/src/memorize.js:51:46)\\\\n at expect (/Users/mattapperson/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.153/projects/75caf8bc3401eff7/instrumented/src/memorize.test.js:391:38)\\\\n at Object.<anonymous> (/Users/mattapperson/Development/slapshot/node_modules/expect/build/toThrowMatchers.js:81:11)\\\\n at Object.throwingMatcher [as toThrowError] (/Users/mattapperson/Development/slapshot/node_modules/expect/build/index.js:342:33)\\\\n at Object.<anonymous> (/Users/mattapperson/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.153/projects/75caf8bc3401eff7/instrumented/src/memorize.test.js:398:12)\\\\n at Generator.next (<anonymous>)\\\\n at /Users/mattapperson/Development/slapshot/node_modules/tslib/tslib.js:110:75\\\\n at new Promise (<anonymous>)\\\\n at Object.__awaiter (/Users/mattapperson/Development/slapshot/node_modules/tslib/tslib.js:106:16)\\\\n at Object.<anonymous>.test (/Users/mattapperson/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.153/projects/75caf8bc3401eff7/instrumented/src/memorize.test.js:378:34)\\\\n at Object.e.length.arguments.(anonymous function) (/Users/mattapperson/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.153/wallaby/runners/node/[email protected]/jasmine2Initializer.js:14:1786)\\\\n at Object.asyncJestTest (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:102:37)\\\\n at resolve (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:43:12)\\\\n at new Promise (<anonymous>)\\\\n at mapper (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:26:19)\\\\n at promise.then (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:73:41)\\",\\"customProp\\":\\"bar\\"}"}`;
exports[`Test: thrown errors are replayed with custom properties | Memorized Name: error | Call iteration: 0`] = `{"results":null,"thrownError":"{\\"type\\":\\"Error\\",\\"message\\":\\"foo\\",\\"name\\":\\"Error\\",\\"stack\\":\\"Error: foo\\\\n at memorize_1.memorize (/Users/mattapperson/Development/slapshot/src/memorize.test.ts:350:13)\\\\n at Object.memorize (/Users/mattapperson/Development/slapshot/src/memorize.ts:62:29)\\\\n at expect (/Users/mattapperson/Development/slapshot/src/memorize.test.ts:349:5)\\\\n at Object.<anonymous> (/Users/mattapperson/Development/slapshot/node_modules/expect/build/toThrowMatchers.js:81:11)\\\\n at Object.throwingMatcher [as toThrowError] (/Users/mattapperson/Development/slapshot/node_modules/expect/build/index.js:342:33)\\\\n at /Users/mattapperson/Development/slapshot/src/memorize.test.ts:352:6\\\\n at Generator.next (<anonymous>)\\\\n at /Users/mattapperson/Development/slapshot/node_modules/tslib/tslib.js:110:75\\\\n at new Promise (<anonymous>)\\\\n at Object.__awaiter (/Users/mattapperson/Development/slapshot/node_modules/tslib/tslib.js:106:16)\\\\n at Object.<anonymous>.test (/Users/mattapperson/Development/slapshot/src/memorize.test.ts:334:70)\\\\n at Object.asyncJestTest (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:102:37)\\\\n at resolve (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:43:12)\\\\n at new Promise (<anonymous>)\\\\n at mapper (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:26:19)\\\\n at promise.then (/Users/mattapperson/Development/slapshot/node_modules/jest-jasmine2/build/queueRunner.js:73:41)\\",\\"customProp\\":\\"bar\\"}"}`;

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

Expand Down
6 changes: 2 additions & 4 deletions src/memorize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const complexReturn = (someValue: any = null) => {

let mockPromise: any;
let mockThunk: any;

let mockedConsole: jest.SpyInstance;

beforeEach(() => {
process.env.SLAPSHOT_HACK_BYPASS_JEST_SHOULD_UPDATE_SNAPSHOTS_FOR_TESTS = undefined;
process.env.SLAPSHOT_ONLINE = undefined;
Expand Down Expand Up @@ -105,7 +105,6 @@ test("calls run but dont update with SLAPSHOT_ONLINE", async () => {
expect(mockWithValue.mock.calls.length).toBe(2);
expect(mockWithValue.mock.calls.length).toBe(2);
expect(data2.foo).toBe("bar");
expect(mockedConsole).not.toBeCalled();
});

test("calls run still in unit tests with just updateSnapshot", async () => {
Expand All @@ -119,9 +118,8 @@ test("calls run still in unit tests with just updateSnapshot", async () => {
process.env.SLAPSHOT_ONLINE = "false";
const data: any = await memorize("d", mockThunk);
expect(mockThunk.mock.calls.length).toBe(1);
expect(mockThunk.mock.calls.length).toBe(1);
expect(data.foo).toBe("bar");
expect(mockedConsole).not.toBeCalled();
expect(mockedConsole).toBeCalled();
});

test("calls run and update with updateSnapshot and SLAPSHOT_ONLINE", async () => {
Expand Down
8 changes: 5 additions & 3 deletions src/memorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function memorize<ReturnedData = any>(
if (!testData.shouldUpdateSnapshot && !runInOnlineMode() && !snapshot) {
throw new Error(
`Missing snapshot
- Method snapshot name: ${testData.fullSnapshotName}
- Snapshot name: ${testData.fullSnapshotName}
- In snapshot file: ${testData.testFileName}
- Test file: ${testData.testFilePath}
Expand Down Expand Up @@ -119,15 +119,17 @@ function resolveData(

let methodResultsToCompare: any = methodResults;
if (typeof methodResultsToCompare === "object") {
methodResultsToCompare = JSON.stringify(methodResultsToCompare);
methodResultsToCompare = JSON.stringify(
safeSnapshot(methodResultsToCompare)
);
}

if (
(snap.results || snap.thrownError) &&
methodResultsToCompare !== snapDataToCompare
) {
const defaultWarning = `[Warning] Integration test result does not match the memorized snap file:
- Method snapshot name: ${fullSnapshotName}
- Snapshot name: ${fullSnapshotName}
- Test file: ${testData.testFilePath
.split(".")
.slice(0, -1)
Expand Down

0 comments on commit 595d656

Please sign in to comment.