Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorForrest L Norvell <forrest@npmjs.com>2015-03-18 06:59:35 +0300
committerForrest L Norvell <forrest@npmjs.com>2015-03-18 06:59:35 +0300
commite013d3156a465f86ac378b2f3898322a530a4f38 (patch)
tree02b38bb224503bd84899df8eb29e00fa87d444f2
parent3703b0b87c127a64649bdbfc3bc697ebccc4aa24 (diff)
test: rework version-message-config for Travis
-rw-r--r--test/tap/version-message-config.js139
1 files changed, 70 insertions, 69 deletions
diff --git a/test/tap/version-message-config.js b/test/tap/version-message-config.js
index d3721aae2..7ce3b4c6b 100644
--- a/test/tap/version-message-config.js
+++ b/test/tap/version-message-config.js
@@ -1,87 +1,88 @@
-var common = require("../common-tap.js")
-var test = require("tap").test
-var osenv = require("osenv")
-var path = require("path")
-var fs = require("fs")
-var rimraf = require("rimraf")
-var mkdirp = require("mkdirp")
-var which = require("which")
-var spawn = require("child_process").spawn
+var common = require('../common-tap.js')
+var fs = require('fs')
+var path = require('path')
-var pkg = path.resolve(__dirname, "version-message-config")
-var opts = { cwd: pkg }
-var cache = path.resolve(pkg, "cache")
-var npmrcPath = path.resolve(pkg, ".npmrc")
-var packagePath = path.resolve(pkg, "package.json")
+var chain = require('slide').chain
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
-test("npm version <semver> with message config", function (t) {
- setup()
- which("git", function (err, git) {
- t.ifError(err, "git found")
+var npm = require('../../lib/npm.js')
+
+var pkg = path.resolve(__dirname, 'version-message-config')
+var cache = path.resolve(pkg, 'cache')
+var npmrc = path.resolve(pkg, '.npmrc')
+var packagePath = path.resolve(pkg, 'package.json')
+
+var json = { name: 'blah', version: '0.1.2' }
- function gitInit(_cb) {
- var child = spawn(git, ["init"])
- var out = ""
- child.stdout.on("data", function (d) {
- out += d.toString()
- })
- child.on("exit", function () {
- return _cb(out)
- })
- }
+var configContents = 'sign-git-tag=false\nmessage=":bookmark: %s"\n'
- function addConfig(_cb) {
- var data = "message = \":bookmark: %s\""
- fs.writeFileSync(npmrcPath, data, "ascii")
- }
+test('npm version <semver> with message config', function (t) {
+ setup()
+
+ npm.load({ prefix: pkg, userconfig: npmrc }, function () {
+ var git = require('../../lib/utils/git.js')
- function addPackageJSON(_cb) {
- var data = JSON.stringify({ name: "blah", version: "0.1.2" })
- fs.writeFileSync(packagePath, data, "ascii")
- }
+ var opts = { cwd: pkg, env: { PATH: process.env.PATH } }
+ chain(
+ [
+ git.chainableExec(['init'], opts),
+ git.chainableExec(['config', 'user.name', 'PhantomFaker'], opts),
+ git.chainableExec(['config', 'user.email', 'nope@not.real'], opts),
+ git.chainableExec(['add', 'package.json'], opts),
+ git.chainableExec(['add', '.npmrc'], opts),
+ git.chainableExec(['commit', '-m', 'stub package'], opts)
+ ],
+ function (er) {
+ t.ifErr(er, 'git bootstrap ran without error')
- function gitLog(_cb) {
- var child = spawn(git, ["log"])
- var out = ""
- child.stdout.on("data", function (d) {
- out += d.toString()
- })
- child.on("exit", function () {
- _cb(out)
- })
- }
+ common.npm(
+ [
+ 'version',
+ 'patch',
+ '--loglevel', 'silent'
+ // package config is picked up from env
+ ],
+ opts,
+ function (err, code, stdout, stderr) {
+ t.ifError(err, 'npm version ran without issue')
+ t.notOk(code, 'exited with a non-error code')
+ t.notOk(stderr, 'no error output')
- gitInit(function() {
- addPackageJSON()
- addConfig()
- common.npm([
- "version",
- "patch",
- "--userconfig=" + npmrcPath
- ],
- opts,
- function (err, code, stdout, stderr) {
- t.ifError(err)
- gitLog(function (log) {
- t.ok(log.match(/:bookmark: 0\.1\.3/g))
- t.end()
- })
- }
- )
- })
+ git.whichAndExec(
+ ['log'],
+ { cwd: pkg, env: process.env },
+ function (er, log, stderr) {
+ t.ok(log.match(/:bookmark: 0\.1\.3/g), 'config was picked up by version')
+ t.end()
+ }
+ )
+ }
+ )
+ }
+ )
})
})
-test("cleanup", function (t) {
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function cleanup () {
// windows fix for locked files
process.chdir(osenv.tmpdir())
rimraf.sync(pkg)
- t.end()
-})
+}
-function setup() {
- mkdirp.sync(pkg)
+function setup () {
+ cleanup()
mkdirp.sync(cache)
process.chdir(pkg)
+
+ fs.writeFileSync(packagePath, JSON.stringify(json), 'utf8')
+ fs.writeFileSync(npmrc, configContents, 'ascii')
}