pnpm-invocation.spec.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import { describe, expect, it } from 'vitest'
  2. import { pnpmInvocation } from './pnpm-invocation.ts'
  3. describe('pnpm invocation', () => {
  4. it.each([
  5. '/tools/pnpm.js',
  6. '/tools/pnpm.cjs',
  7. '/tools/pnpm.mjs',
  8. '/tools/PNPM.CJS',
  9. '/tools/with spaces/工具/$pnpm;.mjs',
  10. ])('runs the JavaScript entrypoint %j through Node', (entrypoint) => {
  11. expect(pnpmInvocation(['run', 'build'], { npm_execpath: entrypoint })).toEqual({
  12. command: process.execPath,
  13. args: [entrypoint, 'run', 'build'],
  14. })
  15. })
  16. it.each([
  17. '/tools/pnpm',
  18. '/tools/with spaces/$pnpm;',
  19. String.raw`C:\Program Files\工具\$pnpm;\pnpm.exe`,
  20. ])('runs the executable entrypoint %j directly', (entrypoint) => {
  21. expect(pnpmInvocation(['run', 'build'], { npm_execpath: entrypoint })).toEqual({
  22. command: entrypoint,
  23. args: ['run', 'build'],
  24. })
  25. })
  26. it.each([undefined, ''])('rejects an unavailable lifecycle entrypoint', (entrypoint) => {
  27. expect(() => pnpmInvocation([], { npm_execpath: entrypoint }))
  28. .toThrow('npm_execpath is unavailable; invoke the script through pnpm run')
  29. })
  30. })