diff --git a/test/migration-createAsset.test.ts b/test/migration-createAsset.test.ts index eade34de..e22da05d 100644 --- a/test/migration-createAsset.test.ts +++ b/test/migration-createAsset.test.ts @@ -4,9 +4,10 @@ import * as prismic from "../src" import type { Asset } from "../src/types/api/asset/asset" import { AssetType } from "../src/types/api/asset/asset" -// Skip test on Node 16 and 18 -const hasFileConstructor = typeof File === "function" -const it = _it.skipIf(!hasFileConstructor) +// Skip test on Node 16 and 18 (File and FormData support) +const isNode16 = process.version.startsWith("v16") +const isNode18 = process.version.startsWith("v18") +const it = _it.skipIf(isNode16 || isNode18) it("creates an asset from a url", () => { const migration = prismic.createMigration() diff --git a/test/writeClient-createAsset.test.ts b/test/writeClient-createAsset.test.ts index 34eaabf8..11748113 100644 --- a/test/writeClient-createAsset.test.ts +++ b/test/writeClient-createAsset.test.ts @@ -7,9 +7,10 @@ import { ForbiddenError } from "../src" import { UNKNOWN_RATE_LIMIT_DELAY } from "../src/BaseClient" import type { AssetTag } from "../src/types/api/asset/tag" -// Skip test on Node 16 and 18 -const hasFileConstructor = typeof File === "function" -const it = _it.skipIf(!hasFileConstructor) +// Skip test on Node 16 and 18 (File and FormData support) +const isNode16 = process.version.startsWith("v16") +const isNode18 = process.version.startsWith("v18") +const it = _it.skipIf(isNode16 || isNode18) it.concurrent("creates an asset from string content", async (ctx) => { const client = createTestWriteClient({ ctx }) diff --git a/test/writeClient-createAssetTag.test.ts b/test/writeClient-createAssetTag.test.ts index 7c1d6d7e..d153ecc1 100644 --- a/test/writeClient-createAssetTag.test.ts +++ b/test/writeClient-createAssetTag.test.ts @@ -1,4 +1,4 @@ -import { expect, it } from "vitest" +import { it as _it, expect } from "vitest" import { createTestWriteClient } from "./__testutils__/createWriteClient" import { mockPrismicAssetAPI } from "./__testutils__/mockPrismicAssetAPI" @@ -7,6 +7,10 @@ import { ForbiddenError } from "../src" import { UNKNOWN_RATE_LIMIT_DELAY } from "../src/BaseClient" import type { AssetTag } from "../src/types/api/asset/tag" +// Skip test on Node 16 (FormData support) +const isNode16 = process.version.startsWith("v16") +const it = _it.skipIf(isNode16) + it.concurrent("creates a tag", async (ctx) => { const client = createTestWriteClient({ ctx }) diff --git a/test/writeClient-getAssets.test.ts b/test/writeClient-getAssets.test.ts index f206e706..e3c694bd 100644 --- a/test/writeClient-getAssets.test.ts +++ b/test/writeClient-getAssets.test.ts @@ -1,4 +1,4 @@ -import { expect, it } from "vitest" +import { it as _it, expect } from "vitest" import { createTestWriteClient } from "./__testutils__/createWriteClient" import { mockPrismicAssetAPI } from "./__testutils__/mockPrismicAssetAPI" @@ -6,6 +6,10 @@ import { mockPrismicAssetAPI } from "./__testutils__/mockPrismicAssetAPI" import { ForbiddenError } from "../src" import { AssetType } from "../src/types/api/asset/asset" +// Skip test on Node 16 (FormData support) +const isNode16 = process.version.startsWith("v16") +const it = _it.skipIf(isNode16) + it.concurrent("get assets", async (ctx) => { const client = createTestWriteClient({ ctx }) diff --git a/test/writeClient-migrate.test.ts b/test/writeClient-migrate.test.ts index dce47ec8..342032a7 100644 --- a/test/writeClient-migrate.test.ts +++ b/test/writeClient-migrate.test.ts @@ -1,4 +1,4 @@ -import { expect, it } from "vitest" +import { it as _it, expect, vi } from "vitest" import { createTestWriteClient } from "./__testutils__/createWriteClient" import { mockPrismicAssetAPI } from "./__testutils__/mockPrismicAssetAPI" @@ -7,14 +7,32 @@ import { mockPrismicRestAPIV2 } from "./__testutils__/mockPrismicRestAPIV2" import * as prismic from "../src" +// Skip test on Node 16 and 18 (File and FormData support) +const isNode16 = process.version.startsWith("v16") +const isNode18 = process.version.startsWith("v18") +const it = _it.skipIf(isNode16 || isNode18) + it("migrates nothing when migration is empty", async (ctx) => { const client = createTestWriteClient({ ctx }) mockPrismicRestAPIV2({ ctx }) mockPrismicAssetAPI({ ctx, client }) - mockPrismicMigrationAPI({ ctx, client }) + // Not mocking migration API to test we're not calling it + // mockPrismicMigrationAPI({ ctx, client }) const migration = prismic.createMigration() - await expect(client.migrate(migration)).resolves.toBeUndefined() + const reporter = vi.fn() + + await expect(client.migrate(migration, { reporter })).resolves.toBeUndefined() + + expect(reporter).toHaveBeenCalledWith({ + type: "end", + data: { + migrated: { + documents: 0, + assets: 0, + }, + }, + }) }) diff --git a/test/writeClient.test.ts b/test/writeClient.test.ts index bb8ea86b..b2ba0466 100644 --- a/test/writeClient.test.ts +++ b/test/writeClient.test.ts @@ -4,6 +4,7 @@ import * as prismic from "../src" it("`createWriteClient` creates a write client", () => { const client = prismic.createWriteClient("qwerty", { + fetch: vi.fn(), writeToken: "xxx", migrationAPIKey: "yyy", }) @@ -20,6 +21,7 @@ it("constructor warns if running in a browser-like environment", () => { .mockImplementation(() => void 0) prismic.createWriteClient("qwerty", { + fetch: vi.fn(), writeToken: "xxx", migrationAPIKey: "yyy", }) @@ -34,6 +36,7 @@ it("constructor warns if running in a browser-like environment", () => { it("uses provided asset API endpoint and adds `/` suffix", () => { const client = prismic.createWriteClient("qwerty", { + fetch: vi.fn(), assetAPIEndpoint: "https://example.com", writeToken: "xxx", migrationAPIKey: "yyy", @@ -44,6 +47,7 @@ it("uses provided asset API endpoint and adds `/` suffix", () => { it("uses provided migration API endpoint and adds `/` suffix", () => { const client = prismic.createWriteClient("qwerty", { + fetch: vi.fn(), migrationAPIEndpoint: "https://example.com", writeToken: "xxx", migrationAPIKey: "yyy",