aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/test/broken-under-nyc-and-travis
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/test/broken-under-nyc-and-travis')
-rw-r--r--deps/npm/test/broken-under-nyc-and-travis/lifecycle-path.js106
-rw-r--r--deps/npm/test/broken-under-nyc-and-travis/whoami.js77
2 files changed, 183 insertions, 0 deletions
diff --git a/deps/npm/test/broken-under-nyc-and-travis/lifecycle-path.js b/deps/npm/test/broken-under-nyc-and-travis/lifecycle-path.js
new file mode 100644
index 0000000000..a9d32d15b0
--- /dev/null
+++ b/deps/npm/test/broken-under-nyc-and-travis/lifecycle-path.js
@@ -0,0 +1,106 @@
+var fs = require('fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+var isWindows = require('../../lib/utils/is-windows.js')
+
+var pkg = path.resolve(__dirname, 'lifecycle-path')
+
+var PATH
+if (isWindows) {
+ // On Windows the 'comspec' environment variable is used,
+ // so cmd.exe does not need to be on the path.
+ PATH = path.dirname(process.env.ComSpec)
+} else {
+ // On non-Windows, without the path to the shell, nothing usually works.
+ PATH = '/bin:/usr/bin'
+}
+
+test('setup', function (t) {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify({}, null, 2)
+ )
+ t.end()
+})
+
+test('make sure the path is correct, without directory of current node', function (t) {
+ checkPath(false, t)
+})
+
+test('make sure the path is correct, with directory of current node', function (t) {
+ checkPath(true, t)
+})
+
+function checkPath (withDirOfCurrentNode, t) {
+ var newPATH = PATH
+ var currentNodeExecPath = process.execPath
+ if (withDirOfCurrentNode) {
+ var newNodeExeDir = path.join(pkg, 'node-bin')
+ mkdirp.sync(newNodeExeDir)
+ currentNodeExecPath = path.join(newNodeExeDir, 'my_bundled_' + path.basename(process.execPath))
+ fs.writeFileSync(currentNodeExecPath, fs.readFileSync(process.execPath))
+ fs.chmodSync(currentNodeExecPath, '755')
+ } else {
+ // Ensure that current node interpreter will be found in the PATH,
+ // so the PATH won't be prepended with its parent directory
+ newPATH = [path.dirname(process.execPath), PATH].join(process.platform === 'win32' ? ';' : ':')
+ }
+ common.npm(['run-script', 'env'], {
+ cwd: pkg,
+ nodeExecPath: currentNodeExecPath,
+ env: {
+ PATH: newPATH
+ },
+ stdio: [ 0, 'pipe', 2 ]
+ }, function (er, code, stdout) {
+ if (er) throw er
+ t.equal(code, 0, 'exit code')
+ var lineMatch = function (line) {
+ return /^PATH=/i.test(line)
+ }
+ // extract just the path value
+ stdout = stdout.split(/\r?\n/).filter(lineMatch).pop().replace(/^PATH=/, '')
+ var pathSplit = process.platform === 'win32' ? ';' : ':'
+ var root = path.resolve(__dirname, '../..')
+ var actual = stdout.split(pathSplit).map(function (p) {
+ if (p.indexOf(root) === 0) {
+ p = '{{ROOT}}' + p.substr(root.length)
+ }
+ return p.replace(/\\/g, '/')
+ })
+ // spawn-wrap adds itself to the path when coverage is enabled
+ actual = actual.filter(function (p) {
+ return !p.match(/\.node-spawn-wrap/)
+ })
+
+ // get the ones we tacked on, then the system-specific requirements
+ var expectedPaths = ['{{ROOT}}/bin/node-gyp-bin',
+ '{{ROOT}}/test/broken-under-nyc-and-travis/lifecycle-path/node_modules/.bin']
+ if (withDirOfCurrentNode) {
+ expectedPaths.push('{{ROOT}}/test/broken-under-nyc-and-travis/lifecycle-path/node-bin')
+ }
+ var expect = expectedPaths.concat(newPATH.split(pathSplit)).map(function (p) {
+ return p.replace(/\\/g, '/')
+ })
+ t.same(actual, expect)
+ t.end()
+ })
+}
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/deps/npm/test/broken-under-nyc-and-travis/whoami.js b/deps/npm/test/broken-under-nyc-and-travis/whoami.js
new file mode 100644
index 0000000000..268e0f94fe
--- /dev/null
+++ b/deps/npm/test/broken-under-nyc-and-travis/whoami.js
@@ -0,0 +1,77 @@
+var common = require('../common-tap.js')
+
+var fs = require('fs')
+var path = require('path')
+var createServer = require('http').createServer
+
+var test = require('tap').test
+var rimraf = require('rimraf')
+
+var opts = { cwd: __dirname }
+
+var FIXTURE_PATH = path.resolve(__dirname, 'fixture_npmrc')
+
+test('npm whoami with basic auth', function (t) {
+ var s = '//registry.lvh.me/:username = wombat\n' +
+ '//registry.lvh.me/:_password = YmFkIHBhc3N3b3Jk\n' +
+ '//registry.lvh.me/:email = lindsay@wdu.org.au\n'
+ fs.writeFileSync(FIXTURE_PATH, s, 'ascii')
+ fs.chmodSync(FIXTURE_PATH, '0444')
+
+ common.npm(
+ [
+ 'whoami',
+ '--userconfig=' + FIXTURE_PATH,
+ '--registry=http://registry.lvh.me/'
+ ],
+ opts,
+ function (err, code, stdout, stderr) {
+ t.ifError(err)
+
+ t.equal(stderr, '', 'got nothing on stderr')
+ t.equal(code, 0, 'exit ok')
+ t.equal(stdout, 'wombat\n', 'got username')
+ rimraf.sync(FIXTURE_PATH)
+ t.end()
+ }
+ )
+})
+
+test('npm whoami with bearer auth', { timeout: 2 * 1000 }, function (t) {
+ var s = '//localhost:' + common.port +
+ '/:_authToken = wombat-developers-union\n'
+ fs.writeFileSync(FIXTURE_PATH, s, 'ascii')
+ fs.chmodSync(FIXTURE_PATH, '0444')
+
+ function verify (req, res) {
+ t.equal(req.method, 'GET')
+ t.equal(req.url, '/-/whoami')
+
+ res.setHeader('content-type', 'application/json')
+ res.writeHeader(200)
+ res.end(JSON.stringify({ username: 'wombat' }), 'utf8')
+ }
+
+ var server = createServer(verify)
+
+ server.listen(common.port, function () {
+ common.npm(
+ [
+ 'whoami',
+ '--userconfig=' + FIXTURE_PATH,
+ '--registry=http://localhost:' + common.port + '/'
+ ],
+ opts,
+ function (err, code, stdout, stderr) {
+ t.ifError(err)
+
+ t.equal(stderr, '', 'got nothing on stderr')
+ t.equal(code, 0, 'exit ok')
+ t.equal(stdout, 'wombat\n', 'got username')
+ rimraf.sync(FIXTURE_PATH)
+ server.close()
+ t.end()
+ }
+ )
+ })
+})