From db5ce99522256b207a4a011985d774bcff394aa0 Mon Sep 17 00:00:00 2001 From: Frederik Bolding Date: Fri, 6 Jan 2023 12:30:29 +0100 Subject: [PATCH 1/2] Bump superstruct to 1.0.3 --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 158b4c04..05b0fcb2 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@types/debug": "^4.1.7", "debug": "^4.3.4", "semver": "^7.3.8", - "superstruct": "^0.16.7" + "superstruct": "^1.0.3" }, "devDependencies": { "@lavamoat/allow-scripts": "^2.0.3", diff --git a/yarn.lock b/yarn.lock index 64fe526c..33b51ef1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -928,7 +928,7 @@ __metadata: rimraf: ^3.0.2 semver: ^7.3.8 stdio-mock: ^1.2.0 - superstruct: ^0.16.7 + superstruct: ^1.0.3 ts-jest: ^29.0.3 tsd: ^0.24.1 typedoc: ^0.23.10 @@ -5934,10 +5934,10 @@ __metadata: languageName: node linkType: hard -"superstruct@npm:^0.16.7": - version: 0.16.7 - resolution: "superstruct@npm:0.16.7" - checksum: c8c855ff6945da8a41048c6d236de7b1af5d4d9c31742b3ee54d65647c31597488620281f65e095d5efc9e2fbdaad529b8c8f2506c12569d428467c835a21477 +"superstruct@npm:^1.0.3": + version: 1.0.3 + resolution: "superstruct@npm:1.0.3" + checksum: 761790bb111e6e21ddd608299c252f3be35df543263a7ebbc004e840d01fcf8046794c274bcb351bdf3eae4600f79d317d085cdbb19ca05803a4361840cc9bb1 languageName: node linkType: hard From 841abfa450e34713a37a7ccf42b9833716fb6214 Mon Sep 17 00:00:00 2001 From: Frederik Bolding Date: Fri, 6 Jan 2023 13:13:32 +0100 Subject: [PATCH 2/2] Fix tests --- src/assert.test.ts | 19 +++++++++++++++--- src/json.test.ts | 49 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/assert.test.ts b/src/assert.test.ts index 1449a57e..200da481 100644 --- a/src/assert.test.ts +++ b/src/assert.test.ts @@ -1,5 +1,4 @@ -import { string } from 'superstruct'; -import * as superstructModule from 'superstruct'; +import { string, assert as superstructAssert } from 'superstruct'; import { assert, @@ -8,6 +7,11 @@ import { assertStruct, } from './assert'; +jest.mock('superstruct', () => ({ + ...jest.requireActual('superstruct'), + assert: jest.fn(), +})); + describe('assert', () => { it('succeeds', () => { expect(() => assert(true)).not.toThrow(); @@ -45,6 +49,13 @@ describe('assertExhaustive', () => { }); describe('assertStruct', () => { + beforeEach(() => { + const actual = jest.requireActual('superstruct'); + ( + superstructAssert as jest.MockedFunction + ).mockImplementation(actual.assert); + }); + it('does not throw for a valid value', () => { expect(() => assertStruct('foo', string())).not.toThrow(); }); @@ -98,7 +109,9 @@ describe('assertStruct', () => { }); it('includes the value thrown in the message if it is not an error', () => { - jest.spyOn(superstructModule, 'assert').mockImplementation(() => { + ( + superstructAssert as jest.MockedFunction + ).mockImplementation(() => { // eslint-disable-next-line @typescript-eslint/no-throw-literal throw 'foo.'; }); diff --git a/src/json.test.ts b/src/json.test.ts index 8381ee78..1b5e5efa 100644 --- a/src/json.test.ts +++ b/src/json.test.ts @@ -1,5 +1,4 @@ -import * as superstructModule from 'superstruct'; -import { validate } from 'superstruct'; +import { validate, assert as superstructAssert } from 'superstruct'; import { assert, @@ -36,7 +35,19 @@ import { NON_SERIALIZABLE_NESTED_OBJECT, } from './__fixtures__'; +jest.mock('superstruct', () => ({ + ...jest.requireActual('superstruct'), + assert: jest.fn(), +})); + describe('json', () => { + beforeEach(() => { + const actual = jest.requireActual('superstruct'); + ( + superstructAssert as jest.MockedFunction + ).mockImplementation(actual.assert); + }); + describe('JsonStruct', () => { it('returns error message', () => { const [error] = validate(undefined, JsonStruct); @@ -104,7 +115,9 @@ describe('json', () => { }); it('includes the value thrown in the message if it is not an error', () => { - jest.spyOn(superstructModule, 'assert').mockImplementation(() => { + ( + superstructAssert as jest.MockedFunction + ).mockImplementation(() => { // eslint-disable-next-line @typescript-eslint/no-throw-literal throw 'oops'; }); @@ -157,7 +170,9 @@ describe('json', () => { }); it('includes the value thrown in the message if it is not an error', () => { - jest.spyOn(superstructModule, 'assert').mockImplementation(() => { + ( + superstructAssert as jest.MockedFunction + ).mockImplementation(() => { // eslint-disable-next-line @typescript-eslint/no-throw-literal throw 'oops'; }); @@ -210,9 +225,11 @@ describe('json', () => { }); it('includes the value thrown in the message if it is not an error', () => { - jest.spyOn(superstructModule, 'assert').mockImplementation(() => { + ( + superstructAssert as jest.MockedFunction + ).mockImplementation(() => { // eslint-disable-next-line @typescript-eslint/no-throw-literal - throw 'oops'; + throw 'oops.'; }); expect(() => @@ -263,9 +280,11 @@ describe('json', () => { }); it('includes the value thrown in the message if it is not an error', () => { - jest.spyOn(superstructModule, 'assert').mockImplementation(() => { + ( + superstructAssert as jest.MockedFunction + ).mockImplementation(() => { // eslint-disable-next-line @typescript-eslint/no-throw-literal - throw 'oops'; + throw 'oops.'; }); expect(() => @@ -316,7 +335,9 @@ describe('json', () => { }); it('includes the value thrown in the message if it is not an error', () => { - jest.spyOn(superstructModule, 'assert').mockImplementation(() => { + ( + superstructAssert as jest.MockedFunction + ).mockImplementation(() => { // eslint-disable-next-line @typescript-eslint/no-throw-literal throw 'oops'; }); @@ -361,7 +382,9 @@ describe('json', () => { ); it('includes the value thrown in the message if it is not an error', () => { - jest.spyOn(superstructModule, 'assert').mockImplementation(() => { + ( + superstructAssert as jest.MockedFunction + ).mockImplementation(() => { // eslint-disable-next-line @typescript-eslint/no-throw-literal throw 'oops'; }); @@ -414,9 +437,11 @@ describe('json', () => { }); it('includes the value thrown in the message if it is not an error', () => { - jest.spyOn(superstructModule, 'assert').mockImplementation(() => { + ( + superstructAssert as jest.MockedFunction + ).mockImplementation(() => { // eslint-disable-next-line @typescript-eslint/no-throw-literal - throw 'oops'; + throw 'oops.'; }); expect(() =>