| @@ -0,0 +1,122 @@ | ||
| // this is a weird meta test. It verifies that all the instances of | ||
| // `npm.config.get(...)` are: | ||
| // a) Simple strings, and not variables | ||
| // b) Documented | ||
| // c) Defined in the `npmconf` package. | ||
|
|
||
| var test = require("tap").test | ||
| var fs = require("fs") | ||
| var path = require("path") | ||
| var root = path.resolve(__dirname, "..", "..") | ||
| var lib = path.resolve(root, "lib") | ||
| var nm = path.resolve(root, "node_modules") | ||
| var doc = path.resolve(root, "doc/misc/npm-config.md") | ||
| var FILES = [] | ||
| var CONFS = {} | ||
| var DOC = {} | ||
|
|
||
| var exceptions = [ | ||
| path.resolve(lib, "config.js"), | ||
| path.resolve(lib, "utils", "lifecycle.js") | ||
| ] | ||
|
|
||
| test("get files", function (t) { | ||
| walk(nm) | ||
| walk(lib) | ||
| t.pass("got files") | ||
| t.end() | ||
|
|
||
| function walk(lib) { | ||
| var files = fs.readdirSync(lib).map(function (f) { | ||
| return path.resolve(lib, f) | ||
| }) | ||
| files.forEach(function (f) { | ||
| if (fs.statSync(f).isDirectory()) | ||
| walk(f) | ||
| else if (f.match(/\.js$/)) | ||
| FILES.push(f) | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| test("get lines", function (t) { | ||
| FILES.forEach(function (f) { | ||
| console.error(f) | ||
| var lines = fs.readFileSync(f, 'utf8').split('\n') | ||
| lines.forEach(function (l, i) { | ||
| var matches = l.split(/conf(?:ig)?\.get\(/g) | ||
| matches.shift() | ||
| matches.forEach(function (m) { | ||
| m = m.split(')').shift() | ||
| var literal = m.match(/^['"].+['"]$/) | ||
| if (literal) { | ||
| m = m.slice(1, -1) | ||
| if (!m.match(/^\_/) && m !== 'argv') | ||
| CONFS[m] = { | ||
| file: f, | ||
| line: i | ||
| } | ||
| } else if (exceptions.indexOf(f) === -1) { | ||
| t.fail("non-string-literal config used in " + f + ":" + i) | ||
| } | ||
| }) | ||
| }) | ||
| }) | ||
| t.pass("got lines") | ||
| t.end() | ||
| }) | ||
|
|
||
| test("get docs", function (t) { | ||
| var d = fs.readFileSync(doc, "utf8").split("\n") | ||
| // walk down until the "## Config Settings" section | ||
| for (var i = 0; i < d.length && d[i] !== "## Config Settings"; i++); | ||
| i++ | ||
| // now gather up all the ^###\s lines until the next ^##\s | ||
| var doclines = [] | ||
| for (; i < d.length && !d[i].match(/^## /); i++) { | ||
| if (d[i].match(/^### /)) | ||
| DOC[ d[i].replace(/^### /, '').trim() ] = true | ||
| } | ||
| t.pass("read the docs") | ||
| console.error(DOC) | ||
| t.end() | ||
| }) | ||
|
|
||
| test("check configs", function (t) { | ||
| var defs = require("npmconf/config-defs.js") | ||
| var types = Object.keys(defs.types) | ||
| var defaults = Object.keys(defs.defaults) | ||
|
|
||
| for (var c in CONFS) { | ||
| if (CONFS[c].file.indexOf(lib) === 0) { | ||
| t.ok(DOC[c], "should be documented " + c + " " | ||
| + CONFS[c].file + ":" + CONFS[c].line) | ||
| t.ok(types.indexOf(c) !== -1, "should be defined in npmconf " + c) | ||
| t.ok(defaults.indexOf(c) !== -1, "should have default in npmconf " + c) | ||
| } | ||
| } | ||
|
|
||
| for (var c in DOC) { | ||
| if (c !== "versions" && c !== "version") { | ||
| t.ok(CONFS[c], "config in doc should be used somewhere " + c) | ||
| t.ok(types.indexOf(c) !== -1, "should be defined in npmconf " + c) | ||
| t.ok(defaults.indexOf(c) !== -1, "should have default in npmconf " + c) | ||
| } | ||
| } | ||
|
|
||
| types.forEach(function(c) { | ||
| if (!c.match(/^\_/) && c !== 'argv' && !c.match(/^versions?$/)) { | ||
| t.ok(DOC[c], 'defined type should be documented ' + c) | ||
| t.ok(CONFS[c], 'defined type should be used ' + c) | ||
| } | ||
| }) | ||
|
|
||
| defaults.forEach(function(c) { | ||
| if (!c.match(/^\_/) && c !== 'argv' && !c.match(/^versions?$/)) { | ||
| t.ok(DOC[c], 'defaulted type should be documented ' + c) | ||
| t.ok(CONFS[c], 'defaulted type should be used ' + c) | ||
| } | ||
| }) | ||
|
|
||
| t.end() | ||
| }) |
| @@ -0,0 +1,71 @@ | ||
| var test = require("tap").test | ||
| var npm = require.resolve("../../bin/npm-cli.js") | ||
|
|
||
| var spawn = require("child_process").spawn | ||
| var node = process.execPath | ||
|
|
||
| // ignore-scripts/package.json has scripts that always exit with non-zero error | ||
| // codes. The "install" script is omitted so that npm tries to run node-gyp, | ||
| // which should also fail. | ||
| var pkg = __dirname + "/ignore-scripts" | ||
|
|
||
| test("ignore-scripts: install using the option", function(t) { | ||
| createChild([npm, "install", "--ignore-scripts"]).on("close", function(code) { | ||
| t.equal(code, 0) | ||
| t.end() | ||
| }) | ||
| }) | ||
|
|
||
| test("ignore-scripts: install NOT using the option", function(t) { | ||
| createChild([npm, "install"]).on("close", function(code) { | ||
| t.notEqual(code, 0) | ||
| t.end() | ||
| }) | ||
| }) | ||
|
|
||
| var scripts = [ | ||
| "prepublish", "publish", "postpublish", | ||
| "preinstall", "install", "postinstall", | ||
| "preuninstall", "uninstall", "postuninstall", | ||
| "preupdate", "update", "postupdate", | ||
| "pretest", "test", "posttest", | ||
| "prestop", "stop", "poststop", | ||
| "prestart", "start", "poststart", | ||
| "prerestart", "restart", "postrestart" | ||
| ] | ||
|
|
||
| scripts.forEach(function(script) { | ||
| test("ignore-scripts: run-script"+script+" using the option", function(t) { | ||
| createChild([npm, "--ignore-scripts", "run-script", script]) | ||
| .on("close", function(code) { | ||
| t.equal(code, 0) | ||
| t.end() | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| scripts.forEach(function(script) { | ||
| test("ignore-scripts: run-script "+script+" NOT using the option", function(t) { | ||
| createChild([npm, "run-script", script]).on("close", function(code) { | ||
| t.notEqual(code, 0) | ||
| t.end() | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| function createChild (args) { | ||
| var env = { | ||
| HOME: process.env.HOME, | ||
| Path: process.env.PATH, | ||
| PATH: process.env.PATH | ||
| } | ||
|
|
||
| if (process.platform === "win32") | ||
| env.npm_config_cache = "%APPDATA%\\npm-cache" | ||
|
|
||
| return spawn(node, args, { | ||
| cwd: pkg, | ||
| stdio: "inherit", | ||
| env: env | ||
| }) | ||
| } |
| @@ -0,0 +1 @@ | ||
| bad_binding_file |
| @@ -0,0 +1,30 @@ | ||
| { | ||
| "author": "Milton the Aussie", | ||
| "name": "ignore-scripts", | ||
| "version": "0.0.0", | ||
| "scripts": { | ||
| "prepublish": "exit 123", | ||
| "publish": "exit 123", | ||
| "postpublish": "exit 123", | ||
| "preinstall": "exit 123", | ||
| "postinstall": "exit 123", | ||
| "preuninstall": "exit 123", | ||
| "uninstall": "exit 123", | ||
| "postuninstall": "exit 123", | ||
| "preupdate": "exit 123", | ||
| "update": "exit 123", | ||
| "postupdate": "exit 123", | ||
| "pretest": "exit 123", | ||
| "test": "exit 123", | ||
| "posttest": "exit 123", | ||
| "prestop": "exit 123", | ||
| "stop": "exit 123", | ||
| "poststop": "exit 123", | ||
| "prestart": "exit 123", | ||
| "start": "exit 123", | ||
| "poststart": "exit 123", | ||
| "prerestart": "exit 123", | ||
| "restart": "exit 123", | ||
| "postrestart": "exit 123" | ||
| } | ||
| } |
| @@ -0,0 +1,72 @@ | ||
| var test = require("tap").test | ||
| var rimraf = require("rimraf") | ||
|
|
||
| var mr = require("npm-registry-mock") | ||
|
|
||
| var spawn = require("child_process").spawn | ||
| var npm = require.resolve("../../bin/npm-cli.js") | ||
| var node = process.execPath | ||
| var pkg = "./url-dependencies" | ||
|
|
||
| var mockRoutes = { | ||
| "get": { | ||
| "/underscore/-/underscore-1.3.1.tgz": [200] | ||
| } | ||
| } | ||
|
|
||
| test("url-dependencies: download first time", function(t) { | ||
| rimraf.sync(__dirname + "/url-dependencies/node_modules") | ||
|
|
||
| performInstall(function(output){ | ||
| if(!tarballWasFetched(output)){ | ||
| t.fail("Tarball was not fetched") | ||
| }else{ | ||
| t.pass("Tarball was fetched") | ||
| } | ||
| t.end() | ||
| }) | ||
| }) | ||
|
|
||
| test("url-dependencies: do not download subsequent times", function(t) { | ||
| rimraf.sync(__dirname + "/url-dependencies/node_modules") | ||
|
|
||
| performInstall(function(){ | ||
| performInstall(function(output){ | ||
| if(tarballWasFetched(output)){ | ||
| t.fail("Tarball was fetched second time around") | ||
| }else{ | ||
| t.pass("Tarball was not fetched") | ||
| } | ||
| t.end() | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| function tarballWasFetched(output){ | ||
| return output.indexOf("http GET http://localhost:1337/underscore/-/underscore-1.3.1.tgz") > -1 | ||
| } | ||
|
|
||
| function performInstall (cb) { | ||
| mr({port: 1337, mocks: mockRoutes}, function(s){ | ||
| var output = "" | ||
| , child = spawn(node, [npm, "install"], { | ||
| cwd: pkg, | ||
| env: { | ||
| npm_config_registry: "http://localhost:1337", | ||
| npm_config_cache_lock_stale: 1000, | ||
| npm_config_cache_lock_wait: 1000, | ||
| HOME: process.env.HOME, | ||
| Path: process.env.PATH, | ||
| PATH: process.env.PATH | ||
| } | ||
| }) | ||
|
|
||
| child.stderr.on("data", function(data){ | ||
| output += data.toString() | ||
| }) | ||
| child.on("close", function () { | ||
| s.close() | ||
| cb(output) | ||
| }) | ||
| }) | ||
| } |
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "author": "Steve Mason", | ||
| "name": "url-dependencies", | ||
| "version": "0.0.0", | ||
| "dependencies": { | ||
| "underscore": "http://localhost:1337/underscore/-/underscore-1.3.1.tgz" | ||
| } | ||
| } |