Skip to content

Commit

Permalink
test: skip tests on specific node version
Browse files Browse the repository at this point in the history
  • Loading branch information
lihbr committed Sep 4, 2024
1 parent 58f1765 commit 84ed67b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 11 deletions.
7 changes: 4 additions & 3 deletions test/migration-createAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions test/writeClient-createAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
6 changes: 5 additions & 1 deletion test/writeClient-createAssetTag.test.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 })

Expand Down
6 changes: 5 additions & 1 deletion test/writeClient-getAssets.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { expect, it } from "vitest"
import { it as _it, expect } from "vitest"

import { createTestWriteClient } from "./__testutils__/createWriteClient"
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 })

Expand Down
24 changes: 21 additions & 3 deletions test/writeClient-migrate.test.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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,
},
},
})
})
4 changes: 4 additions & 0 deletions test/writeClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})
Expand All @@ -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",
})
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 84ed67b

Please sign in to comment.