Skip to content

Commit

Permalink
test: use tinyexec for execArgv tests (#7151)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio authored Dec 30, 2024
1 parent caede68 commit d243c78
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"pathe": "^1.1.2",
"std-env": "^3.8.0",
"tinybench": "^2.9.0",
"tinyexec": "^0.3.1",
"tinyexec": "^0.3.2",
"tinypool": "^1.0.2",
"tinyrainbow": "^1.2.0",
"vite": "^5.0.0 || ^6.0.0",
Expand Down
29 changes: 12 additions & 17 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion test/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"test": "vitest --typecheck.enabled"
},
"devDependencies": {
"tinyexec": "^0.3.0",
"tinyexec": "^0.3.2",
"vite": "latest",
"vitest": "workspace:*"
}
Expand Down
32 changes: 17 additions & 15 deletions test/config/test/exec-args.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawnSync } from 'node:child_process'
import { x } from 'tinyexec'
import { expect, test } from 'vitest'
import { runVitest } from '../../test-utils'

Expand Down Expand Up @@ -35,19 +35,20 @@ test.each([
})

test('should not pass execArgv to workers when not specified in the config', async () => {
const { stdout, stderr } = spawnSync('node', [
const { stdout, stderr } = await x('node', [
'--title',
'this-works-only-on-main-thread',
'../../../../node_modules/vitest/vitest.mjs',
'--run',
], {
encoding: 'utf-8',
cwd: `${process.cwd()}/fixtures/no-exec-args-fixtures`,
env: {
...process.env,
VITE_NODE_DEPS_MODULE_DIRECTORIES: '/node_modules/,/packages/',
NO_COLOR: '1',
nodeOptions: {
cwd: `${process.cwd()}/fixtures/no-exec-args-fixtures`,
env: {
VITE_NODE_DEPS_MODULE_DIRECTORIES: '/node_modules/,/packages/',
NO_COLOR: '1',
},
},
throwOnError: false,
})

expect(stderr).not.toContain('Error: Initiated Worker with invalid execArgv flags: --title')
Expand All @@ -56,20 +57,21 @@ test('should not pass execArgv to workers when not specified in the config', asy
})

test('should let allowed args pass to workers', async () => {
const { stdout, stderr } = spawnSync('node', [
const { stdout, stderr } = await x('node', [
'--heap-prof',
'--diagnostic-dir=/tmp/vitest-diagnostics',
'--heap-prof-name=heap.prof',
'../../../../node_modules/vitest/vitest.mjs',
'--run',
], {
encoding: 'utf-8',
cwd: `${process.cwd()}/fixtures/allowed-exec-args-fixtures`,
env: {
...process.env,
VITE_NODE_DEPS_MODULE_DIRECTORIES: '/node_modules/,/packages/',
NO_COLOR: '1',
nodeOptions: {
cwd: `${process.cwd()}/fixtures/allowed-exec-args-fixtures`,
env: {
VITE_NODE_DEPS_MODULE_DIRECTORIES: '/node_modules/,/packages/',
NO_COLOR: '1',
},
},
throwOnError: false,
})

expect(stderr).toBe('')
Expand Down
2 changes: 1 addition & 1 deletion test/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "echo \"No tests\""
},
"devDependencies": {
"tinyexec": "^0.3.0",
"tinyexec": "^0.3.2",
"tinyrainbow": "^1.2.0",
"vite": "latest",
"vite-node": "workspace:*",
Expand Down

0 comments on commit d243c78

Please sign in to comment.