-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vitest): expose execArgv to the different pools (#4383)
- Loading branch information
1 parent
0db386d
commit 9021e8b
Showing
16 changed files
with
215 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
test/run/allowed-exec-args-fixtures/allowed-exec-argv.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', () => { | ||
// flags that should go through | ||
expect(process.execArgv).toContain('--cpu-prof') | ||
expect(process.execArgv).toContain('--cpu-prof-name=cpu.prof') | ||
expect(process.execArgv).toContain('--heap-prof') | ||
expect(process.execArgv).toContain('--heap-prof-name=heap.prof') | ||
expect(process.execArgv).toContain('--diagnostic-dir=/tmp/vitest-diagnostics') | ||
|
||
// added via vitest | ||
expect(process.execArgv).toContain('--conditions') | ||
expect(process.execArgv).toContain('node') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
describe('exec-args', async () => { | ||
it('should have the correct flags', () => { | ||
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
describe('exec-args', async () => { | ||
it('should have the correct flags', () => { | ||
expect(process.execArgv).toContain('--inspect-brk') | ||
|
||
// added via vitest | ||
expect(process.execArgv).toContain('--conditions') | ||
expect(process.execArgv).toContain('node') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
describe('exec-args', async () => { | ||
it('should have the correct flags', () => { | ||
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('--title') | ||
|
||
// added via vitest | ||
expect(process.execArgv).toContain('--conditions') | ||
expect(process.execArgv).toContain('node') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { afterAll, beforeAll, expect, test } from 'vitest' | ||
import { execa } from 'execa' | ||
import { runVitest } from '../../test-utils' | ||
|
||
// VITEST_SEGFAULT_RETRY messes with the node flags, as can be seen in packages/vitest/src/node/cli-wrapper.ts | ||
// so here we remove it to make sure the tests are not affected by it | ||
const ORIGIN_VITEST_SEGFAULT_RETRY = process.env.VITEST_SEGFAULT_RETRY | ||
beforeAll(() => { | ||
delete process.env.VITEST_SEGFAULT_RETRY | ||
}) | ||
afterAll(() => { | ||
process.env.VITEST_SEGFAULT_RETRY = ORIGIN_VITEST_SEGFAULT_RETRY | ||
}) | ||
|
||
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, stderr } = await execa('node', [ | ||
'--title', 'this-works-only-on-main-thread', | ||
'../node_modules/vitest/vitest.mjs', '--run', | ||
], { | ||
cwd: `${process.cwd()}/no-exec-args-fixtures`, | ||
reject: false, | ||
env: { | ||
VITE_NODE_DEPS_MODULE_DIRECTORIES: '/node_modules/,/packages/', | ||
NO_COLOR: '1', | ||
}, | ||
}) | ||
|
||
expect(stderr).not.toContain('Error: Initiated Worker with invalid execArgv flags: --title') | ||
expect(stderr).not.toContain('ERR_WORKER_INVALID_EXEC_ARGV') | ||
expect(stdout).toContain('✓ no-exec-argv.test.ts') | ||
}) | ||
|
||
test('should let allowed args pass to workers', async () => { | ||
const { stdout, stderr } = await execa('node', [ | ||
'--cpu-prof', '--heap-prof', '--diagnostic-dir=/tmp/vitest-diagnostics', | ||
'--cpu-prof-name=cpu.prof', '--heap-prof-name=heap.prof', | ||
'../node_modules/vitest/vitest.mjs', '--run', | ||
], { | ||
cwd: `${process.cwd()}/allowed-exec-args-fixtures`, | ||
reject: false, | ||
env: { | ||
VITE_NODE_DEPS_MODULE_DIRECTORIES: '/node_modules/,/packages/', | ||
NO_COLOR: '1', | ||
}, | ||
}) | ||
|
||
expect(stderr).toBe('') | ||
expect(stdout).toContain('✓ allowed-exec-argv.test.ts') | ||
}) |