From bbf4ec1ea58e2de7f7feab8d00894663f30899bf Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sat, 7 Dec 2019 16:51:24 +0800 Subject: [PATCH] deps: cmd-shim v3 (#315) Work around quoted batch file names fixed https://github.com/npm/cmd-shim/issues/10 --- package.json | 2 +- test/bundleDependencies.test.js | 2 +- .../runscript-with-mocha/package.json | 6 ++++ test/runscript-with-mocha.test.js | 31 +++++++++++++++++ test/uninstallGlobal.test.js | 34 +++++++++++++------ 5 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 test/fixtures/runscript-with-mocha/package.json create mode 100644 test/runscript-with-mocha.test.js diff --git a/package.json b/package.json index 4c23e1bc..e3c7c354 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "binary-mirror-config": "^1.19.0", "bytes": "^3.1.0", "chalk": "^2.4.2", - "cmd-shim": "^2.0.2", + "cmd-shim": "^3.0.3", "debug": "^4.1.1", "destroy": "^1.0.4", "fs-extra": "^7.0.1", diff --git a/test/bundleDependencies.test.js b/test/bundleDependencies.test.js index 8d0cabc3..1d8fb359 100644 --- a/test/bundleDependencies.test.js +++ b/test/bundleDependencies.test.js @@ -52,7 +52,7 @@ describe('test/bundleDependencies.test.js', () => { }); const bins = await fs.readdir(path.join(tmp, 'node_modules/sqlite3/node_modules/.bin')); if (process.platform === 'win32') { - assert.deepEqual(bins, [ 'node-pre-gyp', 'node-pre-gyp.cmd' ]); + assert.deepEqual(bins, [ 'node-pre-gyp', 'node-pre-gyp.cmd', 'node-pre-gyp.ps1' ]); } else { assert.deepEqual(bins, [ 'node-pre-gyp' ]); } diff --git a/test/fixtures/runscript-with-mocha/package.json b/test/fixtures/runscript-with-mocha/package.json new file mode 100644 index 00000000..2b5606fe --- /dev/null +++ b/test/fixtures/runscript-with-mocha/package.json @@ -0,0 +1,6 @@ +{ + "name": "runscript-with-mocha", + "dependencies": { + "mocha": "3.5.3" + } +} diff --git a/test/runscript-with-mocha.test.js b/test/runscript-with-mocha.test.js new file mode 100644 index 00000000..71b76c6e --- /dev/null +++ b/test/runscript-with-mocha.test.js @@ -0,0 +1,31 @@ +'use strict'; + +const assert = require('assert'); +const path = require('path'); +const runScript = require('runscript'); +const readJSON = require('../lib/utils').readJSON; +const npminstall = require('./npminstall'); +const helper = require('./helper'); + +describe('test/runscript-with-mocha.test.js', () => { + const root = helper.fixtures('runscript-with-mocha'); + const cleanup = helper.cleanup(root); + + beforeEach(cleanup); + afterEach(cleanup); + + it('should runscript with mocha.cmd', async () => { + await npminstall({ + root, + }); + const pkg = await readJSON(path.join(root, 'node_modules', 'mocha', 'package.json')); + assert(pkg.name === 'mocha'); + + let mochaBin = path.join(root, 'node_modules', '.bin', 'mocha'); + if (process.platform === 'win32') { + mochaBin = `${mochaBin}.cmd`; + } + const stdio = await runScript(`${mochaBin} -V`, { stdio: 'pipe' }); + assert(stdio.stdout.toString().trim() === '3.5.3'); + }); +}); diff --git a/test/uninstallGlobal.test.js b/test/uninstallGlobal.test.js index 807968e6..fb51779e 100644 --- a/test/uninstallGlobal.test.js +++ b/test/uninstallGlobal.test.js @@ -20,16 +20,28 @@ describe('test/uninstallGlobal.test.js', () => { .expect('code', 0) .end(); - await coffee.fork(require.resolve('../bin/uninstall'), [ - `--prefix=${tmp}`, - '-g', - 'mocha', - ]) - .debug() - .expect('stdout', /- mocha@\d+\.\d+\.\d+ \.\/test\/fixtures\/tmp\/lib\/node_modules\/mocha/) - .expect('stdout', /- mocha@\d+\.\d+\.\d+ \.\/test\/fixtures\/tmp\/bin\/mocha/) - .expect('stdout', /- mocha@\d+\.\d+\.\d+ \.\/test\/fixtures\/tmp\/bin\/_mocha/) - .expect('code', 0) - .end(); + if (process.platform === 'win32') { + await coffee.fork(require.resolve('../bin/uninstall'), [ + `--prefix=${tmp}`, + '-g', + 'mocha', + ]) + .debug() + .expect('stdout', /- mocha@\d+\.\d+\.\d+/) + .expect('code', 0) + .end(); + } else { + await coffee.fork(require.resolve('../bin/uninstall'), [ + `--prefix=${tmp}`, + '-g', + 'mocha', + ]) + .debug() + .expect('stdout', /- mocha@\d+\.\d+\.\d+ \.[\/\\]test[\/\\]fixtures[\/\\]tmp[\/\\]lib[\/\\]node_modules[\/\\]mocha/) + .expect('stdout', /- mocha@\d+\.\d+\.\d+ \.[\/\\]test[\/\\]fixtures[\/\\]tmp[\/\\]bin[\/\\]mocha/) + .expect('stdout', /- mocha@\d+\.\d+\.\d+ \.[\/\\]test[\/\\]fixtures[\/\\]tmp[\/\\]bin[\/\\]_mocha/) + .expect('code', 0) + .end(); + } }); });