diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-03-06 02:57:32 -0600 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2015-03-06 11:20:05 -0500 |
commit | fe14802fb700c5fea08b7c54f4298c3ac44a5c15 (patch) | |
tree | 74b43bf61e98f366089a416e4fe36b2f1256cd5d /deps/npm/test/tap/run-script.js | |
parent | c09c90c1a9e74ee4f29a051daf10bc4c5d5f7755 (diff) | |
download | android-node-v8-fe14802fb700c5fea08b7c54f4298c3ac44a5c15.tar.gz android-node-v8-fe14802fb700c5fea08b7c54f4298c3ac44a5c15.tar.bz2 android-node-v8-fe14802fb700c5fea08b7c54f4298c3ac44a5c15.zip |
deps: upgrade npm to 2.7.0
PR-URL: https://github.com/iojs/io.js/pull/1080
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'deps/npm/test/tap/run-script.js')
-rw-r--r-- | deps/npm/test/tap/run-script.js | 228 |
1 files changed, 177 insertions, 51 deletions
diff --git a/deps/npm/test/tap/run-script.js b/deps/npm/test/tap/run-script.js index 6b5ce26aa4..35790684f5 100644 --- a/deps/npm/test/tap/run-script.js +++ b/deps/npm/test/tap/run-script.js @@ -1,12 +1,17 @@ -var common = require("../common-tap") - , test = require("tap").test - , path = require("path") - , rimraf = require("rimraf") - , mkdirp = require("mkdirp") - , pkg = path.resolve(__dirname, "run-script") - , cache = path.resolve(pkg, "cache") - , tmp = path.resolve(pkg, "tmp") - , opts = { cwd: pkg } +var fs = require('fs') +var path = require('path') + +var mkdirp = require('mkdirp') +var test = require('tap').test +var rimraf = require('rimraf') + +var common = require('../common-tap') + +var pkg = path.resolve(__dirname, 'run-script') +var cache = path.resolve(pkg, 'cache') +var tmp = path.resolve(pkg, 'tmp') + +var opts = { cwd: pkg } function testOutput (t, command, er, code, stdout, stderr) { var lines @@ -15,95 +20,216 @@ function testOutput (t, command, er, code, stdout, stderr) { throw er if (stderr) - throw new Error("npm " + command + " stderr: " + stderr.toString()) + throw new Error('npm ' + command + ' stderr: ' + stderr.toString()) - lines = stdout.trim().split("\n") - stdout = lines.filter(function(line) { - return line.trim() !== "" && line[0] !== ">" - }).join(";") + lines = stdout.trim().split('\n') + stdout = lines.filter(function (line) { + return line.trim() !== '' && line[0] !== '>' + }).join(';') t.equal(stdout, command) t.end() } +function writeMetadata (object) { + fs.writeFileSync( + path.resolve(pkg, 'package.json'), + JSON.stringify(object, null, 2) + '\n' + ) +} + function cleanup () { - rimraf.sync(cache) - rimraf.sync(tmp) + rimraf.sync(pkg) } -test("setup", function (t) { +test('setup', function (t) { cleanup() mkdirp.sync(cache) mkdirp.sync(tmp) + writeMetadata(fullyPopulated) t.end() }) -test("npm run-script", function (t) { - common.npm(["run-script", "start"], opts, testOutput.bind(null, t, "start")) +var fullyPopulated = { + 'name': 'runscript', + 'version': '1.2.3', + 'scripts': { + 'start': 'node -e "console.log(process.argv[1] || \'start\')"', + 'prewith-pre': 'node -e "console.log(process.argv[1] || \'pre\')"', + 'with-pre': 'node -e "console.log(process.argv[1] || \'main\')"', + 'with-post': 'node -e "console.log(process.argv[1] || \'main\')"', + 'postwith-post': 'node -e "console.log(process.argv[1] || \'post\')"', + 'prewith-both': 'node -e "console.log(process.argv[1] || \'pre\')"', + 'with-both': 'node -e "console.log(process.argv[1] || \'main\')"', + 'postwith-both': 'node -e "console.log(process.argv[1] || \'post\')"', + 'stop': 'node -e "console.log(process.argv[1] || \'stop\')"' + } +} + +var lifecycleOnly = { + name: 'scripted', + version: '1.2.3', + scripts: { + 'prestart': 'echo prestart' + } +} + +var directOnly = { + name: 'scripted', + version: '1.2.3', + scripts: { + 'whoa': 'echo whoa' + } +} + +var both = { + name: 'scripted', + version: '1.2.3', + scripts: { + 'prestart': 'echo prestart', + 'whoa': 'echo whoa' + } +} + +test('npm run-script start', function (t) { + common.npm(['run-script', 'start'], opts, testOutput.bind(null, t, 'start')) +}) + +test('npm run-script with args', function (t) { + common.npm(['run-script', 'start', '--', 'stop'], opts, testOutput.bind(null, t, 'stop')) }) -test("npm run-script with args", function (t) { - common.npm(["run-script", "start", "--", "stop"], opts, testOutput.bind(null, t, "stop")) +test('npm run-script with args that contain spaces', function (t) { + common.npm(['run-script', 'start', '--', 'hello world'], opts, testOutput.bind(null, t, 'hello world')) }) -test("npm run-script with args that contain spaces", function (t) { - common.npm(["run-script", "start", "--", "hello world"], opts, testOutput.bind(null, t, "hello world")) +test('npm run-script with args that contain single quotes', function (t) { + common.npm(['run-script', 'start', '--', 'they"re awesome'], opts, testOutput.bind(null, t, 'they"re awesome')) }) -test("npm run-script with args that contain single quotes", function (t) { - common.npm(["run-script", "start", "--", "they're awesome"], opts, testOutput.bind(null, t, "they're awesome")) +test('npm run-script with args that contain double quotes', function (t) { + common.npm(['run-script', 'start', '--', 'what"s "up"?'], opts, testOutput.bind(null, t, 'what"s "up"?')) }) -test("npm run-script with args that contain double quotes", function (t) { - common.npm(["run-script", "start", "--", "what's \"up\"?"], opts, testOutput.bind(null, t, "what's \"up\"?")) +test('npm run-script with pre script', function (t) { + common.npm(['run-script', 'with-post'], opts, testOutput.bind(null, t, 'main;post')) }) -test("npm run-script with pre script", function (t) { - common.npm(["run-script", "with-post"], opts, testOutput.bind(null, t, "main;post")) +test('npm run-script with post script', function (t) { + common.npm(['run-script', 'with-pre'], opts, testOutput.bind(null, t, 'pre;main')) }) -test("npm run-script with post script", function (t) { - common.npm(["run-script", "with-pre"], opts, testOutput.bind(null, t, "pre;main")) +test('npm run-script with both pre and post script', function (t) { + common.npm(['run-script', 'with-both'], opts, testOutput.bind(null, t, 'pre;main;post')) }) -test("npm run-script with both pre and post script", function (t) { - common.npm(["run-script", "with-both"], opts, testOutput.bind(null, t, "pre;main;post")) +test('npm run-script with both pre and post script and with args', function (t) { + common.npm(['run-script', 'with-both', '--', 'an arg'], opts, testOutput.bind(null, t, 'pre;an arg;post')) }) -test("npm run-script with both pre and post script and with args", function (t) { - common.npm(["run-script", "with-both", "--", "an arg"], opts, testOutput.bind(null, t, "pre;an arg;post")) +test('npm run-script explicitly call pre script with arg', function (t) { + common.npm(['run-script', 'prewith-pre', '--', 'an arg'], opts, testOutput.bind(null, t, 'an arg')) }) -test("npm run-script explicitly call pre script with arg", function (t) { - common.npm(["run-script", "prewith-pre", "--", "an arg"], opts, testOutput.bind(null, t, "an arg")) +test('npm run-script test', function (t) { + common.npm(['run-script', 'test'], opts, function (er, code, stdout, stderr) { + t.ifError(er, 'npm run-script test ran without issue') + t.notOk(stderr, 'should not generate errors') + t.end() + }) +}) + +test('npm run-script env', function (t) { + common.npm(['run-script', 'env'], opts, function (er, code, stdout, stderr) { + t.ifError(er, 'using default env script') + t.notOk(stderr, 'should not generate errors') + t.ok(stdout.indexOf('npm_config_init_version') > 0, 'expected values in var list') + t.end() + }) +}) + +test('npm run-script nonexistent-script', function (t) { + common.npm(['run-script', 'nonexistent-script'], opts, function (er, code, stdout, stderr) { + t.ifError(er, 'npm run-script nonexistent-script did not cause npm to explode') + t.ok(stderr, 'should generate errors') + t.end() + }) +}) + +test('npm run-script restart when there isn\'t restart', function (t) { + common.npm(['run-script', 'restart'], opts, testOutput.bind(null, t, 'stop;start')) +}) + +test('npm run-script nonexistent-script with --if-present flag', function (t) { + common.npm(['run-script', '--if-present', 'nonexistent-script'], opts, function (er, code, stdout, stderr) { + t.ifError(er, 'npm run-script --if-present non-existent-script ran without issue') + t.notOk(stderr, 'should not generate errors') + t.end() + }) }) -test("npm run-script test", function (t) { - common.npm(["run-script", "test"], opts, function (er, code, stdout, stderr) { - t.ifError(er, "npm run-script test ran without issue") - t.notOk(stderr, "should not generate errors") +test('npm run-script no-params (lifecycle only)', function (t) { + var expected = [ + 'Lifecycle scripts included in scripted:', + ' prestart', + ' echo prestart', + '' + ].join('\n') + + writeMetadata(lifecycleOnly) + + common.npm(['run-script'], opts, function (err, code, stdout, stderr) { + t.ifError(err, 'ran run-script without parameters without crashing') + t.notOk(code, 'npm exited without error code') + t.notOk(stderr, 'npm printed nothing to stderr') + t.equal(stdout, expected, 'got expected output') t.end() }) }) -test("npm run-script env", function (t) { - common.npm(["run-script", "env"], opts, function (er, code, stdout, stderr) { - t.ifError(er, "using default env script") - t.notOk(stderr, "should not generate errors") - t.ok( stdout.indexOf("npm_config_init_version") > 0, "expected values in var list" ) +test('npm run-script no-params (direct only)', function (t) { + var expected = [ + 'Scripts available in scripted via `npm run-script`:', + ' whoa', + ' echo whoa', + '' + ].join('\n') + + writeMetadata(directOnly) + + common.npm(['run-script'], opts, function (err, code, stdout, stderr) { + t.ifError(err, 'ran run-script without parameters without crashing') + t.notOk(code, 'npm exited without error code') + t.notOk(stderr, 'npm printed nothing to stderr') + t.equal(stdout, expected, 'got expected output') t.end() }) }) -test("npm run-script nonexistent-script", function (t) { - common.npm(["run-script", "nonexistent-script"], opts, function (er, code, stdout, stderr) { - t.ifError(er, "npm run-script nonexistent-script did not cause npm to explode") - t.ok(stderr, "should generate errors") +test('npm run-script no-params (direct only)', function (t) { + var expected = [ + 'Lifecycle scripts included in scripted:', + ' prestart', + ' echo prestart', + '', + 'available via `npm run-script`:', + ' whoa', + ' echo whoa', + '' + ].join('\n') + + writeMetadata(both) + + common.npm(['run-script'], opts, function (err, code, stdout, stderr) { + t.ifError(err, 'ran run-script without parameters without crashing') + t.notOk(code, 'npm exited without error code') + t.notOk(stderr, 'npm printed nothing to stderr') + t.equal(stdout, expected, 'got expected output') t.end() }) }) -test("cleanup", function (t) { +test('cleanup', function (t) { cleanup() t.end() }) |