diff options
Diffstat (limited to 'deps/npm/test/tap/peer-deps-without-package-json.js')
-rw-r--r-- | deps/npm/test/tap/peer-deps-without-package-json.js | 78 |
1 files changed, 33 insertions, 45 deletions
diff --git a/deps/npm/test/tap/peer-deps-without-package-json.js b/deps/npm/test/tap/peer-deps-without-package-json.js index 9f987c5ee51..ce01be4d088 100644 --- a/deps/npm/test/tap/peer-deps-without-package-json.js +++ b/deps/npm/test/tap/peer-deps-without-package-json.js @@ -1,59 +1,47 @@ var common = require('../common-tap.js') var fs = require("fs") +var path = require("path") var test = require("tap").test var rimraf = require("rimraf") var npm = require("../../") +var mr = require("npm-registry-mock") +var pkg = __dirname + "/peer-deps-without-package-json" -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(common.port, function () { - t.pass('listening') - t.end() - }) -}) - +var js = fs.readFileSync(path.join(pkg, "file-js.js"), "utf8") test("installing a peerDependencies-using package without a package.json present (GH-3049)", function (t) { - rimraf.sync(__dirname + "/peer-deps-without-package-json/node_modules") - 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() + rimraf.sync(pkg + "/node_modules") + rimraf.sync(pkg + "/cache") + + fs.mkdirSync(pkg + "/node_modules") + process.chdir(pkg) + + var customMocks = { + "get": { + "/ok.js": [200, js], + } + } + mr({port: common.port, mocks: customMocks}, function (s) { // create mock registry. + npm.load({ + registry: common.registry, + cache: pkg + "/cache" + }, function () { + npm.install(common.registry + "/ok.js", function (err) { + if (err) { + t.fail(err) + } else { + t.ok(fs.existsSync(pkg + "/node_modules/npm-test-peer-deps-file")) + t.ok(fs.existsSync(pkg + "/node_modules/underscore")) + } + t.end() + s.close() // shutdown mock registry. + }) }) }) }) test("cleanup", function (t) { - server.close(function() { - t.pass("closed") - t.end() - }) + rimraf.sync(pkg + "/node_modules") + rimraf.sync(pkg + "/cache") + t.end() }) |