From 1f70215ffe4ac70669f918dd520aa9c49d6d865b Mon Sep 17 00:00:00 2001 From: Christoph Witzko Date: Fri, 15 May 2015 19:29:53 +0200 Subject: [PATCH] test(pre): verification hook --- tests/index.js | 1 + tests/lib/custom-verification.js | 5 +++ tests/scenarios/custom-verification.js | 45 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 tests/lib/custom-verification.js create mode 100644 tests/scenarios/custom-verification.js diff --git a/tests/index.js b/tests/index.js index 60b522b6..0ac096cb 100644 --- a/tests/index.js +++ b/tests/index.js @@ -5,6 +5,7 @@ var test = require('tape') var createModule = require('./lib/create-module') require('./scenarios/custom-analyzer')(test, createModule) +require('./scenarios/custom-verification')(test, createModule) require('./scenarios/ignore')(test, createModule) require('./scenarios/prepublish')(test, createModule) require('./scenarios/postpublish')(test, createModule) diff --git a/tests/lib/custom-verification.js b/tests/lib/custom-verification.js new file mode 100644 index 00000000..aae19461 --- /dev/null +++ b/tests/lib/custom-verification.js @@ -0,0 +1,5 @@ +'use strict' + +module.exports = function (opts, cb) { + cb(null, !(opts.commits.length % 2)) +} diff --git a/tests/scenarios/custom-verification.js b/tests/scenarios/custom-verification.js new file mode 100644 index 00000000..d9b05879 --- /dev/null +++ b/tests/scenarios/custom-verification.js @@ -0,0 +1,45 @@ +'use strict' + +var path = require('path') + +var efh = require('error-first-handler') +var nixt = require('nixt') + +module.exports = function (test, createModule) { + createModule({ + release: { + verification: path.join(__dirname, '../lib/custom-verification') + } + }, efh()(function (name, cwd) { + test('custom-verification', function (t) { + t.test('even commit count', function (t) { + t.plan(1) + nixt() + .cwd(cwd) + .env('CI', true) + .env('npm_config_registry', 'http://127.0.0.1:4873/') + .exec('git commit --allow-empty -m "feat: commit"') + .run('npm run prepublish') + .code(0) + .end(function (err) { + t.error(err, 'nixt') + }) + }) + + t.test('odd commit count', function (t) { + t.plan(1) + nixt() + .cwd(cwd) + .env('CI', true) + .env('npm_config_registry', 'http://127.0.0.1:4873/') + .exec('git commit --allow-empty -m "feat: commit"') + .run('npm run prepublish') + .code(1) + .stdout(/Verification failed/) + .end(function (err) { + t.error(err, 'nixt') + }) + }) + }) + })) +}