diff options
Diffstat (limited to 'deps/npm/node_modules/npm-registry-client/test/publish.js')
-rw-r--r-- | deps/npm/node_modules/npm-registry-client/test/publish.js | 176 |
1 files changed, 88 insertions, 88 deletions
diff --git a/deps/npm/node_modules/npm-registry-client/test/publish.js b/deps/npm/node_modules/npm-registry-client/test/publish.js index 5a87b64c09e..f2c257e95c3 100644 --- a/deps/npm/node_modules/npm-registry-client/test/publish.js +++ b/deps/npm/node_modules/npm-registry-client/test/publish.js @@ -1,125 +1,125 @@ -var test = require("tap").test -var crypto = require("crypto") -var fs = require("fs") +var test = require('tap').test +var crypto = require('crypto') +var fs = require('fs') -var server = require("./lib/server.js") -var common = require("./lib/common.js") +var server = require('./lib/server.js') +var common = require('./lib/common.js') var client = common.freshClient() function nop () {} -var URI = "http://localhost:1337/" -var USERNAME = "username" -var PASSWORD = "%1234@asdf%" -var EMAIL = "i@izs.me" -var METADATA = require("../package.json") -var ACCESS = "public" +var URI = 'http://localhost:1337/' +var USERNAME = 'username' +var PASSWORD = '%1234@asdf%' +var EMAIL = 'i@izs.me' +var METADATA = require('../package.json') +var ACCESS = 'public' // not really a tarball, but doesn't matter -var BODY_PATH = require.resolve("../package.json") -var BODY = fs.createReadStream(BODY_PATH, "base64") -var AUTH = { - username : USERNAME, - password : PASSWORD, - email : EMAIL +var BODY_PATH = require.resolve('../package.json') +var BODY = fs.createReadStream(BODY_PATH) +var AUTH = { + username: USERNAME, + password: PASSWORD, + email: EMAIL } -var PARAMS = { - metadata : METADATA, - access : ACCESS, - body : BODY, - auth : AUTH +var PARAMS = { + metadata: METADATA, + access: ACCESS, + body: BODY, + auth: AUTH } -test("publish call contract", function (t) { +test('publish call contract', function (t) { t.throws(function () { client.publish(undefined, PARAMS, nop) - }, "requires a URI") + }, 'requires a URI') t.throws(function () { client.publish([], PARAMS, nop) - }, "requires URI to be a string") + }, 'requires URI to be a string') t.throws(function () { client.publish(URI, undefined, nop) - }, "requires params object") + }, 'requires params object') t.throws(function () { - client.publish(URI, "", nop) - }, "params must be object") + client.publish(URI, '', nop) + }, 'params must be object') t.throws(function () { client.publish(URI, PARAMS, undefined) - }, "requires callback") + }, 'requires callback') t.throws(function () { - client.publish(URI, PARAMS, "callback") - }, "callback must be function") + client.publish(URI, PARAMS, 'callback') + }, 'callback must be function') t.throws( function () { var params = { - access : ACCESS, - body : BODY, - auth : AUTH + access: ACCESS, + body: BODY, + auth: AUTH } client.publish(URI, params, nop) }, - { name : "AssertionError", message : "must pass package metadata to publish" }, - "params must include metadata for package" + { name: 'AssertionError', message: 'must pass package metadata to publish' }, + 'params must include metadata for package' ) t.throws( function () { var params = { - metadata : METADATA, - access : ACCESS, - auth : AUTH + metadata: METADATA, + access: ACCESS, + auth: AUTH } client.publish(URI, params, nop) }, - { name : "AssertionError", message : "must pass package body to publish" }, - "params must include body of package to publish" + { name: 'AssertionError', message: 'must pass package body to publish' }, + 'params must include body of package to publish' ) t.throws( function () { var params = { - metadata : METADATA, - access : ACCESS, - body : BODY + metadata: METADATA, + access: ACCESS, + body: BODY } client.publish(URI, params, nop) }, - { name : "AssertionError", message : "must pass auth to publish" }, - "params must include auth" + { name: 'AssertionError', message: 'must pass auth to publish' }, + 'params must include auth' ) t.throws( function () { var params = { - metadata : -1, - access : ACCESS, - body : BODY, - auth : AUTH + metadata: -1, + access: ACCESS, + body: BODY, + auth: AUTH } client.publish(URI, params, nop) }, - { name : "AssertionError", message : "must pass package metadata to publish" }, - "metadata must be object" + { name: 'AssertionError', message: 'must pass package metadata to publish' }, + 'metadata must be object' ) t.throws( function () { var params = { - metadata : METADATA, - access : "hamchunx", - body : BODY, - auth : AUTH + metadata: METADATA, + access: 'hamchunx', + body: BODY, + auth: AUTH } client.publish(URI, params, nop) }, { - name : "AssertionError", - message : "if present, access level must be either 'public' or 'restricted'" + name: 'AssertionError', + message: "if present, access level must be either 'public' or 'restricted'" }, "access level must be 'public' or 'restricted'" ) @@ -127,34 +127,34 @@ test("publish call contract", function (t) { t.throws( function () { var params = { - metadata : METADATA, - access : ACCESS, - body : -1, - auth : AUTH + metadata: METADATA, + access: ACCESS, + body: -1, + auth: AUTH } client.publish(URI, params, nop) }, { - name : "AssertionError", - message : "package body passed to publish must be a stream" + name: 'AssertionError', + message: 'package body passed to publish must be a stream' }, - "body must be a Stream" + 'body must be a Stream' ) - t.test("malformed semver in publish", function (t) { + t.test('malformed semver in publish', function (t) { var metadata = JSON.parse(JSON.stringify(METADATA)) - metadata.version = "%!@#$" + metadata.version = '%!@#$' var params = { - metadata : metadata, - access : ACCESS, - message : BODY, - auth : AUTH + metadata: metadata, + access: ACCESS, + message: BODY, + auth: AUTH } client.publish(URI, params, function (err) { t.equal( err && err.message, - "invalid semver: %!@#$", - "got expected semver validation failure" + 'invalid semver: %!@#$', + 'got expected semver validation failure' ) t.end() }) @@ -163,41 +163,41 @@ test("publish call contract", function (t) { t.end() }) -test("publish", function (t) { - var pd = fs.readFileSync(BODY_PATH, "base64") +test('publish', function (t) { + var pd = fs.readFileSync(BODY_PATH, 'base64') - server.expect("/npm-registry-client", function (req, res) { - t.equal(req.method, "PUT") - var b = "" - req.setEncoding("utf8") - req.on("data", function (d) { + server.expect('/npm-registry-client', function (req, res) { + t.equal(req.method, 'PUT') + var b = '' + req.setEncoding('utf8') + req.on('data', function (d) { b += d }) - req.on("end", function () { + req.on('end', function () { var o = JSON.parse(b) - t.equal(o._id, "npm-registry-client") - t.equal(o["dist-tags"].latest, METADATA.version) + t.equal(o._id, 'npm-registry-client') + t.equal(o['dist-tags'].latest, METADATA.version) t.equal(o.access, ACCESS) t.has(o.versions[METADATA.version], METADATA) - t.same(o.maintainers, [{ name : "username", email : "i@izs.me" }]) + t.same(o.maintainers, [{ name: 'username', email: 'i@izs.me' }]) t.same(o.maintainers, o.versions[METADATA.version].maintainers) - var att = o._attachments[METADATA.name+"-"+METADATA.version+".tgz"] + var att = o._attachments[METADATA.name + '-' + METADATA.version + '.tgz'] t.same(att.data, pd) - var hash = crypto.createHash("sha1").update(pd, "base64").digest("hex") + var hash = crypto.createHash('sha1').update(pd, 'base64').digest('hex') t.equal(o.versions[METADATA.version].dist.shasum, hash) res.statusCode = 201 - res.json({ created : true }) + res.json({ created: true }) }) }) client.publish(URI, PARAMS, function (er, data) { if (er) throw er - t.deepEqual(data, { created : true }) + t.deepEqual(data, { created: true }) t.end() }) }) |