diff --git a/test/api.js b/test/api.js index c854d07..6f06604 100644 --- a/test/api.js +++ b/test/api.js @@ -1,5 +1,6 @@ 'use strict'; var path = require('path'); +var figures = require('figures'); var test = require('tap').test; var Api = require('../api'); @@ -36,6 +37,43 @@ test('async/await support', function (t) { }); }); +test('test title prefixes', function (t) { + t.plan(5); + + var separator = ' ' + figures.pointerSmall + ' '; + var files = [ + path.join(__dirname, 'fixture/async-await.js'), + path.join(__dirname, 'fixture/es2015.js'), + path.join(__dirname, 'fixture/generators.js') + ]; + var expected = [ + ['async-await', 'async function'].join(separator), + ['async-await', 'arrow async function'].join(separator), + ['es2015', '[anonymous]'].join(separator), + ['generators', 'generator function'].join(separator) + ]; + var index; + + var api = new Api(files); + + api.run() + .then(function () { + // if all lines were removed from expected output + // actual output matches expected output + t.is(expected.length, 0); + }); + + api.on('test', function (a) { + var unnecessaryString = 'test' + separator + 'fixture' + separator; + index = expected.indexOf(a.title.replace(unnecessaryString, '')); + + t.true(index >= 0); + + // remove line from expected output + expected.splice(index, 1); + }); +}); + test('display filename prefixes for failed test stack traces', function (t) { t.plan(3); diff --git a/test/cli.js b/test/cli.js index 50d05f9..cd18b2a 100644 --- a/test/cli.js +++ b/test/cli.js @@ -1,6 +1,5 @@ 'use strict'; var childProcess = require('child_process'); -var figures = require('figures'); var test = require('tap').test; function execCli(args, cb) { @@ -20,50 +19,6 @@ function execCli(args, cb) { }, cb); } -test('display test title prefixes', function (t) { - t.plan(6); - - execCli([ - 'fixture/async-await.js', - 'fixture/es2015.js', - 'fixture/generators.js' - ], function (err, stdout, stderr) { - t.ifError(err); - - // remove everything except test list - var output = stderr - .replace(/[0-9] tests passed/, '') - .replace(new RegExp(figures.tick, 'gm'), '') - .replace(/^\s+/gm, '') - .trim(); - - var separator = ' ' + figures.pointerSmall + ' '; - - // expected output - var tests = [ - ['async-await', 'async function'].join(separator), - ['async-await', 'arrow async function'].join(separator), - ['generators', 'generator function'].join(separator), - ['es2015', '[anonymous]'].join(separator) - ]; - - // check if each line in actual output - // exists in expected output - output.split('\n').forEach(function (line) { - var index = tests.indexOf(line); - - t.true(index >= 0); - - // remove line from expected output - tests.splice(index, 1); - }); - - // if all lines were removed from expected output - // actual output matches expected output - t.is(tests.length, 0); - }); -}); - test('don\'t display test title if there is only one anonymous test', function (t) { t.plan(2);