Skip to content

Commit

Permalink
test: use fs.execFile instead of exec (#2110)
Browse files Browse the repository at this point in the history
* test: use fs.execFile instead of exec

Generally safer than building a shell script, and allows to run the
tests from a directory with spaces in it.

* fix windows

* use shell
  • Loading branch information
targos authored Dec 23, 2024
1 parent bb1f89d commit abd6621
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions test/pkg/pkg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { promisify } = require('node:util')
const { unlink } = require('node:fs/promises')
const { join } = require('node:path')
const { platform } = require('node:process')
const exec = promisify(require('node:child_process').exec)
const execFile = promisify(require('node:child_process').execFile)

/**
* The following regex is for tesintg the deprecation warning that is thrown by the `punycode` module.
Expand All @@ -24,7 +24,7 @@ test('worker test when packaged into executable using pkg', { skip: !!process.en
// package the app into several node versions, check config for more info
const filePath = `${join(__dirname, packageName)}.js`
const configPath = join(__dirname, 'pkg.config.json')
const { stderr } = await exec(`npx pkg ${filePath} --config ${configPath}`)
const { stderr } = await execFile('npx', ['pkg', filePath, '--config', configPath], { shell: true })

// there should be no error when packaging
const expectedvalue = stderr === '' || deprecationWarningRegex.test(stderr)
Expand All @@ -42,7 +42,7 @@ test('worker test when packaged into executable using pkg', { skip: !!process.en
executablePath = `./${executablePath}`
}

const { stderr } = await exec(executablePath)
const { stderr } = await execFile(executablePath)

// check if there were no errors
const expectedvalue = stderr === '' || deprecationWarningRegex.test(stderr)
Expand Down

0 comments on commit abd6621

Please sign in to comment.