mirror of
https://github.com/zhigang1992/npm.git
synced 2026-01-12 17:32:45 +08:00
test: fixes to work with Windows
This commit is contained in:
committed by
Forrest L Norvell
parent
05838743f0
commit
ccc1e2e067
@@ -1,124 +1,69 @@
|
||||
var common = require('../common-tap.js')
|
||||
var test = require('tap').test
|
||||
var osenv = require('osenv')
|
||||
var npm = require.resolve("../../bin/npm-cli.js")
|
||||
var node = process.execPath
|
||||
var path = require('path')
|
||||
var fs = require('fs')
|
||||
var rimraf = require('rimraf')
|
||||
var mkdirp = require('mkdirp')
|
||||
var pkg = path.resolve(__dirname, 'ignore-install-link')
|
||||
var root = path.resolve(__dirname, 'ignore-install-link-root')
|
||||
var spawn = require('child_process').spawn
|
||||
var linkDir = path.resolve(osenv.tmpdir(), 'npm-link-issue')
|
||||
if (process.platform === "win32") {
|
||||
console.log("ok - symlinks are weird on windows, skip this test")
|
||||
return
|
||||
}
|
||||
var common = require("../common-tap.js")
|
||||
var test = require("tap").test
|
||||
var path = require("path")
|
||||
var fs = require("fs")
|
||||
var rimraf = require("rimraf")
|
||||
var mkdirp = require("mkdirp")
|
||||
|
||||
test('ignore-install-link: ignore install if a package is linked', function(t) {
|
||||
setup(function(err) {
|
||||
if (err) {
|
||||
t.ifError(err)
|
||||
t.end()
|
||||
return
|
||||
}
|
||||
var root = path.resolve(__dirname, "ignore-install-link")
|
||||
var pkg = path.resolve(root, "pkg")
|
||||
var dep = path.resolve(root, "dep")
|
||||
var target = path.resolve(pkg, "node_modules", "dep")
|
||||
var cache = path.resolve(root, "cache")
|
||||
var globalPath = path.resolve(root, "global")
|
||||
|
||||
var p = path.resolve(pkg, 'node_modules', 'npm-link-issue')
|
||||
fs.lstat(p, function(err, s) {
|
||||
t.ifError(err)
|
||||
var pkgj = { "name":"pkg", "version": "1.2.3"
|
||||
, "dependencies": { "dep": "1.2.3" } }
|
||||
var depj = { "name": "dep", "version": "1.2.3" }
|
||||
|
||||
t.ok(true === s.isSymbolicLink(), 'child is a symlink')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
var myreg = require("http").createServer(function (q, s) {
|
||||
s.statusCode = 403
|
||||
s.end(JSON.stringify({"error":"forbidden"}) + "\n")
|
||||
}).listen(common.port)
|
||||
|
||||
test('cleanup', function(t) {
|
||||
process.chdir(osenv.tmpdir())
|
||||
rimraf.sync(pkg)
|
||||
test("setup", function (t) {
|
||||
rimraf.sync(root)
|
||||
rimraf.sync(linkDir)
|
||||
mkdirp.sync(root)
|
||||
mkdirp.sync(path.resolve(pkg, "node_modules"))
|
||||
mkdirp.sync(dep)
|
||||
mkdirp.sync(cache)
|
||||
mkdirp.sync(globalPath)
|
||||
fs.writeFileSync(path.resolve(pkg, "package.json"), JSON.stringify(pkgj))
|
||||
fs.writeFileSync(path.resolve(dep, "package.json"), JSON.stringify(depj))
|
||||
fs.symlinkSync(dep, target, "dir")
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("ignore install if package is linked", function (t) {
|
||||
common.npm(["install"], {
|
||||
cwd: pkg,
|
||||
env: {
|
||||
PATH: process.env.PATH || process.env.Path,
|
||||
HOME: process.env.HOME,
|
||||
"npm_config_prefix": globalPath,
|
||||
"npm_config_cache": cache,
|
||||
"npm_config_registry": common.registry,
|
||||
"npm_config_loglevel": "silent"
|
||||
},
|
||||
stdio: "inherit"
|
||||
}, function (er, code) {
|
||||
if (er) throw er
|
||||
t.equal(code, 0)
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
function setup(cb) {
|
||||
rimraf.sync(linkDir)
|
||||
test("still a symlink", function (t) {
|
||||
t.equal(true, fs.lstatSync(target).isSymbolicLink())
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("cleanup", function (t) {
|
||||
rimraf.sync(root)
|
||||
mkdirp.sync(root)
|
||||
mkdirp.sync(pkg)
|
||||
mkdirp.sync(path.resolve(pkg, 'cache'))
|
||||
mkdirp.sync(path.resolve(pkg, 'node_modules'))
|
||||
mkdirp.sync(linkDir)
|
||||
fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({
|
||||
author: 'Evan Lucas',
|
||||
name: 'ignore-install-link',
|
||||
version: '0.0.0',
|
||||
description: 'Test for ignoring install when a package has been linked',
|
||||
dependencies: {
|
||||
'npm-link-issue': 'git+https://github.com/lancefisher/npm-link-issue.git#0.0.1'
|
||||
}
|
||||
}), 'utf8')
|
||||
fs.writeFileSync(path.resolve(linkDir, 'package.json'), JSON.stringify({
|
||||
author: 'lancefisher',
|
||||
name: 'npm-link-issue',
|
||||
version: '0.0.1',
|
||||
description: 'Sample Dependency'
|
||||
}), 'utf8')
|
||||
|
||||
clone(cb)
|
||||
}
|
||||
|
||||
function clone (cb) {
|
||||
var child = createChild(process.cwd(), 'git', ['--git-dir', linkDir, 'init'])
|
||||
child.on('close', function(c) {
|
||||
if (c !== 0)
|
||||
return cb(new Error('Failed to init the git repository'))
|
||||
|
||||
process.chdir(linkDir)
|
||||
performLink(cb)
|
||||
})
|
||||
}
|
||||
|
||||
function performLink (cb) {
|
||||
var child = createChild(linkDir, node, [npm, 'link', '.'])
|
||||
child.on('close', function(c) {
|
||||
if (c !== 0)
|
||||
return cb(new Error('Failed to link ' + linkDir + ' globally'))
|
||||
|
||||
performLink2(cb)
|
||||
})
|
||||
}
|
||||
|
||||
function performLink2 (cb) {
|
||||
var child = createChild(pkg, node, [npm, 'link', 'npm-link-issue'])
|
||||
child.on('close', function(c) {
|
||||
if (c !== 0)
|
||||
return cb(new Error('Failed to link ' + linkDir + ' to local node_modules'))
|
||||
|
||||
performInstall(cb)
|
||||
})
|
||||
}
|
||||
|
||||
function performInstall (cb) {
|
||||
var child = createChild(pkg, node, [npm, 'install'])
|
||||
child.on('close', function(c) {
|
||||
if (c !== 0)
|
||||
return cb(new Error('Failed to install'))
|
||||
|
||||
cb()
|
||||
})
|
||||
}
|
||||
|
||||
function createChild (cwd, cmd, args) {
|
||||
var env = {
|
||||
HOME: process.env.HOME,
|
||||
Path: process.env.PATH,
|
||||
PATH: process.env.PATH,
|
||||
npm_config_loglevel: "error",
|
||||
npm_config_prefix: root
|
||||
}
|
||||
|
||||
return spawn(cmd, args, {
|
||||
cwd: cwd,
|
||||
stdio: [0, "ignore", 2],
|
||||
env: env
|
||||
})
|
||||
}
|
||||
myreg.close()
|
||||
t.end()
|
||||
})
|
||||
|
||||
@@ -18,7 +18,7 @@ function testOutput (t, command, er, code, stdout, stderr) {
|
||||
if (stderr)
|
||||
throw new Error('npm ' + command + ' stderr: ' + stderr.toString())
|
||||
|
||||
stdout = stdout.trim().split('\n')
|
||||
stdout = stdout.trim().split(/\n|\r/)
|
||||
stdout = stdout[stdout.length - 1]
|
||||
t.equal(stdout, command)
|
||||
t.end()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{"name":"startstop"
|
||||
,"version":"1.2.3"
|
||||
,"scripts":{
|
||||
"start":"node -e 'console.log(\"start\")'",
|
||||
"stop":"node -e 'console.log(\"stop\")'"
|
||||
"start":"node -e \"console.log('start')\"",
|
||||
"stop":"node -e \"console.log('stop')\""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user