Skip to content

Commit

Permalink
test: Make tap tests not rely on gists
Browse files Browse the repository at this point in the history
Too slow and unreliable.  Still need to work out how to make this work
for the other non-tap tests.  Maybe those should all just go away.
  • Loading branch information
isaacs committed Mar 20, 2013
1 parent b2eacd4 commit 3d1ac90
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 18 deletions.
66 changes: 59 additions & 7 deletions test/tap/peer-deps-invalid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,75 @@ var fs = require("fs")
var test = require("tap").test
var rimraf = require("rimraf")
var npm = require("../../")
var http = require("http")

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' +
'module.exports = "I\'m just a lonely index, naked as the day I was born."\n'
)

var failFile = new Buffer(
'/**package\n' +
' * { "name": "npm-test-peer-deps-file-invalid"\n' +
' * , "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' +
' * }\n' +
' **/\n' +
'\n' +
'module.exports = "I\'m just a lonely index, naked as the day I was born."\n'
)

var server
test("setup", function(t) {
server = http.createServer(function (req, res) {
res.setHeader('content-type', 'application/javascript')
switch (req.url) {
case "/ok.js":
return res.end(okFile)
default:
return res.end(failFile)
}
})
server.listen(1337, function() {
t.pass("listening")
t.end()
})
})

test("installing dependencies that having conflicting peerDependencies", function (t) {
t.plan(1)


test("installing dependencies that having 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!")
process.exit(1)
return
} else {
t.equal(err.code, "EPEERINVALID")
}

t.equal(err.code, "EPEERINVALID")
process.exit(0)
t.end()
})
})
})

test("shutdown", function(t) {
server.close(function() {
t.pass("closed")
t.end()
})
})
4 changes: 2 additions & 2 deletions test/tap/peer-deps-invalid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "peer-deps-invalid",
"version": "0.0.0",
"dependencies": {
"npm-test-peer-deps-file": "https://raw.github.com/gist/3971128/3f6aa37b4fa1186c2f47da9b77dcc4ec496e3483/index.js",
"npm-test-peer-deps-file-invalid": "https://gist.github.com/raw/4303335/861f8d3213061826ab31591840c3cb0ac737f4fc/index.js"
"npm-test-peer-deps-file": "http://localhost:1337/ok.js",
"npm-test-peer-deps-file-invalid": "http://localhost:1337/invalid.js"
}
}
47 changes: 38 additions & 9 deletions test/tap/peer-deps-without-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,33 @@ var test = require("tap").test
var rimraf = require("rimraf")
var npm = require("../../")

var peerDepsTestUrl = "https://gist.github.com/raw/3971128/3f6aa37b4fa1186c2f47da9b77dcc4ec496e3483/index.js"
var http = require("http")


var js = 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' +
'module.exports = "I\'m just a lonely index, naked as the day I was born."\n')

var server
test("setup", function(t) {
server = http.createServer(function (q, s) {
s.setHeader('content-type', 'application/javascript')
s.end(js)
})
server.listen(1337, function() {
t.pass('listening')
t.end()
})
})

test("installing a peerDependencies-using package without a package.json present (GH-3049)", function (t) {

Expand All @@ -12,18 +38,21 @@ test("installing a peerDependencies-using package without a package.json present
process.chdir(__dirname + "/peer-deps-without-package-json")

npm.load(function () {
npm.install(peerDepsTestUrl, function (err) {
npm.install('http://localhost:1337/', function (err) {
if (err) {
t.fail(err)
t.end()
process.exit(1)
return
} 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.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()
process.exit(0)
})
})
})

test("cleanup", function (t) {
server.close(function() {
t.pass("closed")
t.end()
})
})

0 comments on commit 3d1ac90

Please sign in to comment.