Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/danielroe/uppt. A composite GitHub Action that turns conventional commits into a draft release PR, tags the PR on merge, and stages publishing to npm via OIDC trusted publishing.
github-action npm npmjs oidc staged-publish trusted-publishing
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import process from 'node:process'import { afterEach, describe, expect, it, vi } from 'vitest'import { runMain } from '../scripts/_cli.ts'
const entry = `file://${process.argv[1]}`
afterEach(() => { vi.restoreAllMocks()})
describe('runMain', () => { it('does nothing when the module is not the entrypoint', () => { const main = vi.fn() runMain('file:///somewhere/else.ts', main) expect(main).not.toHaveBeenCalled() })
it('runs main when the module is the entrypoint', () => { const main = vi.fn() runMain(entry, main) expect(main).toHaveBeenCalled() })
it('exits non-zero when main throws', () => { const error = vi.spyOn(console, 'error').mockImplementation(() => {}) const exit = vi.spyOn(process, 'exit').mockImplementation(() => undefined as never) runMain(entry, () => { throw new Error('boom') }) expect(error).toHaveBeenCalled() expect(exit).toHaveBeenCalledWith(1) })
it('exits non-zero when an async main rejects', async () => { const error = vi.spyOn(console, 'error').mockImplementation(() => {}) const exit = vi.spyOn(process, 'exit').mockImplementation(() => undefined as never) runMain(entry, async () => { throw new Error('boom') }) await new Promise(r => setTimeout(r, 0)) expect(error).toHaveBeenCalled() expect(exit).toHaveBeenCalledWith(1) })
it('leaves a resolving async main alone', async () => { const exit = vi.spyOn(process, 'exit').mockImplementation(() => undefined as never) runMain(entry, async () => 'ok') await new Promise(r => setTimeout(r, 0)) expect(exit).not.toHaveBeenCalled() })})