run-oxlint.spec.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { describe, expect, it } from 'vitest'
  2. import { resolveOxlintInvocation } from './run-oxlint.ts'
  3. describe('Oxlint invocation', () => {
  4. it('preserves the ordinary default invocation', () => {
  5. expect(resolveOxlintInvocation(['.'], { PATH: '/bin' })).toEqual({
  6. args: ['.'],
  7. env: { PATH: '/bin' },
  8. })
  9. })
  10. it('bounds both worker pools from one setting', () => {
  11. expect(resolveOxlintInvocation(['.', '--fix'], { DSH_OXLINT_THREADS: '4', GOMAXPROCS: '12' })).toEqual({
  12. args: ['.', '--fix', '--threads=4'],
  13. env: { DSH_OXLINT_THREADS: '4', GOMAXPROCS: '4' },
  14. })
  15. })
  16. it('uses location-preserving diagnostics in CI', () => {
  17. expect(resolveOxlintInvocation(['.'], { CI: 'true', DSH_OXLINT_THREADS: '4' })).toEqual({
  18. args: ['.', '--format=default', '--threads=4'],
  19. env: { CI: 'true', DSH_OXLINT_THREADS: '4', GOMAXPROCS: '4' },
  20. })
  21. })
  22. it('preserves an explicitly selected CI formatter', () => {
  23. expect(resolveOxlintInvocation(['.', '--format', 'github'], { CI: 'true' }).args)
  24. .toEqual(['.', '--format', 'github'])
  25. })
  26. it.each(['0', '-1', '1.5', 'auto'])('rejects invalid worker bound %s', (value) => {
  27. expect(() => resolveOxlintInvocation(['.'], { DSH_OXLINT_THREADS: value }))
  28. .toThrow('DSH_OXLINT_THREADS must be a positive integer')
  29. })
  30. it('rejects a competing direct worker bound', () => {
  31. expect(() => resolveOxlintInvocation(['.', '--threads=2'], { DSH_OXLINT_THREADS: '4' }))
  32. .toThrow('use DSH_OXLINT_THREADS instead')
  33. })
  34. })