diff options
author | Robert Kowalski <rok@kowalski.gd> | 2014-02-21 00:05:05 +0400 |
---|---|---|
committer | Robert Kowalski <rok@kowalski.gd> | 2014-02-21 01:10:53 +0400 |
commit | 2ddd06037e9bd58cd95a380a9381ff90bea47f0d (patch) | |
tree | d53182d89c32f6301d77e866afcd42ab08f33b80 /test | |
parent | 6fd6ff7e536ea6acd33037b1878d4eca1f931985 (diff) |
add test, some boyscouting
Diffstat (limited to 'test')
-rw-r--r-- | test/tap/sorted-package-json.js | 93 | ||||
-rw-r--r-- | test/tap/url-dependencies.js | 7 |
2 files changed, 97 insertions, 3 deletions
diff --git a/test/tap/sorted-package-json.js b/test/tap/sorted-package-json.js new file mode 100644 index 000000000..0d978997f --- /dev/null +++ b/test/tap/sorted-package-json.js @@ -0,0 +1,93 @@ +var test = require("tap").test + , path = require("path") + , rimraf = require("rimraf") + , mkdirp = require("mkdirp") + , spawn = require("child_process").spawn + , npm = require.resolve("../../bin/npm-cli.js") + , node = process.execPath + , pkg = path.resolve(__dirname, "sorted-package-json") + , tmp = path.join(pkg, "tmp") + , cache = path.join(pkg, "cache") + , fs = require("fs") + , common = require("../common-tap.js") + , mr = require("npm-registry-mock") + , osenv = require("osenv") + + +test("sorting dependencies", function (t) { + var packageJson = path.resolve(pkg, "package.json") + + cleanup() + mkdirp.sync(cache) + mkdirp.sync(tmp) + setup() + + var before = JSON.parse(fs.readFileSync(packageJson).toString()) + + mr({port: 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", "underscore@1.3.3"], { + cwd: pkg, + env: { + npm_config_registry: common.registry, + npm_config_cache: cache, + npm_config_tmp: tmp, + npm_config_prefix: pkg, + npm_config_global: "false", + HOME: process.env.HOME, + Path: process.env.PATH, + PATH: process.env.PATH + } + }) + + child.on("close", function (code) { + var result = fs.readFileSync(packageJson).toString() + , resultAsJson = JSON.parse(result) + + s.close() + + t.same(Object.keys(resultAsJson.dependencies), + Object.keys(before.dependencies).sort()) + + t.notSame(Object.keys(resultAsJson.dependencies), + Object.keys(before.dependencies)) + + t.ok(resultAsJson.dependencies.underscore) + t.ok(resultAsJson.dependencies.request) + t.end() + }) + }) +}) + +test("cleanup", function (t) { + cleanup() + t.pass("cleaned up") + t.end() +}) + +function setup() { + mkdirp.sync(pkg) + + fs.writeFileSync(path.resolve(pkg, "package.json"), JSON.stringify({ + "name": "sorted-package-json", + "version": "0.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Rocko Artischocko", + "license": "ISC", + "dependencies": { + "underscore": "^1.3.3", + "request": "^0.9.0" + } + }, null, 2), 'utf8') +} + +function cleanup() { + process.chdir(osenv.tmpdir()) + rimraf.sync(cache) + rimraf.sync(pkg) +} diff --git a/test/tap/url-dependencies.js b/test/tap/url-dependencies.js index 59513dba2..c3e1fa2a3 100644 --- a/test/tap/url-dependencies.js +++ b/test/tap/url-dependencies.js @@ -7,6 +7,7 @@ var spawn = require("child_process").spawn var npm = require.resolve("../../bin/npm-cli.js") var node = process.execPath var pkg = path.resolve(__dirname, "url-dependencies") +var common = require('../common-tap') var mockRoutes = { "get": { @@ -43,16 +44,16 @@ test("url-dependencies: do not download subsequent times", function(t) { }) function tarballWasFetched(output){ - return output.indexOf("http GET http://localhost:1337/underscore/-/underscore-1.3.1.tgz") > -1 + return output.indexOf("http GET " + common.registry + "/underscore/-/underscore-1.3.1.tgz") > -1 } function performInstall (cb) { - mr({port: 1337, mocks: mockRoutes}, function(s){ + mr({port: common.port, mocks: mockRoutes}, function(s){ var output = "" , child = spawn(node, [npm, "install"], { cwd: pkg, env: { - npm_config_registry: "http://localhost:1337", + npm_config_registry: common.registry, npm_config_cache_lock_stale: 1000, npm_config_cache_lock_wait: 1000, HOME: process.env.HOME, |