diff options
Diffstat (limited to 'node_modules/spawn-wrap/test')
-rw-r--r-- | node_modules/spawn-wrap/test/abs-shebang.js | 68 | ||||
-rw-r--r-- | node_modules/spawn-wrap/test/basic.js | 419 | ||||
-rw-r--r-- | node_modules/spawn-wrap/test/fixtures/node_modules/npm/bin/npm-cli.js | 4 | ||||
-rwxr-xr-x | node_modules/spawn-wrap/test/fixtures/npm | 5 | ||||
-rw-r--r-- | node_modules/spawn-wrap/test/fixtures/npm.cmd | 2 | ||||
-rwxr-xr-x | node_modules/spawn-wrap/test/fixtures/script.js | 6 | ||||
-rw-r--r-- | node_modules/spawn-wrap/test/fixtures/test-shim.js | 3 | ||||
-rw-r--r-- | node_modules/spawn-wrap/test/fixtures/wrap.js | 27 | ||||
-rw-r--r-- | node_modules/spawn-wrap/test/win-rebase.js | 40 |
9 files changed, 0 insertions, 574 deletions
diff --git a/node_modules/spawn-wrap/test/abs-shebang.js b/node_modules/spawn-wrap/test/abs-shebang.js deleted file mode 100644 index f254683df..000000000 --- a/node_modules/spawn-wrap/test/abs-shebang.js +++ /dev/null @@ -1,68 +0,0 @@ -var path = require('path') -var fs = require('fs') -var spawn = require('child_process').spawn -var t = require('tap') -var node = process.execPath -var wrap = require.resolve('./fixtures/wrap.js') -var rimraf = require('rimraf') -var mkdirp = require('mkdirp') -var fs = require('fs') - -if (process.platform === 'win32') { - t.plan(0, 'No proper shebang support on windows, so skip this') - process.exit(0) -} - -var expect = - 'before in shim\n' + - 'shebang main foo,bar\n' + - 'after in shim\n' + - 'before in shim\n' + - 'shebang main foo,bar\n' + - 'after in shim\n' - -var fixdir = path.resolve(__dirname, 'fixtures', 'shebangs') - -t.test('setup', function (t) { - rimraf.sync(fixdir) - mkdirp.sync(fixdir) - t.end() -}) - -t.test('absolute', function (t) { - var file = path.resolve(fixdir, 'absolute.js') - runTest(file, process.execPath, t) -}) - -t.test('env', function (t) { - var file = path.resolve(fixdir, 'env.js') - runTest(file, '/usr/bin/env node', t) -}) - -function runTest (file, shebang, t) { - var content = '#!' + shebang + '\n' + - 'console.log("shebang main " + process.argv.slice(2))\n' - fs.writeFileSync(file, content, 'utf8') - fs.chmodSync(file, '0755') - var child = spawn(node, [wrap, file, 'foo', 'bar']) - var out = '' - var err = '' - child.stdout.on('data', function (c) { - out += c - }) - child.stderr.on('data', function (c) { - err += c - }) - child.on('close', function (code, signal) { - t.equal(code, 0) - t.equal(signal, null) - t.equal(out, expect) - // console.error(err) - t.end() - }) -} - -t.test('cleanup', function (t) { - rimraf.sync(fixdir) - t.end() -}) diff --git a/node_modules/spawn-wrap/test/basic.js b/node_modules/spawn-wrap/test/basic.js deleted file mode 100644 index 969310088..000000000 --- a/node_modules/spawn-wrap/test/basic.js +++ /dev/null @@ -1,419 +0,0 @@ -var sw = require('../') -var isWindows = require('../lib/is-windows.js')() -var winNoShebang = isWindows && 'no shebang execution on windows' -var winNoSig = isWindows && 'no signals get through cmd' - -var onExit = require('signal-exit') -var cp = require('child_process') -var fixture = require.resolve('./fixtures/script.js') -var npmFixture = require.resolve('./fixtures/npm') -var fs = require('fs') -var path = require('path') - -if (process.argv[2] === 'parent') { - // hang up once - process.once('SIGHUP', function onHup () { - console.log('SIGHUP') - }) - // handle sigints forever - process.on('SIGINT', function onInt () { - console.log('SIGINT') - }) - onExit(function (code, signal) { - console.log('EXIT %j', [code, signal]) - }) - var argv = process.argv.slice(3).map(function (arg) { - if (arg === fixture) { - return '{{FIXTURE}}' - } - return arg - }) - console.log('WRAP %j', process.execArgv.concat(argv)) - sw.runMain() - return -} - -var t = require('tap') -var unwrap = sw([__filename, 'parent']) - -var expect = 'WRAP ["{{FIXTURE}}","xyz"]\n' + - '[]\n' + - '["xyz"]\n' + - 'EXIT [0,null]\n' - -// dummy for node v0.10 -if (!cp.spawnSync) { - cp.spawnSync = function () { - return { - status: 0, - signal: null, - stdout: expect - } - } -} - -t.test('spawn execPath', function (t) { - t.plan(4) - - t.test('basic', function (t) { - var child = cp.spawn(process.execPath, [fixture, 'xyz']) - - var out = '' - child.stdout.on('data', function (c) { - out += c - }) - child.on('close', function (code, signal) { - t.equal(code, 0) - t.equal(signal, null) - t.equal(out, expect) - t.end() - }) - }) - - t.test('basic sync', function (t) { - var child = cp.spawnSync(process.execPath, [fixture, 'xyz']) - - t.equal(child.status, 0) - t.equal(child.signal, null) - t.equal(child.stdout.toString(), expect) - t.end() - }) - - t.test('SIGINT', { skip: winNoSig }, function (t) { - var child = cp.spawn(process.execPath, [fixture, 'xyz']) - - var out = '' - child.stdout.on('data', function (c) { - out += c - }) - child.stdout.once('data', function () { - child.kill('SIGINT') - }) - child.stderr.on('data', function (t) { - console.error(t) - }) - child.on('close', function (code, signal) { - t.equal(code, 0) - t.equal(signal, null) - t.equal(out, 'WRAP ["{{FIXTURE}}","xyz"]\n' + - '[]\n' + - '["xyz"]\n' + - 'SIGINT\n' + - 'EXIT [0,null]\n') - t.end() - }) - }) - - t.test('SIGHUP', { skip: winNoSig }, function (t) { - var child = cp.spawn(process.execPath, [fixture, 'xyz']) - - var out = '' - child.stdout.on('data', function (c) { - out += c - child.kill('SIGHUP') - }) - child.on('close', function (code, signal) { - t.equal(signal, 'SIGHUP') - t.equal(out, 'WRAP ["{{FIXTURE}}","xyz"]\n' + - '[]\n' + - '["xyz"]\n' + - 'SIGHUP\n' + - 'EXIT [null,"SIGHUP"]\n') - t.end() - }) - }) -}) - -t.test('spawn node', function (t) { - t.plan(4) - - t.test('basic', function (t) { - var child = cp.spawn('node', [fixture, 'xyz']) - - var out = '' - child.stdout.on('data', function (c) { - out += c - }) - child.on('close', function (code, signal) { - t.equal(code, 0) - t.equal(signal, null) - t.equal(out, expect) - t.end() - }) - }) - - t.test('basic sync', function (t) { - var child = cp.spawnSync('node', [fixture, 'xyz']) - - t.equal(child.status, 0) - t.equal(child.signal, null) - t.equal(child.stdout.toString(), expect) - t.end() - }) - - t.test('SIGINT', { skip: winNoSig }, function (t) { - var child = cp.spawn('node', [fixture, 'xyz']) - - var out = '' - child.stdout.on('data', function (c) { - out += c - }) - child.stdout.once('data', function () { - child.kill('SIGINT') - }) - child.stderr.on('data', function (t) { - console.error(t) - }) - child.on('close', function (code, signal) { - t.equal(code, 0) - t.equal(signal, null) - t.equal(out, 'WRAP ["{{FIXTURE}}","xyz"]\n' + - '[]\n' + - '["xyz"]\n' + - 'SIGINT\n' + - 'EXIT [0,null]\n') - t.end() - }) - }) - - t.test('SIGHUP', { skip: winNoSig }, function (t) { - var child = cp.spawn('node', [fixture, 'xyz']) - - var out = '' - child.stdout.on('data', function (c) { - out += c - child.kill('SIGHUP') - }) - child.on('close', function (code, signal) { - t.equal(signal, 'SIGHUP') - t.equal(out, 'WRAP ["{{FIXTURE}}","xyz"]\n' + - '[]\n' + - '["xyz"]\n' + - 'SIGHUP\n' + - 'EXIT [null,"SIGHUP"]\n') - t.end() - }) - }) -}) - -t.test('exec execPath', function (t) { - t.plan(4) - - t.test('basic', function (t) { - var opt = isWindows ? null : { shell: '/bin/bash' } - var child = cp.exec(process.execPath + ' ' + fixture + ' xyz', opt) - - var out = '' - child.stdout.on('data', function (c) { - out += c - }) - child.on('close', function (code, signal) { - t.equal(code, 0) - t.equal(signal, null) - t.equal(out, expect) - t.end() - }) - }) - - t.test('execPath wrapped with quotes', function (t) { - var opt = isWindows ? null : { shell: '/bin/bash' } - var child = cp.exec(JSON.stringify(process.execPath) + ' ' + fixture + - ' xyz', opt) - - var out = '' - child.stdout.on('data', function (c) { - out += c - }) - child.on('close', function (code, signal) { - t.equal(code, 0) - t.equal(signal, null) - t.equal(out, expect) - t.end() - }) - }) - - t.test('SIGINT', { skip: winNoSig }, function (t) { - var child = cp.exec(process.execPath + ' ' + fixture + ' xyz', { shell: '/bin/bash' }) - - var out = '' - child.stdout.on('data', function (c) { - out += c - }) - child.stdout.once('data', function () { - child.kill('SIGINT') - }) - child.stderr.on('data', function (t) { - console.error(t) - }) - child.on('close', function (code, signal) { - t.equal(code, 0) - t.equal(signal, null) - t.equal(out, 'WRAP ["{{FIXTURE}}","xyz"]\n' + - '[]\n' + - '["xyz"]\n' + - 'SIGINT\n' + - 'EXIT [0,null]\n') - t.end() - }) - }) - - t.test('SIGHUP', { skip: winNoSig }, function (t) { - var child = cp.exec(process.execPath + ' ' + fixture + ' xyz', { shell: '/bin/bash' }) - - var out = '' - child.stdout.on('data', function (c) { - out += c - child.kill('SIGHUP') - }) - child.on('close', function (code, signal) { - t.equal(signal, 'SIGHUP') - t.equal(out, 'WRAP ["{{FIXTURE}}","xyz"]\n' + - '[]\n' + - '["xyz"]\n' + - 'SIGHUP\n' + - 'EXIT [null,"SIGHUP"]\n') - t.end() - }) - }) -}) - -t.test('exec shebang', { skip: winNoShebang }, function (t) { - t.plan(3) - - t.test('basic', function (t) { - var child = cp.exec(fixture + ' xyz', { shell: '/bin/bash' }) - - var out = '' - child.stdout.on('data', function (c) { - out += c - }) - child.on('close', function (code, signal) { - t.equal(code, 0) - t.equal(signal, null) - t.equal(out, expect) - t.end() - }) - }) - - t.test('SIGHUP', function (t) { - var child = cp.exec(fixture + ' xyz', { shell: '/bin/bash' }) - - var out = '' - child.stdout.on('data', function (c) { - out += c - child.kill('SIGHUP') - }) - child.on('close', function (code, signal) { - t.equal(signal, 'SIGHUP') - t.equal(out, 'WRAP ["{{FIXTURE}}","xyz"]\n' + - '[]\n' + - '["xyz"]\n' + - 'SIGHUP\n' + - 'EXIT [null,"SIGHUP"]\n') - t.end() - }) - }) - - t.test('SIGINT', function (t) { - var child = cp.exec(fixture + ' xyz', { shell: '/bin/bash' }) - - var out = '' - child.stdout.on('data', function (c) { - out += c - }) - child.stdout.once('data', function () { - child.kill('SIGINT') - }) - child.stderr.on('data', function (t) { - console.error(t) - }) - child.on('close', function (code, signal) { - t.equal(code, 0) - t.equal(signal, null) - t.equal(out, 'WRAP ["{{FIXTURE}}","xyz"]\n' + - '[]\n' + - '["xyz"]\n' + - 'SIGINT\n' + - 'EXIT [0,null]\n') - t.end() - }) - }) -}) - -// see: https://github.com/bcoe/nyc/issues/190 -t.test('Node 5.8.x + npm 3.7.x - spawn', { skip: winNoShebang }, function (t) { - var npmdir = path.dirname(npmFixture) - process.env.PATH = npmdir + ':' + (process.env.PATH || '') - var child = cp.spawn('npm', ['xyz']) - - var out = '' - child.stdout.on('data', function (c) { - out += c - }) - child.on('close', function (code, signal) { - t.equal(code, 0) - t.equal(signal, null) - t.true(~out.indexOf('xyz')) - t.end() - }) -}) - -t.test('Node 5.8.x + npm 3.7.x - shell', { skip: winNoShebang }, function (t) { - var npmdir = path.dirname(npmFixture) - process.env.PATH = npmdir + ':' + (process.env.PATH || '') - var child = cp.exec('npm xyz') - - var out = '' - child.stdout.on('data', function (c) { - out += c - }) - child.on('close', function (code, signal) { - t.equal(code, 0) - t.equal(signal, null) - t.true(~out.indexOf('xyz')) - t.end() - }) -}) - -t.test('--harmony', function (t) { - var node = process.execPath - var child = cp.spawn(node, ['--harmony', fixture, 'xyz']) - var out = '' - child.stdout.on('data', function (c) { - out += c - }) - child.on('close', function (code, signal) { - t.equal(code, 0) - t.equal(signal, null) - t.equal(out, 'WRAP ["--harmony","{{FIXTURE}}","xyz"]\n' + - '["--harmony"]\n' + - '["xyz"]\n' + - 'EXIT [0,null]\n') - t.end() - }) -}) - -t.test('node exe with different name', function(t) { - var fp = path.join(__dirname, 'fixtures', 'exething.exe') - var data = fs.readFileSync(process.execPath) - fs.writeFileSync(fp, data) - fs.chmodSync(fp, '0775') - var child = cp.spawn(process.execPath, [fixture, 'xyz']) - - var out = '' - child.stdout.on('data', function (c) { - out += c - }) - child.on('close', function (code, signal) { - t.equal(code, 0) - t.equal(signal, null) - t.equal(out, expect) - fs.unlinkSync(fp) - t.end() - }) -}) - -t.test('unwrap', function (t) { - unwrap() - t.end() -}) diff --git a/node_modules/spawn-wrap/test/fixtures/node_modules/npm/bin/npm-cli.js b/node_modules/spawn-wrap/test/fixtures/node_modules/npm/bin/npm-cli.js deleted file mode 100644 index b3c400768..000000000 --- a/node_modules/spawn-wrap/test/fixtures/node_modules/npm/bin/npm-cli.js +++ /dev/null @@ -1,4 +0,0 @@ -'use strict'; -console.log('%j', process.execArgv) -console.log('%j', process.argv.slice(2)) -setTimeout(function () {}, 100) diff --git a/node_modules/spawn-wrap/test/fixtures/npm b/node_modules/spawn-wrap/test/fixtures/npm deleted file mode 100755 index 4e026deb9..000000000 --- a/node_modules/spawn-wrap/test/fixtures/npm +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -// 2>/dev/null; exec "`dirname "$0"`/node" "$0" "$@" -console.log('%j', process.execArgv) -console.log('%j', process.argv.slice(2)) -setTimeout(function () {}, 100) diff --git a/node_modules/spawn-wrap/test/fixtures/npm.cmd b/node_modules/spawn-wrap/test/fixtures/npm.cmd deleted file mode 100644 index 521ec9e4d..000000000 --- a/node_modules/spawn-wrap/test/fixtures/npm.cmd +++ /dev/null @@ -1,2 +0,0 @@ -@echo This code should never be executed. -exit /B 1 diff --git a/node_modules/spawn-wrap/test/fixtures/script.js b/node_modules/spawn-wrap/test/fixtures/script.js deleted file mode 100755 index 3ccd0c9ea..000000000 --- a/node_modules/spawn-wrap/test/fixtures/script.js +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env node -console.log('%j', process.execArgv) -console.log('%j', process.argv.slice(2)) - -// Keep the event loop alive long enough to receive signals. -setTimeout(function() {}, 100) diff --git a/node_modules/spawn-wrap/test/fixtures/test-shim.js b/node_modules/spawn-wrap/test/fixtures/test-shim.js deleted file mode 100644 index b6baf69ee..000000000 --- a/node_modules/spawn-wrap/test/fixtures/test-shim.js +++ /dev/null @@ -1,3 +0,0 @@ -console.log('before in shim') -require('../..').runMain() -console.log('after in shim') diff --git a/node_modules/spawn-wrap/test/fixtures/wrap.js b/node_modules/spawn-wrap/test/fixtures/wrap.js deleted file mode 100644 index a8af6e471..000000000 --- a/node_modules/spawn-wrap/test/fixtures/wrap.js +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env node -var sw = require('../..') - -sw([require.resolve('./test-shim.js')]) - -var path = require('path') -var spawn = require('child_process').spawn - -spawn(path.resolve(process.argv[2]), process.argv.slice(3), { - stdio: 'inherit' -}).on('close', function (code, signal) { - if (code || signal) { - throw new Error('failed with ' + (code || signal)) - } - - // now run using PATH - process.env.PATH = path.resolve(path.dirname(process.argv[2])) + - ':' + process.env.PATH - - spawn(path.basename(process.argv[2]), process.argv.slice(3), { - stdio: 'inherit', - }, function (code, signal) { - if (code || signal) { - throw new Error('failed with ' + (code || signal)) - } - }) -}) diff --git a/node_modules/spawn-wrap/test/win-rebase.js b/node_modules/spawn-wrap/test/win-rebase.js deleted file mode 100644 index b9d09fe0b..000000000 --- a/node_modules/spawn-wrap/test/win-rebase.js +++ /dev/null @@ -1,40 +0,0 @@ -var t = require('tap') -var winRebase = require('../lib/win-rebase') - -t.test('it replaces path to node bin', function (t) { - var result = winRebase('C:\\Program Files\\nodejs\\node.exe', 'C:\\foo') - t.equal(result, 'C:\\foo') - t.done() -}) - -t.test('it does not replace path if it references an unknown bin', function (t) { - var result = winRebase('C:\\Program Files\\nodejs\\banana', 'C:\\foo') - t.equal(result, 'C:\\Program Files\\nodejs\\banana') - t.done() -}) - -t.test('replaces node bin and leaves the script being executed', function (t) { - var result = winRebase('C:\\Program Files\\nodejs\\node.exe foo.js', 'C:\\foo') - t.equal(result, 'C:\\foo foo.js') - t.done() -}) - -t.test('handles a quote', function (t) { - var result = winRebase('"C:\\Program Files\\nodejs\\node.exe" "foo.js"', 'C:\\foo') - t.equal(result, '"C:\\foo" "foo.js"') - t.end() -}) - -t.test('handles many quotes', function (t) { - var result = winRebase('""C:\\Program Files\\nodejs\\node.exe" "foo.js""', 'C:\\foo') - t.equal(result, '""C:\\foo" "foo.js""') - t.end() -}) - -t.test('handles npm invocations', function (t) { - var result = winRebase('""npm" "install""', - 'C:\\foo', - function() { return 'C:\\path-to-npm\\npm' }) - t.equal(result, '""C:\\foo "C:\\path-to-npm\\node_modules\\npm\\bin\\npm-cli.js"" "install""') - t.end() -}) |