Skip to content

Commit

Permalink
update tap tests to hit no external dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored and isaacs committed Apr 10, 2014
1 parent c95cf08 commit 7d0aec2
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 60 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
script: "npm run-script tap"
node_js:
- "0.11"
- "0.10"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
npm(1) -- node package manager
==============================

[![Build Status](https://img.shields.io/travis/npm/npm/master.svg)](https://travis-ci.org/npm/npm)
## SYNOPSIS

This is just enough info to get you up and running.
Expand Down
1 change: 0 additions & 1 deletion lib/dedupe.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,3 @@ function whoDepends_ (pkg, who, test) {
})
return who
}

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
},
"scripts": {
"test": "node ./test/run.js && tap test/tap/*.js",
"tap": "tap test/tap/*.js",
"tap": "tap --timeout 120 test/tap/*.js",
"prepublish": "node bin/npm-cli.js prune --prefix=. --no-global && rm -rf test/*/*/node_modules && make -j32 doc",
"dumpconf": "env | grep npm | sort | uniq",
"echo": "node bin/npm-cli.js"
Expand Down
10 changes: 7 additions & 3 deletions test/tap/404-parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var fs = require('fs')
var rimraf = require('rimraf')
var mkdirp = require('mkdirp')
var pkg = path.resolve(__dirname, '404-parent')
var mr = require("npm-registry-mock")

test('404-parent: if parent exists, specify parent in error message', function(t) {
setup()
Expand Down Expand Up @@ -41,9 +42,12 @@ function setup() {
}

function performInstall(cb) {
npm.load(function() {
npm.commands.install(pkg, [], function(err) {
cb(err)
mr(common.port, function (s) { // create mock registry.
npm.load({registry: common.registry}, function() {
npm.commands.install(pkg, [], function(err) {
cb(err)
s.close() // shutdown mock npm server.
})
})
})
}
20 changes: 12 additions & 8 deletions test/tap/dedupe.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@ var test = require("tap").test
, existsSync = fs.existsSync || path.existsSync
, npm = require("../../")
, rimraf = require("rimraf")
, mr = require("npm-registry-mock")
, common = require('../common-tap.js')

test("dedupe finds the common module and moves it up one level", function (t) {
t.plan(2)

setup(function () {
setup(function (s) {
npm.install(".", function (err) {
if (err) return t.fail(err)
npm.dedupe(function(err) {
if (err) return t.fail(err)
t.ok(existsSync(path.join(__dirname, "dedupe", "node_modules", "minimist")))
t.ok(!existsSync(path.join(__dirname, "dedupe", "node_modules", "prime")))
t.ok(!existsSync(path.join(__dirname, "dedupe", "node_modules", "checker")))
s.close() // shutdown mock registry.
t.end()
})
})
})
})

function setup (cb) {
process.chdir(path.join(__dirname, "dedupe"))
npm.load(function () {
rimraf.sync(path.join(__dirname, "dedupe", "node_modules"))
fs.mkdirSync(path.join(__dirname, "dedupe", "node_modules"))
cb()
mr(common.port, function (s) { // create mock registry.
npm.load({registry: common.registry}, function() {
rimraf.sync(path.join(__dirname, "dedupe", "node_modules"))
fs.mkdirSync(path.join(__dirname, "dedupe", "node_modules"))
cb(s)
})
})
}
4 changes: 1 addition & 3 deletions test/tap/dedupe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"version": "0.0.0",
"dependencies": {
"optimist": "0.6.0",
"clean": "2.1.6",
"informal": "0.0.1",
"pathogen": "0.1.5"
"clean": "2.1.6"
}
}
3 changes: 3 additions & 0 deletions test/tap/git-cache-locking.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ test("setup", function (t) {

test("git-cache-locking: install a git dependency", function (t) {

// disable git integration tests on Travis.
if (process.env.TRAVIS) return t.end()

// package c depends on a.git#master and b.git#master
// package b depends on a.git#master
var child = spawn(node, [npm, "install", "git://github.com/nigelzor/npm-4503-c.git"], {
Expand Down
2 changes: 1 addition & 1 deletion test/tap/lifecycle-signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var pkg = path.resolve(__dirname, "lifecycle-signal")

test("lifecycle signal abort", function (t) {
// windows does not use lifecycle signals, abort
if (process.platform === "win32") return t.end()
if (process.platform === "win32" || process.env.TRAVIS) return t.end()
var child = spawn(node, [npm, "install"], {
cwd: pkg
})
Expand Down
17 changes: 10 additions & 7 deletions test/tap/outdated-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var mkdirp = require("mkdirp")
var rimraf = require("rimraf")
var mr = require("npm-registry-mock")
var exec = require('child_process').exec
var mr = require("npm-registry-mock")

var pkg = __dirname + '/outdated'
var NPM_BIN = __dirname + '/../../bin/npm-cli.js'
Expand All @@ -25,17 +26,19 @@ function ansiTrim (str) {
// it's not running in a tty
test("does not use ansi styling", function (t) {
t.plan(3)
exec('node ' + NPM_BIN + ' outdated --color false', {
cwd: pkg
}, function(err, stdout) {
t.ifError(err)
t.ok(stdout, stdout.length)
t.ok(!hasControlCodes(stdout))
mr(common.port, function (s) { // create mock registry.
exec('node ' + NPM_BIN + ' outdated --registry ' + common.registry + ' --color false underscore', {
cwd: pkg
}, function(err, stdout) {
t.ifError(err)
t.ok(stdout, stdout.length)
t.ok(!hasControlCodes(stdout))
s.close()
})
})
})

test("cleanup", function (t) {
rimraf.sync(pkg + "/cache")
t.end()
})

50 changes: 28 additions & 22 deletions test/tap/peer-deps-invalid.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ var test = require("tap").test
var rimraf = require("rimraf")
var npm = require("../../")
var http = require("http")
var mr = require("npm-registry-mock")

var okFile = new Buffer(
'/**package\n' +
' * { "name": "npm-test-peer-deps-file"\n' +
' * , "main": "index.js"\n' +
' * , "version": "1.2.3"\n' +
' * , "description":"No package.json in sight!"\n' +
' * , "peerDependencies": { "dict": "1.1.0" }\n' +
' * , "dependencies": { "opener": "1.3.0" }\n' +
' * }\n' +
' **/\n' +
'\n' +
'/**package\n' +
' * { "name": "npm-test-peer-deps-file"\n' +
' * , "main": "index.js"\n' +
' * , "version": "1.2.3"\n' +
' * , "description":"No package.json in sight!"\n' +
' * , "peerDependencies": { "underscore": "1.3.1" }\n' +
' * , "dependencies": { "mkdirp": "0.3.5" }\n' +
' * }\n' +
' **/\n' +
'\n' +
'module.exports = "I\'m just a lonely index, naked as the day I was born."\n'
)

Expand All @@ -25,7 +26,7 @@ var failFile = new Buffer(
' * , "main": "index.js"\n' +
' * , "version": "1.2.3"\n' +
' * , "description":"This one should conflict with the other one"\n' +
' * , "peerDependencies": { "dict": "1.0.0" }\n' +
' * , "peerDependencies": { "underscore": "1.3.3" }\n' +
' * }\n' +
' **/\n' +
'\n' +
Expand All @@ -51,20 +52,25 @@ test("setup", function(t) {



test("installing dependencies that having conflicting peerDependencies", function (t) {
test("installing dependencies that have conflicting peerDependencies", function (t) {
rimraf.sync(__dirname + "/peer-deps-invalid/node_modules")
process.chdir(__dirname + "/peer-deps-invalid")

npm.load(function () {
console.error('back from load')
npm.commands.install([], function (err) {
console.error('back from install')
if (!err) {
t.fail("No error!")
} else {
t.equal(err.code, "EPEERINVALID")
}
t.end()
// we're already listening on common.port,
// use an alternative port for this test.
mr(1331, function (s) { // create mock registry.
npm.load({registry: "http://localhost:1331"}, function () {
console.error('back from load')
npm.commands.install([], function (err) {
console.error('back from install')
if (!err) {
t.fail("No error!")
} else {
t.equal(err.code, "EPEERINVALID")
}
t.end()
s.close() // shutdown mock registry.
})
})
})
})
Expand Down
29 changes: 17 additions & 12 deletions test/tap/peer-deps-without-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var fs = require("fs")
var test = require("tap").test
var rimraf = require("rimraf")
var npm = require("../../")

var mr = require("npm-registry-mock")
var http = require("http")


Expand All @@ -13,8 +13,8 @@ var js = new Buffer(
' * , "main": "index.js"\n' +
' * , "version": "1.2.3"\n' +
' * , "description":"No package.json in sight!"\n' +
' * , "peerDependencies": { "dict": "1.1.0" }\n' +
' * , "dependencies": { "opener": "1.3.0" }\n' +
' * , "peerDependencies": { "underscore": "1.3.1" }\n' +
' * , "dependencies": { "mkdirp": "0.3.5" }\n' +
' * }\n' +
' **/\n' +
'\n' +
Expand All @@ -38,15 +38,20 @@ test("installing a peerDependencies-using package without a package.json present
fs.mkdirSync(__dirname + "/peer-deps-without-package-json/node_modules")
process.chdir(__dirname + "/peer-deps-without-package-json")

npm.load(function () {
npm.install(common.registry, function (err) {
if (err) {
t.fail(err)
} else {
t.ok(fs.existsSync(__dirname + "/peer-deps-without-package-json/node_modules/npm-test-peer-deps-file"))
t.ok(fs.existsSync(__dirname + "/peer-deps-without-package-json/node_modules/dict"))
}
t.end()
// we're already listening on common.port,
// use an alternative port for this test.
mr(1331, function (s) { // create mock registry.
npm.load({registry: 'http://localhost:1331'}, function () {
npm.install(common.registry, function (err) {
if (err) {
t.fail(err)
} else {
t.ok(fs.existsSync(__dirname + "/peer-deps-without-package-json/node_modules/npm-test-peer-deps-file"))
t.ok(fs.existsSync(__dirname + "/peer-deps-without-package-json/node_modules/underscore"))
}
t.end()
s.close() // shutdown mock registry.
})
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/tap/sorted-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test("sorting dependencies", function (t) {

var before = JSON.parse(fs.readFileSync(packageJson).toString())

mr({port: common.port}, function (s) {
mr(common.port, function (s) {
// underscore is already in the package.json,
// but --save will trigger a rewrite with sort
var child = spawn(node, [npm, "install", "--save", "[email protected]"], {
Expand Down

0 comments on commit 7d0aec2

Please sign in to comment.