diff --git a/ass-stubs/cli-test.js b/ass-stubs/cli-test.js index 7c4e760..7974c67 100644 --- a/ass-stubs/cli-test.js +++ b/ass-stubs/cli-test.js @@ -1 +1 @@ -require('ass'); require('../gh-badge.js'); +require('../gh-badge.js'); diff --git a/package.json b/package.json index dab3659..8428e98 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "mocha": "~1.14.0" }, "scripts": { - "test": "mocha -R spec test.js" + "test": "node test.js" }, "bin": { "badge": "./gh-badge.js" }, "files": [ diff --git a/test.js b/test.js index 5aec33e..cdec1fe 100644 --- a/test.js +++ b/test.js @@ -1,151 +1,145 @@ -var ass = require('ass').enable(); -var should = require('should'); - +var assertion = require('assert'); var http = require('http'); var cproc = require('child_process'); var fs = require('fs'); -describe('the CLI', function() { - it('should provide a help message', function(done) { +function test(target, tests) { + var wrappedTests = tests.map(function(test) { + return function() { + var desc = test[0]; + var f = test[1]; + return new Promise(function(resolve, reject) { + var assert = function(pred, msg) { assert.ok(pred, msg); }; + ['ok', 'equal', 'deepEqual', 'strictEqual', 'deepStrictEqual', + 'notEqual', 'notDeepEqual', 'notStrictEqual', 'notDeepStrictEqual', + 'fail', 'doesNotThrow', 'throws', + ].forEach(function(k) { + assert[k] = function(...args) { + try { + assertion[k].apply(null, args); + } catch(e) { reject(e); } + }; + }); + f(resolve, assert); + }).catch(function(e) { + console.error('Failed:', target + ' ' + desc + '\n', e.stack); + }); + }; + }); + var prom = wrappedTests[0](); + for (var i = 1; i < wrappedTests.length; i++) { + prom = prom.then(wrappedTests[i]); + } + return prom; +} + +// Test parameters +var port = '1111'; +var url = 'http://127.0.0.1:' + port + '/'; +var server; + +test('The CLI', [ + ['should provide a help message', function(done, assert) { var child = cproc.spawn('node', ['ass-stubs/cli-test.js']); var buffer = ''; child.stdout.on('data', function(chunk) { buffer += ''+chunk; }); child.stdout.on('end', function() { - buffer.should.startWith('Usage'); + assert(buffer.startsWith('Usage')); done(); }); - }); - it('should produce default badges', function(done) { + }], + ['should produce default badges', function(done, assert) { var child = cproc.spawn('node', ['ass-stubs/cli-test.js', 'cactus', 'grown']); child.stdout.on('data', function(chunk) { var buffer = ''+chunk; - buffer.should.startWith('= 0 && !isDone) { done(); isDone = true; } }); server.stderr.on('data', function(data) { console.log(''+data); }); - }); - - it('should produce colorscheme badges', function(done) { + }], + ['should produce colorscheme badges', function(done, assert) { http.get(url + ':fruit-apple-green.svg', function(res) { var buffer = ''; res.on('data', function(chunk) { buffer += ''+chunk; }); res.on('end', function() { - buffer.should.startWith('