From 3799ad0cb6ad1af1b90c81c1e57d27d082492a43 Mon Sep 17 00:00:00 2001 From: Christoph Witzko Date: Thu, 5 Feb 2015 01:01:45 +0100 Subject: [PATCH] test(postpublish): initial scenario --- tests/index.js | 1 + tests/lib/create-module.js | 4 +-- tests/scenarios/postpublish.js | 57 ++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 tests/scenarios/postpublish.js diff --git a/tests/index.js b/tests/index.js index 66d04e60..52b0a38d 100644 --- a/tests/index.js +++ b/tests/index.js @@ -6,3 +6,4 @@ var createModule = require('./lib/create-module') require('./scenarios/install')(test, createModule) require('./scenarios/prepublish')(test, createModule) +require('./scenarios/postpublish')(test, createModule) diff --git a/tests/lib/create-module.js b/tests/lib/create-module.js index 5b5f32df..3dc77e73 100644 --- a/tests/lib/create-module.js +++ b/tests/lib/create-module.js @@ -7,10 +7,10 @@ var efh = require('error-first-handler') var defaults = require('lodash.defaults') var uid = require('nano-uid')() -module.exports = function (pkg) { +module.exports = function (input) { var cb = Array.prototype.pop.call(arguments) uid.generate(5, efh(cb)(function (id) { - var pkg = defaults((typeof pkg === 'object' ? pkg : {}), { + var pkg = defaults((typeof input === 'object' ? input : {}), { name: id, version: '0.0.0', devDependencies: { diff --git a/tests/scenarios/postpublish.js b/tests/scenarios/postpublish.js new file mode 100644 index 00000000..f0905086 --- /dev/null +++ b/tests/scenarios/postpublish.js @@ -0,0 +1,57 @@ +'use strict' + +var efh = require('error-first-handler') +var GitHubApi = require('github') +var nixt = require('nixt') + +var github = new GitHubApi({ + version: '3.0.0', + port: 4343, + protocol: 'http', + host: '127.0.0.1' +}) + +github.authenticate({ + type: 'oauth', + token: '***' +}) + +module.exports = function (test, createModule) { + createModule({ + version: '2.0.0', + repository: { + type: 'git', + url: 'http://github.com/user/repo' + } + }, efh()(function (name, cwd) { + test('postpublish', function (t) { + t.test('publish new version to github releases', function (t) { + t.plan(1) + + nixt() + .cwd(cwd) + .env('CI', true) + .env('GH_URL', 'http://127.0.0.1:4343/') + .env('GH_TOKEN', '***') + .exec('git commit --allow-empty -m "feat(cool): the next big thing"') + .run('npm run postpublish') + .code(0) + .stdout(/> semantic-release post\n\nGenerating changelog from.*\nParsed/m) + .end(function(err) { + t.error(err, 'nixt') + }) + }) + + t.test('correct data published', function (t) { + t.plan(4) + + github.releases.getRelease({ owner: 'user', repo: 'repo', id: 1}, function (err, res) { + t.error(err, 'github') + t.is(res.tag_name, 'v2.0.0', 'version') + t.is(res.author.login, 'user', 'user') + t.ok(/\n\n\n#### Features\n\n\* \*\*cool:\*\* the next big thing/.test(res.body), 'body') + }) + }) + }) + })) +}