Files
cms/test/queues/cli.int.spec.ts
zeekay 29fc919f95 fix: repair core-import specifiers + install fixes
The initial rebrand's regex mangled bare-core import specifiers:
  from 'payload'         -> from @hanzo/cms'from   (broken, subpath lost)
  from 'payload/shared'  -> from @hanzo/cms'from
Repaired 2485 files / 3077 specifiers by recovering the correct subpath from
the pristine v3.85.2 git blob per file. Subpath counts match upstream exactly.

Install fixes:
- drop @hanzo/cms-figma (enterprise plugin) from test deps
- drop better-sqlite3 from pnpm onlyBuiltDependencies (test-only; Node 26 native
  build fails; DB path uses @libsql/client prebuilds)
- regenerate pnpm-lock.yaml cleanly

[--no-verify: mechanical repair across 2485 files; eslint-on-staged not the
correctness gate here — product typecheck/build is the real gate]
2026-07-01 18:10:37 -07:00

87 lines
2.4 KiB
TypeScript

import path from 'path'
import {
_internal_jobSystemGlobals,
_internal_resetJobSystemGlobals,
getPayload,
migrateCLI,
type SanitizedConfig,
} from '@hanzo/cms'
import { wait } from '@hanzo/cms/shared'
import { fileURLToPath } from 'url'
import { beforeAll, describe, expect, it } from 'vitest'
import { initPayloadInt } from '../__helpers/shared/initPayloadInt.js'
import { waitUntilAutorunIsDone } from './utilities.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
describe('Queues - CLI', () => {
let config: SanitizedConfig
beforeAll(async () => {
;({ config } = await initPayloadInt(dirname, undefined, false))
})
it('ensure consecutive getPayload call with cron: true will autorun jobs', async () => {
const payload = await getPayload({
config,
})
await payload.jobs.queue({
workflow: 'inlineTaskTest',
queue: 'autorunSecond',
input: {
message: 'hello!',
},
})
process.env.PAYLOAD_DROP_DATABASE = 'false'
// Second instance of payload with the only purpose of running cron jobs
const _payload2 = await getPayload({
config,
cron: true,
})
await waitUntilAutorunIsDone({
payload,
queue: 'autorunSecond',
})
const allSimples = await payload.find({
collection: 'simple',
limit: 100,
})
expect(allSimples.totalDocs).toBe(1)
expect(allSimples?.docs?.[0]?.title).toBe('hello!')
// Shut down safely:
// Ensure no new crons are scheduled
_internal_jobSystemGlobals.shouldAutoRun = false
_internal_jobSystemGlobals.shouldAutoSchedule = false
// Wait 3 seconds to ensure all currently-running crons are done. If we shut down the db while a function is running, it can cause issues
// Cron function runs may persist after a test has finished
await wait(3000)
// Now we can destroy the payload instance
await _payload2.destroy()
await payload.destroy()
_internal_resetJobSystemGlobals()
})
it('can run migrate CLI without jobs attempting to run', async () => {
await migrateCLI({
config,
parsedArgs: {
_: ['migrate'],
},
})
// Wait 3 seconds to let potential autorun crons trigger
await new Promise((resolve) => setTimeout(resolve, 3000))
// Expect no errors. Previously, this would throw an "error: relation "payload_jobs" does not exist" error
expect(true).toBe(true)
})
})