diff --git a/packages/api/test/codegen/languages/typescript/index.test.ts b/packages/api/test/codegen/languages/typescript/index.test.ts index d6c0c255..b323f327 100644 --- a/packages/api/test/codegen/languages/typescript/index.test.ts +++ b/packages/api/test/codegen/languages/typescript/index.test.ts @@ -1,3 +1,5 @@ +import type { SpyInstance } from 'vitest'; + import fs from 'node:fs/promises'; import path from 'node:path'; @@ -70,22 +72,16 @@ function assertSDKFixture(file: string, fixture: string) { const actual = actualFiles[filename]; const expectedFilePath = path.join(dir, filename); - // We have to wrap in our current package version into the `<>` placeholder so - // we don't need to worry about committing package versions into source control or trying - // to mock out our `packageInfo` library, potentially causing sideeffects in other tests. - return fs - .readFile(expectedFilePath, 'utf8') - .then(expected => expected.replace('<>', packageInfo.PACKAGE_VERSION)) - .then(async expected => { - if (actual !== expected && process.env.UPDATE_FIXTURES) { - // eslint-disable-next-line no-console - console.info('[sdk fixture updated]', expectedFilePath); - await fs.writeFile(expectedFilePath, actual.replace(packageInfo.PACKAGE_VERSION, '<>')); - return; - } - - expect(actual).toBe(expected); - }); + return fs.readFile(expectedFilePath, 'utf8').then(async expected => { + if (actual !== expected && process.env.UPDATE_FIXTURES) { + // eslint-disable-next-line no-console + console.info('[sdk fixture updated]', expectedFilePath); + await fs.writeFile(expectedFilePath, actual); + return; + } + + expect(actual).toBe(expected); + }); }), ); @@ -96,12 +92,17 @@ function assertSDKFixture(file: string, fixture: string) { } describe('typescript', () => { + let packageInfoSpy: SpyInstance; + beforeEach(() => { + // @ts-expect-error deliberately setting this const to another value + packageInfoSpy = vi.spyOn(packageInfo, 'PACKAGE_VERSION', 'get').mockReturnValue('7.0.0-mock'); vi.setSystemTime(new Date('2023-10-25')); Storage.setStorageDir(uniqueTempDir()); }); afterEach(() => { + packageInfoSpy.mockReset(); vi.useRealTimers(); Storage.reset(); }); diff --git a/packages/api/test/commands/__snapshots__/list.test.ts.snap b/packages/api/test/commands/__snapshots__/list.test.ts.snap index 589004ce..b68cfe48 100644 --- a/packages/api/test/commands/__snapshots__/list.test.ts.snap +++ b/packages/api/test/commands/__snapshots__/list.test.ts.snap @@ -9,7 +9,7 @@ language: js source: @petstore/v1.0#n6kvf10vakpemvplx -installer version: 7.0.0-beta.3 +installer version: 7.0.0-mock created at: 2023-10-25T00:00:00.000Z" `; diff --git a/packages/api/test/commands/list.test.ts b/packages/api/test/commands/list.test.ts index 0e780c74..8c7c0d4e 100644 --- a/packages/api/test/commands/list.test.ts +++ b/packages/api/test/commands/list.test.ts @@ -8,6 +8,7 @@ import { describe, beforeEach, it, expect, vi, afterEach } from 'vitest'; import { SupportedLanguages } from '../../src/codegen/factory.js'; import installCmd from '../../src/commands/list.js'; +import * as packageInfo from '../../src/packageInfo.js'; import Storage from '../../src/storage.js'; const baseCommand = ['api', 'list']; @@ -18,6 +19,7 @@ describe('install command', () => { let stdout: string[]; let stderr: string[]; let consoleLogSpy: SpyInstance; + let packageInfoSpy: SpyInstance; const getCommandOutput = () => { return [consoleLogSpy.mock.calls.join('\n\n')].filter(Boolean).join('\n\n'); @@ -34,13 +36,16 @@ describe('install command', () => { }); consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); + // @ts-expect-error deliberately setting this const to another value + packageInfoSpy = vi.spyOn(packageInfo, 'PACKAGE_VERSION', 'get').mockReturnValue('7.0.0-mock'); Storage.setStorageDir(uniqueTempDir()); vi.setSystemTime(new Date('2023-10-25')); }); afterEach(() => { - consoleLogSpy.mockRestore(); + consoleLogSpy.mockReset(); fetchMock.restore(); + packageInfoSpy.mockReset(); Storage.reset(); vi.useRealTimers(); }); diff --git a/packages/test-utils/sdks/alby/README.md b/packages/test-utils/sdks/alby/README.md index a682b3fc..8c62aeaf 100644 --- a/packages/test-utils/sdks/alby/README.md +++ b/packages/test-utils/sdks/alby/README.md @@ -17,7 +17,7 @@ alby.getMe() Here's some additional info about the generated SDK: -`api` version: <> +`api` version: 7.0.0-mock Generated at 2023-10-25T00:00:00.000Z ---> diff --git a/packages/test-utils/sdks/alby/src/index.ts b/packages/test-utils/sdks/alby/src/index.ts index 7eb82bfb..8c589012 100644 --- a/packages/test-utils/sdks/alby/src/index.ts +++ b/packages/test-utils/sdks/alby/src/index.ts @@ -7,7 +7,7 @@ class SDK { core: APICore; constructor() { - this.core = new APICore(definition, 'alby/1.0.14 (api/<>)'); + this.core = new APICore(definition, 'alby/1.0.14 (api/7.0.0-mock)'); } /** diff --git a/packages/test-utils/sdks/metrotransit/README.md b/packages/test-utils/sdks/metrotransit/README.md index 56a211ac..8c103849 100644 --- a/packages/test-utils/sdks/metrotransit/README.md +++ b/packages/test-utils/sdks/metrotransit/README.md @@ -16,7 +16,7 @@ metrotransit.getNextripAgencies() Here's some additional info about the generated SDK: -`api` version: <> +`api` version: 7.0.0-mock Generated at 2023-10-25T00:00:00.000Z ---> diff --git a/packages/test-utils/sdks/metrotransit/src/index.ts b/packages/test-utils/sdks/metrotransit/src/index.ts index 378a5602..7e223df9 100644 --- a/packages/test-utils/sdks/metrotransit/src/index.ts +++ b/packages/test-utils/sdks/metrotransit/src/index.ts @@ -7,7 +7,7 @@ class SDK { core: APICore; constructor() { - this.core = new APICore(definition, 'metrotransit/2 (api/<>)'); + this.core = new APICore(definition, 'metrotransit/2 (api/7.0.0-mock)'); } /** diff --git a/packages/test-utils/sdks/operationid-quirks/README.md b/packages/test-utils/sdks/operationid-quirks/README.md index edf4faba..5080d23a 100644 --- a/packages/test-utils/sdks/operationid-quirks/README.md +++ b/packages/test-utils/sdks/operationid-quirks/README.md @@ -16,7 +16,7 @@ operationidQuirks.quirky_OperationId_string() Here's some additional info about the generated SDK: -`api` version: <> +`api` version: 7.0.0-mock Generated at 2023-10-25T00:00:00.000Z ---> diff --git a/packages/test-utils/sdks/operationid-quirks/src/index.ts b/packages/test-utils/sdks/operationid-quirks/src/index.ts index 7cde59f9..ea1eab28 100644 --- a/packages/test-utils/sdks/operationid-quirks/src/index.ts +++ b/packages/test-utils/sdks/operationid-quirks/src/index.ts @@ -6,7 +6,7 @@ class SDK { core: APICore; constructor() { - this.core = new APICore(definition, 'operationid-quirks/1.0.0 (api/<>)'); + this.core = new APICore(definition, 'operationid-quirks/1.0.0 (api/7.0.0-mock)'); } /** diff --git a/packages/test-utils/sdks/optional-payload/README.md b/packages/test-utils/sdks/optional-payload/README.md index fa994f2f..36c84222 100644 --- a/packages/test-utils/sdks/optional-payload/README.md +++ b/packages/test-utils/sdks/optional-payload/README.md @@ -8,7 +8,7 @@ Add SDK setup information and usage examples here so your users get started in a Here's some additional info about the generated SDK: -`api` version: <> +`api` version: 7.0.0-mock Generated at 2023-10-25T00:00:00.000Z ---> diff --git a/packages/test-utils/sdks/optional-payload/src/index.ts b/packages/test-utils/sdks/optional-payload/src/index.ts index 7116b388..b9a61b98 100644 --- a/packages/test-utils/sdks/optional-payload/src/index.ts +++ b/packages/test-utils/sdks/optional-payload/src/index.ts @@ -7,7 +7,7 @@ class SDK { core: APICore; constructor() { - this.core = new APICore(definition, 'optional-payload/1.0.0 (api/<>)'); + this.core = new APICore(definition, 'optional-payload/1.0.0 (api/7.0.0-mock)'); } /** diff --git a/packages/test-utils/sdks/petstore/README.md b/packages/test-utils/sdks/petstore/README.md index 31dc70d5..3e76612c 100644 --- a/packages/test-utils/sdks/petstore/README.md +++ b/packages/test-utils/sdks/petstore/README.md @@ -17,7 +17,7 @@ petstore.getInventory() Here's some additional info about the generated SDK: -`api` version: <> +`api` version: 7.0.0-mock Generated at 2023-10-25T00:00:00.000Z ---> diff --git a/packages/test-utils/sdks/petstore/src/index.ts b/packages/test-utils/sdks/petstore/src/index.ts index aedae05c..7fa46010 100644 --- a/packages/test-utils/sdks/petstore/src/index.ts +++ b/packages/test-utils/sdks/petstore/src/index.ts @@ -7,7 +7,7 @@ class SDK { core: APICore; constructor() { - this.core = new APICore(definition, 'petstore/1.0.0 (api/<>)'); + this.core = new APICore(definition, 'petstore/1.0.0 (api/7.0.0-mock)'); } /** diff --git a/packages/test-utils/sdks/readme/README.md b/packages/test-utils/sdks/readme/README.md index a80c28f8..162764c5 100644 --- a/packages/test-utils/sdks/readme/README.md +++ b/packages/test-utils/sdks/readme/README.md @@ -17,7 +17,7 @@ readme.getAPISpecification() Here's some additional info about the generated SDK: -`api` version: <> +`api` version: 7.0.0-mock Generated at 2023-10-25T00:00:00.000Z ---> diff --git a/packages/test-utils/sdks/readme/src/index.ts b/packages/test-utils/sdks/readme/src/index.ts index baf69853..7404db08 100644 --- a/packages/test-utils/sdks/readme/src/index.ts +++ b/packages/test-utils/sdks/readme/src/index.ts @@ -7,7 +7,7 @@ class SDK { core: APICore; constructor() { - this.core = new APICore(definition, 'readme/4.355.0 (api/<>)'); + this.core = new APICore(definition, 'readme/4.355.0 (api/7.0.0-mock)'); } /** diff --git a/packages/test-utils/sdks/response-title-quirks/README.md b/packages/test-utils/sdks/response-title-quirks/README.md index 395ed81c..336ca017 100644 --- a/packages/test-utils/sdks/response-title-quirks/README.md +++ b/packages/test-utils/sdks/response-title-quirks/README.md @@ -8,7 +8,7 @@ Add SDK setup information and usage examples here so your users get started in a Here's some additional info about the generated SDK: -`api` version: <> +`api` version: 7.0.0-mock Generated at 2023-10-25T00:00:00.000Z ---> diff --git a/packages/test-utils/sdks/response-title-quirks/src/index.ts b/packages/test-utils/sdks/response-title-quirks/src/index.ts index 9e7ed6fc..2a1db243 100644 --- a/packages/test-utils/sdks/response-title-quirks/src/index.ts +++ b/packages/test-utils/sdks/response-title-quirks/src/index.ts @@ -7,7 +7,7 @@ class SDK { core: APICore; constructor() { - this.core = new APICore(definition, 'response-title-quirks/1.0.0 (api/<>)'); + this.core = new APICore(definition, 'response-title-quirks/1.0.0 (api/7.0.0-mock)'); } /** diff --git a/packages/test-utils/sdks/simple/README.md b/packages/test-utils/sdks/simple/README.md index c2e0c52d..4e41dbe9 100644 --- a/packages/test-utils/sdks/simple/README.md +++ b/packages/test-utils/sdks/simple/README.md @@ -8,7 +8,7 @@ Add SDK setup information and usage examples here so your users get started in a Here's some additional info about the generated SDK: -`api` version: <> +`api` version: 7.0.0-mock Generated at 2023-10-25T00:00:00.000Z ---> diff --git a/packages/test-utils/sdks/simple/src/index.ts b/packages/test-utils/sdks/simple/src/index.ts index 70b87730..466df99e 100644 --- a/packages/test-utils/sdks/simple/src/index.ts +++ b/packages/test-utils/sdks/simple/src/index.ts @@ -7,7 +7,7 @@ class SDK { core: APICore; constructor() { - this.core = new APICore(definition, 'simple/1.0.0 (api/<>)'); + this.core = new APICore(definition, 'simple/1.0.0 (api/7.0.0-mock)'); } /** diff --git a/packages/test-utils/sdks/star-trek/README.md b/packages/test-utils/sdks/star-trek/README.md index 523ad114..a30bcc06 100644 --- a/packages/test-utils/sdks/star-trek/README.md +++ b/packages/test-utils/sdks/star-trek/README.md @@ -16,7 +16,7 @@ starTrek.getAnimalSearch() Here's some additional info about the generated SDK: -`api` version: <> +`api` version: 7.0.0-mock Generated at 2023-10-25T00:00:00.000Z ---> diff --git a/packages/test-utils/sdks/star-trek/src/index.ts b/packages/test-utils/sdks/star-trek/src/index.ts index 7335a08b..9a426234 100644 --- a/packages/test-utils/sdks/star-trek/src/index.ts +++ b/packages/test-utils/sdks/star-trek/src/index.ts @@ -7,7 +7,7 @@ class SDK { core: APICore; constructor() { - this.core = new APICore(definition, 'star-trek/1.0.0 (api/<>)'); + this.core = new APICore(definition, 'star-trek/1.0.0 (api/7.0.0-mock)'); } /**