diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2014-09-13 09:44:40 +0400 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2014-09-13 09:44:40 +0400 |
commit | f6187eb5454e5f232cfbc5c2a84ab322b87ef3cc (patch) | |
tree | e91c8ae043f88f67e0c6027d3da375072bd7b67a /test | |
parent | 0b0a59d504f20f424294b1590ace73a7464f0378 (diff) |
reformat test for less oof
Diffstat (limited to 'test')
-rw-r--r-- | test/tap/prepublish.js | 89 |
1 files changed, 43 insertions, 46 deletions
diff --git a/test/tap/prepublish.js b/test/tap/prepublish.js index f80085d92..ad71eab5c 100644 --- a/test/tap/prepublish.js +++ b/test/tap/prepublish.js @@ -1,68 +1,66 @@ // verify that prepublish runs on pack and publish -var test = require('tap').test -var npm = require('../../') -var fs = require('fs') -var pkg = __dirname + '/prepublish_package' -var tmp = pkg + '/tmp' -var cache = pkg + '/cache' -var mkdirp = require('mkdirp') -var rimraf = require('rimraf') -var path = require('path') -var os = require('os') +var test = require("tap").test +var fs = require("graceful-fs") +var join = require("path").join +var mkdirp = require("mkdirp") +var rimraf = require("rimraf") +var path = require("path") -test('setup', function (t) { +var pkg = join(__dirname, "prepublish_package") +var tmp = join(pkg, "tmp") +var cache = join(pkg, "cache") + +test("setup", function (t) { var n = 0 mkdirp(pkg, then()) mkdirp(cache, then()) mkdirp(tmp, then()) - function then (er) { - n ++ + function then () { + n++ return function (er) { - if (er) - throw er - if (--n === 0) - next() + if (er) throw er + if (--n === 0) next() } } function next () { - fs.writeFile(pkg + '/package.json', JSON.stringify({ - name: 'npm-test-prepublish', - version: '1.2.5', - scripts: { prepublish: 'echo ok' } - }), 'ascii', function (er) { - if (er) - throw er - t.pass('setup done') + fs.writeFile(join(pkg, "package.json"), JSON.stringify({ + name: "npm-test-prepublish", + version: "1.2.5", + scripts: { prepublish: "echo ok" } + }), "ascii", function (er) { + if (er) throw er + + t.pass("setup done") t.end() }) } }) -test('test', function (t) { - var spawn = require('child_process').spawn +test("test", function (t) { + var spawn = require("child_process").spawn var node = process.execPath - var npm = path.resolve(__dirname, '../../cli.js') + var npm = path.resolve(__dirname, "../../cli.js") var env = { - npm_config_cache: cache, - npm_config_tmp: tmp, - npm_config_prefix: pkg, - npm_config_global: 'false' + "npm_config_cache" : cache, + "npm_config_tmp" : tmp, + "npm_config_prefix" : pkg, + "npm_config_global" : "false" } for (var i in process.env) { if (!/^npm_config_/.test(i)) env[i] = process.env[i] } - var child = spawn(node, [npm, 'pack'], { + var child = spawn(node, [npm, "pack"], { cwd: pkg, env: env }) - child.stdout.setEncoding('utf8') - child.stderr.on('data', onerr) - child.stdout.on('data', ondata) - child.on('close', onend) - var c = '' - , e = '' + child.stdout.setEncoding("utf8") + child.stderr.on("data", onerr) + child.stdout.on("data", ondata) + child.on("close", onend) + var c = "" + , e = "" function ondata (chunk) { c += chunk } @@ -71,7 +69,7 @@ test('test', function (t) { } function onend () { if (e) { - throw new Error('got stderr data: ' + JSON.stringify('' + e)) + throw new Error("got stderr data: " + JSON.stringify("" + e)) } c = c.trim() var regex = new RegExp("" + @@ -86,12 +84,11 @@ test('test', function (t) { } }) -test('cleanup', function (t) { - rimraf(pkg, function(er) { - if (er) - throw er - t.pass('cleaned up') +test("cleanup", function (t) { + rimraf(pkg, function (er) { + if (er) throw er + + t.pass("cleaned up") t.end() }) }) - |