Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix: create-spree-app package manager tests no longer time out on busy CI runners (#14829)

Damian Legawiec7a2f5deb19a5
diff --git a/packages/admin-sdk/tests/zod-schemas.test.ts b/packages/admin-sdk/tests/zod-schemas.test.ts
index 4f9dc4aed1..095862e152 100644
--- a/packages/admin-sdk/tests/zod-schemas.test.ts
+++ b/packages/admin-sdk/tests/zod-schemas.test.ts
@@ -2,11 +2,19 @@ import { describe, expect, it } from 'vitest'
import { rejectedExamples } from '../../sdk-core/scripts/openapi-examples'
import * as schemas from '../src/zod'
+// Parses the whole API reference, which a busy CI runner can take well over
+// the default five seconds to do.
+const TIMEOUT = 30_000
+
describe('generated Zod schemas', () => {
- it('accept every response recorded in the Admin API reference', () => {
- const { checked, rejections } = rejectedExamples('admin', schemas)
+ it(
+ 'accept every response recorded in the Admin API reference',
+ () => {
+ const { checked, rejections } = rejectedExamples('admin', schemas)
- expect(checked).toBeGreaterThan(0)
- expect(rejections).toEqual([])
- })
+ expect(checked).toBeGreaterThan(0)
+ expect(rejections).toEqual([])
+ },
+ TIMEOUT,
+ )
})
diff --git a/packages/create-spree-app/tests/utils.test.ts b/packages/create-spree-app/tests/utils.test.ts
index fd382db5bd..526eee6850 100644
--- a/packages/create-spree-app/tests/utils.test.ts
+++ b/packages/create-spree-app/tests/utils.test.ts
@@ -1,4 +1,5 @@
-import { beforeEach, describe, expect, it } from 'vitest'
+import { execa } from 'execa'
+import { beforeEach, describe, expect, it, vi } from 'vitest'
import {
detectPackageManager,
generateEncryptionKeys,
@@ -8,11 +9,17 @@ import {
storefrontPm,
} from '../src/utils'
+vi.mock('execa', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('execa')>()),
+ execa: vi.fn(),
+}))
+
describe('detectPackageManager', () => {
const originalEnv = process.env.npm_config_user_agent
beforeEach(() => {
process.env.npm_config_user_agent = originalEnv
+ vi.mocked(execa).mockReset()
})
it('respects an explicit yarn agent', async () => {
@@ -26,17 +33,23 @@ describe('detectPackageManager', () => {
})
// An npm agent is the default runner (`npx create-spree-app`), not a
- // choice — prefer pnpm when installed. These tests run under the pnpm
- // workspace, so pnpm is always on PATH here.
+ // choice — prefer pnpm when installed.
it('prefers pnpm over an npm agent when pnpm is installed', async () => {
process.env.npm_config_user_agent = 'npm/10.0.0 node/v20.0.0'
await expect(detectPackageManager()).resolves.toBe('pnpm')
+ expect(execa).toHaveBeenCalledWith('pnpm', ['--version'], { stdio: 'ignore' })
})
it('prefers pnpm when the agent is unknown', async () => {
delete process.env.npm_config_user_agent
await expect(detectPackageManager()).resolves.toBe('pnpm')
})
+
+ it('falls back to npm when pnpm is not installed', async () => {
+ process.env.npm_config_user_agent = 'npm/10.0.0 node/v20.0.0'
+ vi.mocked(execa).mockRejectedValue(new Error('spawn pnpm ENOENT'))
+ await expect(detectPackageManager()).resolves.toBe('npm')
+ })
})
describe('generateSecretKeyBase', () => {
diff --git a/packages/sdk/tests/zod-schemas.test.ts b/packages/sdk/tests/zod-schemas.test.ts
index 0534639396..bbaf3f3e91 100644
--- a/packages/sdk/tests/zod-schemas.test.ts
+++ b/packages/sdk/tests/zod-schemas.test.ts
@@ -2,11 +2,19 @@ import { describe, expect, it } from 'vitest'
import { rejectedExamples } from '../../sdk-core/scripts/openapi-examples'
import * as schemas from '../src/zod'
+// Parses the whole API reference, which a busy CI runner can take well over
+// the default five seconds to do.
+const TIMEOUT = 30_000
+
describe('generated Zod schemas', () => {
- it('accept every response recorded in the Store API reference', () => {
- const { checked, rejections } = rejectedExamples('store', schemas)
+ it(
+ 'accept every response recorded in the Store API reference',
+ () => {
+ const { checked, rejections } = rejectedExamples('store', schemas)
- expect(checked).toBeGreaterThan(0)
- expect(rejections).toEqual([])
- })
+ expect(checked).toBeGreaterThan(0)
+ expect(rejections).toEqual([])
+ },
+ TIMEOUT,
+ )
})
diff --git a/packages/seller-sdk/tests/zod-schemas.test.ts b/packages/seller-sdk/tests/zod-schemas.test.ts
index d2d5364a91..3f854e3eb0 100644
--- a/packages/seller-sdk/tests/zod-schemas.test.ts
+++ b/packages/seller-sdk/tests/zod-schemas.test.ts
@@ -2,11 +2,19 @@ import { describe, expect, it } from 'vitest'
import { rejectedExamples } from '../../sdk-core/scripts/openapi-examples'
import * as schemas from '../src/zod'
+// Parses the whole API reference, which a busy CI runner can take well over
+// the default five seconds to do.
+const TIMEOUT = 30_000
+
describe('generated Zod schemas', () => {
- it('accept every response recorded in the Seller API reference', () => {
- const { checked, rejections } = rejectedExamples('seller', schemas)
+ it(
+ 'accept every response recorded in the Seller API reference',
+ () => {
+ const { checked, rejections } = rejectedExamples('seller', schemas)
- expect(checked).toBeGreaterThan(0)
- expect(rejections).toEqual([])
- })
+ expect(checked).toBeGreaterThan(0)
+ expect(rejections).toEqual([])
+ },
+ TIMEOUT,
+ )
})