Skip to content

Commit

Permalink
test(vitest): add tests on exec args
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencaccia committed Oct 28, 2023
1 parent 444d7f2 commit ad41d3e
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions test/run/exec-args-fixtures/forks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, expect, it } from 'vitest'

describe('exec-args', async () => {
it('should have the correct flags', () => {
// passed via poolOptions.forks.execArgv in vitest.config.ts
expect(process.execArgv).toContain('--hash-seed=1')
expect(process.execArgv).toContain('--random-seed=1')
expect(process.execArgv).toContain('--no-opt')

// added via vitest
expect(process.execArgv).toContain('--conditions')
expect(process.execArgv).toContain('node')
})
})
12 changes: 12 additions & 0 deletions test/run/exec-args-fixtures/threads.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, expect, it } from 'vitest'

describe('exec-args', async () => {
it('should have the correct flags', () => {
// passed via poolOptions.forks.execArgv in vitest.config.ts
expect(process.execArgv).toContain('--inspect-brk')

// added via vitest
expect(process.execArgv).toContain('--conditions')
expect(process.execArgv).toContain('node')
})
})
16 changes: 16 additions & 0 deletions test/run/exec-args-fixtures/vmThreads.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from 'vitest'

describe('exec-args', async () => {
it('should have the correct flags', () => {
// passed via poolOptions.vmThreads.execArgv in vitest.config.ts
expect(process.execArgv).toContain('--inspect-brk')

// added via vitest
expect(process.execArgv).toContain('--experimental-import-meta-resolve')
expect(process.execArgv).toContain('--experimental-vm-modules')
expect(process.execArgv).toContain('--require')
expect(process.execArgv).toContainEqual(expect.stringContaining('/packages/vitest/suppress-warnings.cjs'))
expect(process.execArgv).toContain('--conditions')
expect(process.execArgv).toContain('node')
})
})
12 changes: 12 additions & 0 deletions test/run/no-exec-args-fixtures/no-exec-argv.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, expect, it } from 'vitest'

describe('exec-args', async () => {
it('should have the correct flags', () => {
// flags should not be passed
expect(process.execArgv).not.toContain('--inspect-brk')

// added via vitest
expect(process.execArgv).toContain('--conditions')
expect(process.execArgv).toContain('node')
})
})
7 changes: 7 additions & 0 deletions test/run/no-exec-args-fixtures/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
pool: 'threads',
},
})
1 change: 1 addition & 0 deletions test/run/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"test": "vitest"
},
"devDependencies": {
"execa": "^7.1.1",
"vite": "latest",
"vitest": "workspace:*"
}
Expand Down
30 changes: 30 additions & 0 deletions test/run/test/exec-args.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { expect, test } from 'vitest'
import { execa } from 'execa'
import { runVitest } from '../../test-utils'

test.each([
{ pool: 'forks', execArgv: ['--hash-seed=1', '--random-seed=1', '--no-opt'] },
{ pool: 'threads', execArgv: ['--inspect-brk'] },
{ pool: 'vmThreads', execArgv: ['--inspect-brk'] },
] as const)('should pass execArgv to { pool: $pool } ', async ({ pool, execArgv }) => {
const fileToTest = `exec-args-fixtures/${pool}.test.ts`

const vitest = await runVitest({
include: [fileToTest],
pool,
poolOptions: {
[pool]: {
execArgv,
},
},
})

expect(vitest.stdout).toContain(`✓ ${fileToTest}`)
})

test('should not pass execArgv to workers when not specified in the config', async () => {
const { stdout } = await execa('npx', ['vitest', '--run', '--root', 'no-exec-args-fixtures', '--config', 'vitest.config.ts'],
{ env: { NODE_OPTIONS: '--inspect-brk' } })

expect(stdout).toContain('✓ no-exec-argv.test.ts')
})

0 comments on commit ad41d3e

Please sign in to comment.