Added some tests
This commit is contained in:
93
tests/node_modules/tap-spec/test/e2e/index.js
generated
vendored
Normal file
93
tests/node_modules/tap-spec/test/e2e/index.js
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tapes');
|
||||
var fs = require('fs');
|
||||
var _ = require('lodash');
|
||||
var path = require('path');
|
||||
var okTestPath = path.resolve(__dirname, '..', 'fixtures', 'ok.txt');
|
||||
var notOkTestPath = path.resolve(__dirname, '..', 'fixtures', 'not-ok.txt');
|
||||
var format = require('chalk');
|
||||
var symbols = {
|
||||
ok: '\u2713',
|
||||
err: '\u2717'
|
||||
};
|
||||
var tapSpec = null;
|
||||
var actual = null;
|
||||
|
||||
|
||||
test('e2e test', function(t) {
|
||||
t.beforeEach(function(t) {
|
||||
actual = '';
|
||||
tapSpec = require('../../')();
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test('ok test output', function(t) {
|
||||
t.plan(1);
|
||||
var testOutStream = fs.createReadStream(okTestPath);
|
||||
var expected = ' '.repeat(2) + 'beep\n' +
|
||||
' '.repeat(4) + format.green(symbols.ok) + ' ' + format.gray('should be equal') + '\n' +
|
||||
' '.repeat(4) + format.green(symbols.ok) + ' ' + format.gray('should be equivalent') + '\n' +
|
||||
' '.repeat(2) + 'boop\n' +
|
||||
' '.repeat(4) + format.green(symbols.ok) + ' ' + format.gray('should be equal') + '\n' +
|
||||
' '.repeat(4) + format.green(symbols.ok) + ' ' + format.gray('(unnamed assert)') + '\n' +
|
||||
' '.repeat(2) + 'total:' + ' '.repeat(5) + '4\n' +
|
||||
format.green(' '.repeat(2) + 'passing:' + ' '.repeat(3) + 4) + '\n' +
|
||||
' '.repeat(2) + format.green.bold('All tests pass!');
|
||||
|
||||
testOutStream.pipe(tapSpec);
|
||||
tapSpec.on('data', function(data) {
|
||||
actual += data.toString();
|
||||
});
|
||||
|
||||
testOutStream.on('end', function() {
|
||||
t.deepEqual(normalize(actual, 1), expected, 'Format ok-test output.');
|
||||
});
|
||||
});
|
||||
|
||||
t.test('not ok test output', function(t) {
|
||||
t.plan(1);
|
||||
var testOutStream = fs.createReadStream(notOkTestPath);
|
||||
var expected = ' '.repeat(2) + 'THIS IS A SUITE\n' +
|
||||
' '.repeat(2) + 'test 1\n' +
|
||||
' '.repeat(4) + format.green(symbols.ok) + ' ' + format.gray('this test should pass') + '\n' +
|
||||
' '.repeat(2) + 'test 2\n' +
|
||||
' '.repeat(4) + format.red(symbols.err) + ' ' + format.gray('this test should fail') + '\n' +
|
||||
' '.repeat(3) + format.yellow(' ---') + '\n' +
|
||||
' '.repeat(3) + format.yellow(' operator: ok') + '\n' +
|
||||
' '.repeat(3) + format.yellow(' expected: true') + '\n' +
|
||||
' '.repeat(3) + format.yellow(' actual: false') + '\n' +
|
||||
' '.repeat(3) + format.yellow(' at: Test.<anonymous> (/Users/khanh.nguyen/tap-spec/test.js:13:15)') + '\n' +
|
||||
' '.repeat(3) + format.yellow(' ...') + '\n' +
|
||||
' '.repeat(2) + format.red.bold('Failed Tests: ') + 'There was ' + format.red.bold(1) + ' failure\n' +
|
||||
' '.repeat(4) + '3) test 2\n' +
|
||||
' '.repeat(6) + format.red(symbols.err) + ' ' + format.red('this test should fail') + '\n' +
|
||||
' '.repeat(2) + 'total:' + ' '.repeat(5) + '2\n' +
|
||||
format.green(' '.repeat(2) + 'passing:' + ' '.repeat(3) + 1) + '\n' +
|
||||
format.red(' '.repeat(2) + 'failing:' + ' '.repeat(3) + 1);
|
||||
|
||||
testOutStream.pipe(tapSpec);
|
||||
tapSpec.on('data', function(data) {
|
||||
actual += data.toString();
|
||||
});
|
||||
|
||||
testOutStream.on('end', function() {
|
||||
t.deepEqual(normalize(actual, 0), expected, 'Format fail-test output.');
|
||||
});
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
// remove empty lines and 'duration ...' line
|
||||
// durationLinePos is the position of 'duration ...' line counting from the last line.
|
||||
function normalize(data, durationLinePos) {
|
||||
var noEmptyLine = _.filter(data.split('\n'), function(line) { return line.trim().length !== 0; });
|
||||
noEmptyLine.splice(noEmptyLine.length - durationLinePos - 1, 1);
|
||||
return noEmptyLine.join('\n');
|
||||
}
|
||||
|
||||
String.prototype.repeat = function(n) {
|
||||
return new Array(n + 1).join(this);
|
||||
}
|
||||
|
||||
17
tests/node_modules/tap-spec/test/fixtures/not-ok.txt
generated
vendored
Normal file
17
tests/node_modules/tap-spec/test/fixtures/not-ok.txt
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
TAP version 13
|
||||
# THIS IS A SUITE
|
||||
# test 1
|
||||
ok 1 this test should pass
|
||||
# test 2
|
||||
not ok 2 this test should fail
|
||||
---
|
||||
operator: ok
|
||||
expected: true
|
||||
actual: false
|
||||
at: Test.<anonymous> (/Users/khanh.nguyen/tap-spec/test.js:13:15)
|
||||
...
|
||||
|
||||
1..2
|
||||
# tests 2
|
||||
# pass 1
|
||||
# fail 1
|
||||
13
tests/node_modules/tap-spec/test/fixtures/ok.txt
generated
vendored
Normal file
13
tests/node_modules/tap-spec/test/fixtures/ok.txt
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
TAP version 13
|
||||
# beep
|
||||
ok 1 should be equal
|
||||
ok 2 should be equivalent
|
||||
# boop
|
||||
ok 3 should be equal
|
||||
ok 4 (unnamed assert)
|
||||
|
||||
1..4
|
||||
# tests 4
|
||||
# pass 4
|
||||
|
||||
# ok
|
||||
81
tests/node_modules/tap-spec/test/unit/index.js
generated
vendored
Normal file
81
tests/node_modules/tap-spec/test/unit/index.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
var ts = require('../..');
|
||||
var test = require('tapes');
|
||||
var format = require('chalk');
|
||||
var symbols = {
|
||||
ok: '\u2713',
|
||||
err: '\u2717'
|
||||
};
|
||||
var rs = null;
|
||||
var actual = null;
|
||||
var tapSpec = null;
|
||||
|
||||
test('unit test', function(t) {
|
||||
t.beforeEach(function(t) {
|
||||
rs = require('stream').Readable();
|
||||
rs._read = function noop() {};
|
||||
actual = '';
|
||||
tapSpec = ts();
|
||||
tapSpec.on('data', function(data) {
|
||||
actual += data.toString();
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test('Parsing comment', function(t) {
|
||||
t.plan(1);
|
||||
var comment = '# This is a comment\n';
|
||||
var expected = '\n This is a comment\n\n';
|
||||
|
||||
rs.on('end', function() {
|
||||
t.equal(actual, expected, 'Should format comment correctly.');
|
||||
});
|
||||
|
||||
rs.pipe(tapSpec);
|
||||
rs.push(comment);
|
||||
rs.push(null);
|
||||
});
|
||||
|
||||
t.test('Assert ok', function(t) {
|
||||
t.plan(1);
|
||||
var assert = 'ok 1 this is an ok assertion\n';
|
||||
var expected = ' ' + format.green(symbols.ok) + ' ' + format.gray('this is an ok assertion') + '\n';
|
||||
|
||||
rs.on('end', function() {
|
||||
t.equal(actual, expected, 'Should format ok assertion correctly.');
|
||||
});
|
||||
|
||||
rs.pipe(tapSpec);
|
||||
rs.push(assert);
|
||||
rs.push(null);
|
||||
});
|
||||
|
||||
t.test('Assert not ok', function(t) {
|
||||
t.plan(1);
|
||||
var assert = 'not ok 1 this is a not-ok assertion\n';
|
||||
var expected = ' ' + format.red(symbols.err) + ' ' + format.gray('this is a not-ok assertion') + '\n';
|
||||
|
||||
rs.on('end', function() {
|
||||
t.equal(actual, expected, 'Should format not-ok assertion correctly.');
|
||||
});
|
||||
|
||||
rs.pipe(tapSpec);
|
||||
rs.push(assert);
|
||||
rs.push(null);
|
||||
});
|
||||
|
||||
t.test('Extra', function(t) {
|
||||
t.plan(1);
|
||||
var extra = 'something extra that does not match any other regex\n';
|
||||
var expected = ' ' + format.yellow('something extra that does not match any other regex') + '\n';
|
||||
|
||||
rs.on('end', function() {
|
||||
t.equal(actual, expected, 'Should format extra correctly.');
|
||||
});
|
||||
|
||||
rs.pipe(tapSpec);
|
||||
rs.push(extra);
|
||||
rs.push(null);
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
Reference in New Issue
Block a user