From bd589500b277e48ec04449bcc6c2dd64e30f08a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Mon, 23 Dec 2024 09:03:03 +0100 Subject: [PATCH 1/3] 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. --- test/pkg/pkg.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/pkg/pkg.test.js b/test/pkg/pkg.test.js index bf2643ae3..f20669543 100644 --- a/test/pkg/pkg.test.js +++ b/test/pkg/pkg.test.js @@ -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. @@ -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]) // there should be no error when packaging const expectedvalue = stderr === '' || deprecationWarningRegex.test(stderr) @@ -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) From 41eb6733b0adaf056d68ffb01f29c50ade56f5ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Mon, 23 Dec 2024 10:06:31 +0100 Subject: [PATCH 2/3] fix windows --- test/pkg/pkg.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/pkg/pkg.test.js b/test/pkg/pkg.test.js index f20669543..1348b2d7f 100644 --- a/test/pkg/pkg.test.js +++ b/test/pkg/pkg.test.js @@ -24,7 +24,8 @@ 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 execFile('npx', ['pkg', filePath, '--config', configPath]) + const npxExecutable = platform === 'win32' ? 'npx.cmd' : 'npx' + const { stderr } = await execFile(npxExecutable, ['pkg', filePath, '--config', configPath]) // there should be no error when packaging const expectedvalue = stderr === '' || deprecationWarningRegex.test(stderr) From babfbf771cdbdb886a54d9937a99d3cef71544a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Mon, 23 Dec 2024 10:40:58 +0100 Subject: [PATCH 3/3] use shell --- test/pkg/pkg.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/pkg/pkg.test.js b/test/pkg/pkg.test.js index 1348b2d7f..a74b03303 100644 --- a/test/pkg/pkg.test.js +++ b/test/pkg/pkg.test.js @@ -24,8 +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 npxExecutable = platform === 'win32' ? 'npx.cmd' : 'npx' - const { stderr } = await execFile(npxExecutable, ['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)