Added some tests

This commit is contained in:
2021-06-23 22:30:45 +02:00
parent 24f897e907
commit 3d3d7fae48
3796 changed files with 218744 additions and 3 deletions

22
tests/node_modules/tap-out/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2014 Scott Corgan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

216
tests/node_modules/tap-out/README.md generated vendored Normal file
View File

@@ -0,0 +1,216 @@
# tap-out
A different tap parser
## Install
```
npm install tap-out --save
```
## Usage
**CLI**
```
$ something-that-produces-tap | tap-out
{
tests: [
{ name: 'is true', number: 1, raw: '# is true', type: 'test' }
],
asserts: [
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' },
{ name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' }
],
versions: [],
results: [],
comments: [],
plans: [{ type: 'plan', raw: '1..2', from: 1, to: 2, skip: false }],
pass: [
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' },
{ name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' }
],
fail: [],
errors: []
}
```
**API**
```js
var tapOut = require('tap-out');
var t = tapOut(function (output) {
console.log(output);
});
t.on('assert', function (assert) {
// Do something
});
process.stdin.pipe(t);
```
## Methods
### var t = tapOut(function (err, output) {})
Returns a stream that emits events with various TAP data. Takes a callback which is called when all parsing is done.
## Events
### t.on('output', function (output) {})
All output after all TAP data is parsed.
Example output
```js
{
tests: [
{ name: 'is true', number: 1, raw: '# is true', type: 'test' }
],
asserts: [
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' },
{ name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' }
],
results: [],
versions: [],
comments: [],
fail: [],
pass: [
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' },
{ name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' }
],
}
```
### t.on('test', function (test) {})
Parsed test object with details.
* `type` - value will always be `test`
* `name` - name of the test
* `raw` - the raw output before it was parsed
* `number` - the number of the test
```js
{
type: 'test',
name: 'is true',
raw: '# is true',
number: 1
}
```
### t.on('assert', function (assertion) {})
Parsed assert object details.
* `type` - this will always be `assert`
* `name` - the name of the assertion
* `raw` - the raw output before it was parsed
* `number` - the number of the assertion
* `ok` - whether the assertion passed or failed
* `test` - the number of the test this assertion belongs to
```js
{
name: 'true value',
number: 1,
ok: true,
raw: 'ok 1 true value',
test: 1,
type: 'assert'
}
```
### t.on('version', function (version) {})
Parsed version data.
* `type` - this will always be `version`
* `raw` - the raw output before it was parsed
```js
{
raw: 'TAP version 13',
type: 'version'
}
```
### t.on('result', function (result) {})
Parsed test result data for tests, pass, fail.
* `type` - this will always be `result`
* `name` - the name of the result
* `raw` - the raw output before it was parsed
* `count` - the number of tests related to this result
Tests
```js
{
count: '15',
name: 'tests',
raw: '# tests 15',
type: 'result'
}
```
Pass
```js
{
count: '13',
name: 'pass',
raw: '# pass 13',
type: 'result'
}
```
Fail
```js
{
count: '2',
name: 'fail',
raw: '# fail 2',
type: 'result'
}
```
### t.on('pass', function (assertion) {})
Parsed assertion that has passed with details. The assertion formate is the same as the [`assert`](#tonassert-function-assertion-) event.
### t.on('fail', function (assertion) {})
Failed assertion that has passed with details. The assertion formate is the same as the [`assert`](#tonassert-function-assertion-) event.
### t.on('comment', function (comment) {})
Generic output like `console.log()` in your tests.
* `type` - this will always be `comment`
* `raw` - the raw output before it was parsed
* `test` - the number of the test this comment belongs to
```js
{
type: 'comment',
raw: 'this is a console log',
test: 1
}
```
## Run Tests
```
git clone git@github.com:scottcorgan/tap-out.git && cd tap-out
npm install
npm test
```

21
tests/node_modules/tap-out/bin/cmd.js generated vendored Executable file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env node
var tapOut = require('../');
var parser = tapOut(function (err, output) {
if (err) {
throw err;
}
var out = output;
try {
out = JSON.stringify(output, null, 2);
}
catch (e) {}
process.stdout.write(out);
});
process.stdin.pipe(parser);

289
tests/node_modules/tap-out/index.js generated vendored Normal file
View File

@@ -0,0 +1,289 @@
'use strict';
var PassThrough = require('readable-stream/passthrough');
var split = require('split');
var trim = require('trim');
var util = require('util');
var EventEmitter = require('events').EventEmitter;
var reemit = require('re-emitter');
var expr = require('./lib/utils/regexes');
var parseLine = require('./lib/parse-line');
var error = require('./lib/error');
function Parser() {
if (!(this instanceof Parser)) {
return new Parser();
}
EventEmitter.call(this);
this.results = {
tests: [],
asserts: [],
versions: [],
results: [],
comments: [],
plans: [],
pass: [],
fail: [],
errors: [],
};
this.testNumber = 0;
this.previousLine = '';
this.currentNextLineError = null;
this.writingErrorOutput = false;
this.writingErrorStackOutput = false;
this.tmpErrorOutput = '';
}
util.inherits(Parser, EventEmitter);
Parser.prototype.handleLine = function handleLine(line) {
var parsed = parseLine(line);
// This will handle all the error stuff
this._handleError(line);
// This is weird, but it's the only way to distinguish a
// console.log type output from an error output
if (
!this.writingErrorOutput
&& !parsed
&& !isErrorOutputEnd(line)
&& !isRawTapTestStatus(line)
)
{
var comment = {
type: 'comment',
raw: line,
test: this.testNumber
};
this.emit('comment', comment);
this.results.comments.push(comment);
}
// Invalid line
if (!parsed) {
return;
}
// Handle tests
if (parsed.type === 'test') {
this.testNumber += 1;
parsed.number = this.testNumber;
}
// Handle asserts
if (parsed.type === 'assert') {
parsed.test = this.testNumber;
this.results[parsed.ok ? 'pass' : 'fail'].push(parsed);
if (parsed.ok) {
// No need to have the error object
// in a passing assertion
delete parsed.error;
this.emit('pass', parsed);
}
}
if (!isOkLine(this.previousLine)) {
this.emit(parsed.type, parsed);
this.results[parsed.type + 's'].push(parsed);
}
// This is all so we can determine if the "# ok" output on the last line
// should be skipped
function isOkLine (previousLine) {
return line === '# ok' && previousLine.indexOf('# pass') > -1;
}
this.previousLine = line;
};
Parser.prototype._handleError = function _handleError(line) {
// Start of error output
if (isErrorOutputStart(line)) {
this.writingErrorOutput = true;
this.lastAsserRawErrorString = '';
}
// End of error output
else if (isErrorOutputEnd(line)) {
this.writingErrorOutput = false;
this.currentNextLineError = null;
this.writingErrorStackOutput = false;
// Emit error here so it has the full error message with it
var lastAssert = this.results.fail[this.results.fail.length - 1];
if (this.tmpErrorOutput) {
lastAssert.error.stack = this.tmpErrorOutput;
this.lastAsserRawErrorString += this.tmpErrorOutput + '\n';
this.tmpErrorOutput = '';
}
// right-trimmed raw error string
lastAssert.error.raw = this.lastAsserRawErrorString.replace(/\s+$/g, '');
this.emit('fail', lastAssert);
}
// Append to stack
else if (this.writingErrorStackOutput) {
this.tmpErrorOutput += trim(line) + '\n';
}
// Not the beginning of the error message but it's the body
else if (this.writingErrorOutput) {
var lastAssert = this.results.fail[this.results.fail.length - 1];
var m = splitFirst(trim(line), (':'));
// Rebuild raw error output
this.lastAsserRawErrorString += line + '\n';
if (m[0] === 'stack') {
this.writingErrorStackOutput = true;
return;
}
var msg = trim((m[1] || '').replace(/['"]+/g, ''));
if (m[0] === 'at') {
// Example string: Object.async.eachSeries (/Users/scott/www/modules/nash/node_modules/async/lib/async.js:145:20)
msg = msg
.split(' ')[1]
.replace('(', '')
.replace(')', '');
var values = msg.split(':');
var file = values.slice(0, values.length-2).join(':');
msg = {
file: file,
line: values[values.length-2],
character: values[values.length-1]
};
}
// This is a plan failure
if (lastAssert.name === 'plan != count') {
lastAssert.type = 'plan';
delete lastAssert.error.at;
lastAssert.error.operator = 'count';
// Need to set this value
if (m[0] === 'actual') {
lastAssert.error.actual = trim(m[1]);
}
}
// outputting expected/actual object or array
if (this.currentNextLineError) {
lastAssert.error[this.currentNextLineError] = trim(line);
this.currentNextLineError = null;
}
else if (trim(m[1]) === '|-') {
this.currentNextLineError = m[0];
}
else {
lastAssert.error[m[0]] = msg;
}
}
};
Parser.prototype._handleEnd = function _handleEnd() {
var plan = this.results.plans.length ? this.results.plans[0] : null;
var count = this.results.asserts.length;
var first = count && this.results.asserts.reduce(firstAssertion);
var last = count && this.results.asserts.reduce(lastAssertion);
if (!plan) {
if (count > 0) {
this.results.errors.push(error('no plan provided'));
}
return;
}
if (this.results.fail.length > 0) {
return;
}
if (count !== (plan.to - plan.from + 1)) {
this.results.errors.push(error('incorrect number of assertions made'));
} else if (first && first.number !== plan.from) {
this.results.errors.push(error('first assertion number does not equal the plan start'));
} else if (last && last.number !== plan.to) {
this.results.errors.push(error('last assertion number does not equal the plan end'));
}
};
module.exports = function (done) {
done = done || function () {};
var stream = new PassThrough();
var parser = Parser();
reemit(parser, stream, [
'test', 'assert', 'version', 'result', 'pass', 'fail', 'comment', 'plan'
]);
stream
.pipe(split())
.on('data', function (data) {
if (!data) {
return;
}
var line = data.toString();
parser.handleLine(line);
})
.on('close', function () {
parser._handleEnd();
stream.emit('output', parser.results);
done(null, parser.results);
})
.on('error', done);
return stream;
};
module.exports.Parser = Parser;
function isErrorOutputStart (line) {
return line.indexOf(' ---') === 0;
}
function isErrorOutputEnd (line) {
return line.indexOf(' ...') === 0;
}
function splitFirst(str, pattern) {
var parts = str.split(pattern);
if (parts.length <= 1) {
return parts;
}
return [parts[0], parts.slice(1).join(pattern)];
}
function isRawTapTestStatus (str) {
var rawTapTestStatusRegex = new RegExp('(\\d+)(\\.)(\\.)(\\d+)');;
return rawTapTestStatusRegex.exec(str);
}
function firstAssertion(first, assert) {
return assert.number < first.number ? assert : first;
}
function lastAssertion(last, assert) {
return assert.number > last.number ? assert : last;
}

25
tests/node_modules/tap-out/lib/assert.js generated vendored Normal file
View File

@@ -0,0 +1,25 @@
var expr = require('./utils/regexes');
var exports = module.exports = function (line) {
var m = expr.ok.exec(line);
return {
type: 'assert',
raw: line,
ok: !m[1],
number: m[2] && Number(m[2]),
name: m[3],
error: {
operator: undefined,
expected: undefined,
actual: undefined,
at: undefined
}
};
};
exports.equals = function (line) {
return expr.ok.test(line);
};

6
tests/node_modules/tap-out/lib/error.js generated vendored Normal file
View File

@@ -0,0 +1,6 @@
module.exports = function (message) {
return {
type: 'error',
message: message
};
};

24
tests/node_modules/tap-out/lib/parse-line.js generated vendored Normal file
View File

@@ -0,0 +1,24 @@
var types = require('./types');
module.exports = function (line) {
if (types.is('version', line)) {
return types.version(line);
}
if (types.is('result', line)) {
return types.result(line);
}
if (types.is('assert', line)) {
return types.assert(line);
}
if (types.is('test', line)) {
return types.test(line);
}
if (types.is('plan', line)) {
return types.plan(line);
}
};

17
tests/node_modules/tap-out/lib/plan.js generated vendored Normal file
View File

@@ -0,0 +1,17 @@
var expr = require('./utils/regexes');
var exports = module.exports = function (line) {
var m = expr.plan.exec(line);
return {
type: 'plan',
raw: line,
from: m[1] && Number(m[1]),
to: m[2] && Number(m[2]),
skip: m[3]
};
};
exports.equals = function (line) {
return expr.plan.test(line);
};

24
tests/node_modules/tap-out/lib/result.js generated vendored Normal file
View File

@@ -0,0 +1,24 @@
var exports = module.exports = function (line) {
var m = line
.split(' ')
.filter(function (item) {
// Remove blank spaces
return item !== '';
});
return {
type: 'result',
raw: line,
name: m[1],
count: m[2]
};
};
exports.equals = function (line) {
var p = new RegExp('(#)(\\s+)((?:[a-z][a-z]+))(\\s+)(\\d+)',['i']);
return p.test(line);
};

18
tests/node_modules/tap-out/lib/test.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
var expr = require('./utils/regexes');
var exports = module.exports = function (line) {
var m = expr.comment.exec(line);
return {
type: 'test',
name: m[1],
raw: line
};
};
exports.equals = function (line) {
// TODO: need a more thorough test for this???
return line.indexOf('# ') === 0;
};

17
tests/node_modules/tap-out/lib/types.js generated vendored Normal file
View File

@@ -0,0 +1,17 @@
var types = module.exports = {
result: require('./result'),
assert: require('./assert'),
test: require('./test'),
version: require('./version'),
plan: require('./plan'),
is: function (type, line) {
var type = types[type];
if (!type) {
return false;
}
return type.equals(line);
}
};

8
tests/node_modules/tap-out/lib/utils/regexes.js generated vendored Normal file
View File

@@ -0,0 +1,8 @@
module.exports = {
ok: new RegExp('^(not )?ok\\b(?:(?:\\s+(\\d+))?(?:\\s+(?:(?:\\s*-\\s*)?(.*)))?)?'),
result: new RegExp('(#)(\\s+)((?:[a-z][a-z]+))(\\s+)(\\d+)',['i']),
plan: /^(\d+)\.\.(\d+)\b(?:\s+#\s+SKIP\s+(.*)$)?/,
comment: /^#\s*(.+)/,
version: /^TAP\s+version\s+(\d+)/i,
label_todo: /^(.*?)\s*#\s*TODO\s+(.*)$/
};

14
tests/node_modules/tap-out/lib/version.js generated vendored Normal file
View File

@@ -0,0 +1,14 @@
var expr = require('./utils/regexes');
var exports = module.exports = function (line) {
return {
type: 'version',
raw: line
};
};
exports.equals = function (line) {
return expr.version.test(line);
};

68
tests/node_modules/tap-out/package.json generated vendored Normal file
View File

@@ -0,0 +1,68 @@
{
"_from": "tap-out@^2.1.0",
"_id": "tap-out@2.1.0",
"_inBundle": false,
"_integrity": "sha512-LJE+TBoVbOWhwdz4+FQk40nmbIuxJLqaGvj3WauQw3NYYU5TdjoV3C0x/yq37YAvVyi+oeBXmWnxWSjJ7IEyUw==",
"_location": "/tap-out",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "tap-out@^2.1.0",
"name": "tap-out",
"escapedName": "tap-out",
"rawSpec": "^2.1.0",
"saveSpec": null,
"fetchSpec": "^2.1.0"
},
"_requiredBy": [
"/tap-spec"
],
"_resolved": "https://registry.npmjs.org/tap-out/-/tap-out-2.1.0.tgz",
"_shasum": "c093079a915036de8b835bfa3297f14458b15358",
"_spec": "tap-out@^2.1.0",
"_where": "/home/lilleman/go/src/gitlab.larvit.se/power-plan/auth/tests/node_modules/tap-spec",
"author": {
"name": "Scott Corgan"
},
"bin": {
"tap-out": "bin/cmd.js"
},
"bugs": {
"url": "https://github.com/scottcorgan/tap-out/issues"
},
"bundleDependencies": false,
"dependencies": {
"re-emitter": "1.1.3",
"readable-stream": "2.2.9",
"split": "1.0.0",
"trim": "0.0.1"
},
"deprecated": false,
"description": "A different tap parser",
"devDependencies": {
"tape": "4.6.3"
},
"directories": {
"test": "test"
},
"homepage": "https://github.com/scottcorgan/tap-out",
"keywords": [
"tap",
"parser",
"tape",
"tap-spec",
"test"
],
"license": "MIT",
"main": "index.js",
"name": "tap-out",
"repository": {
"type": "git",
"url": "git+https://github.com/scottcorgan/tap-out.git"
},
"scripts": {
"test": "tape test/index.js"
},
"version": "2.1.0"
}

762
tests/node_modules/tap-out/test/index.js generated vendored Normal file
View File

@@ -0,0 +1,762 @@
var parser = require('../');
var test = require('tape');
test('output event', function (t) {
t.plan(1);
var mockTap = [
'# is true',
'ok 1 true value',
'ok 2 true value',
'1..2'
];
var p = parser();
p.on('output', function (output) {
t.deepEqual(output, {
asserts: [
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' },
{ name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' }
],
fail: [],
pass: [
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' },
{ name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' }
],
results: [],
tests: [
{ name: 'is true', number: 1, raw: '# is true', type: 'test' }
],
versions: [],
comments: [],
plans: [{ from: 1, to: 2, raw: '1..2', skip: undefined, type: 'plan' }],
errors: []
}, 'output data');
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
test('output callback', function (t) {
t.plan(1);
var mockTap = [
'# is true',
'ok 1 true value',
'ok 2 true value',
'1..2'
];
var p = parser(function (err, output) {
t.deepEqual(output, {
asserts: [
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' },
{ name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' }
],
fail: [],
pass: [
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' },
{ name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' }
],
results: [],
tests: [
{ name: 'is true', number: 1, raw: '# is true', type: 'test' }
],
versions: [],
comments: [],
plans: [{ from: 1, to: 2, raw: '1..2', skip: undefined, type: 'plan' }],
errors: []
}, 'output data');
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
test('tests', function (t) {
t.plan(1);
var mockTap = [
'# is true',
'ok 1 true value',
'ok 2 true value'
];
var p = parser();
p.on('test', function (test) {
t.deepEqual(test, {
type: 'test',
name: 'is true',
raw: '# is true',
number: 1
}, 'test is parsed');
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
test('asserts', function (t) {
t.plan(2);
var mockTap = [
'# is true',
'ok 1 true value',
'ok 2 true value'
];
var p = parser();
var asserts = [];
p.on('assert', function (assert) {
asserts.push(assert);
});
p.on('output', function () {
t.deepEqual(asserts[0], {
name: 'true value',
number: 1,
ok: true,
raw: 'ok 1 true value',
test: 1,
type: 'assert'
}, 'assert 1')
t.deepEqual(asserts[1], {
name: 'true value',
number: 2,
ok: true,
raw: 'ok 2 true value',
test: 1,
type: 'assert'
}, 'assert 2')
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
test('results', function (t) {
t.plan(3);
var mockTap = [
'# tests 15',
'# pass 13',
'# fail 2'
];
var p = parser();
var results = [];
p.on('result', function (result) {
results.push(result);
});
p.on('output', function () {
t.deepEqual(results[0], {
count: '15',
name: 'tests',
raw: '# tests 15',
type: 'result'
}, 'tests');
t.deepEqual(results[1], {
count: '13',
name: 'pass',
raw: '# pass 13',
type: 'result'
}, 'pass');
t.deepEqual(results[2], {
count: '2',
name: 'fail',
raw: '# fail 2',
type: 'result'
}, 'fail');
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
test('version', function (t) {
t.plan(1);
var mockTap = [
'TAP version 13'
];
var p = parser();
var results = [];
p.on('version', function (version) {
t.deepEqual(version, {
raw: 'TAP version 13',
type: 'version'
}, 'version data');
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
test('pass', function (t) {
t.plan(2);
var mockTap = [
'# is true',
'ok 1 true value',
'ok 2 true value'
];
var p = parser();
var passes = [];
p.on('pass', function (pass) {
passes.push(pass);
});
p.on('output', function () {
t.deepEqual(passes[0], {
name: 'true value',
number: 1,
ok: true,
raw: 'ok 1 true value',
test: 1,
type: 'assert'
}, 'pass 1');
t.deepEqual(passes[1], {
name: 'true value',
number: 2,
ok: true,
raw: 'ok 2 true value',
test: 1,
type: 'assert'
}, 'pass 2');
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
test('failed assertion', function (t) {
t.plan(1);
var mockTap = [
"TAP version 13",
"# is true",
"ok 1 true value",
"ok 2 true value",
"not ok 3 strings match",
" ---",
" operator: equal",
" expected: 'you'",
" actual: 'me'",
" at: Test.<anonymous> (/Users/scott/www/divshot/divshot-cli/test/index.js:8:5)",
" ...",
"not ok 15 plan != count",
" ---",
" operator: fail",
" expected: 4",
" actual: 3",
" ...",
"",
"1..15",
];
var fails = [];
var p = parser(function () {
t.deepEqual(
fails,
[
{
error: {
actual: 'me',
at: {
character: '5',
file: '/Users/scott/www/divshot/divshot-cli/test/index.js',
line: '8'
},
expected: 'you',
operator: 'equal',
raw: [
" operator: equal",
" expected: 'you'",
" actual: 'me'",
" at: Test.<anonymous> (/Users/scott/www/divshot/divshot-cli/test/index.js:8:5)"
].join('\n')
},
name: 'strings match',
number: 3,
ok: false,
raw: 'not ok 3 strings match',
test: 1,
type: 'assert'
},
{
error: {
actual: '3',
expected: '4',
operator: 'count',
raw: [
" operator: fail",
" expected: 4",
" actual: 3"
].join('\n')
},
name: 'plan != count',
number: 15,
ok: false,
raw: 'not ok 15 plan != count',
test: 1,
type: 'plan'
}
],
'fails'
);
});
p.on('fail', function (fail) {
fails.push(fail);
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
test('plan', function (t) {
var mockTap = [
'1..2',
];
var plans = [];
var p = parser(function () {
t.deepEqual(plans, [
{ from: 1, to: 2, raw: '1..2', skip: undefined, type: 'plan' }
]);
t.end();
});
p.on('plan', function (plan) {
plans.push(plan);
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
// NOTE: comments output the same as test names.
// This makes it very difficult to parse them.
// Ignoring them for now. Just don't use comments.
test('comments');
test('generic output', function (t) {
var mockTap = [
"TAP version 13",
"# is true",
"ok 1 true value",
"not ok 2 strings match",
" ---",
" operator: equal",
" expected: 'you'",
" actual: 'me'",
" at: Test.<anonymous> (/Users/scott/www/divshot/divshot-cli/test/index.js:8:5)",
" ...",
"ok 3 true value",
"this is a console log",
"# false values",
"ok 4 should be false",
"ok 5 false value"
];
var comments = [];
var p = parser(function (err, output) {
t.deepEqual(
comments,
[
{
type: 'comment',
raw: 'this is a console log',
test: 1
}
],
'one comment'
);
t.end();
});
p.on('comment', function (comment) {
comments.push(comment);
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
test('handles HTTP error source', function (t) {
t.plan(1);
var mockTap = [
"TAP version 13",
"# is true",
"ok 1 true value",
"ok 2 true value",
"not ok 3 strings match",
" ---",
" operator: equal",
" expected: 'you'",
" actual: 'me'",
" at: Test.<anonymous> (http://localhost:9966/index.js:8:5)",
" ...",
"not ok 15 plan != count",
" ---",
" operator: fail",
" expected: 4",
" actual: 3",
" ...",
"",
"1..15",
];
var p = parser();
p.on('output', function (output) {
var assert = output.fail[0];
t.deepEqual(assert.error.at, { character: '5', file: 'http://localhost:9966/index.js', line: '8' });
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
test('handles raw error string', function (t) {
t.plan(1);
var rawLines = [
" operator: deepEqual",
" expected:",
" { 0: 0, 1: 0, 10: 0, 11: 255, 12: 0, 13: 0, 14: 0, 15: 255, 2: 0, 3: 221, 4: 0, 5: 0, 6: 0, 7: 255, 8: 0, 9: 0 }",
" actual:",
" { 0: 0, 1: 0, 10: 0, 11: 255, 12: 0, 13: 0, 14: 0, 15: 255, 2: 0, 3: 255, 4: 0, 5: 0, 6: 0, 7: 255, 8: 0, 9: 0 }",
" at: Test.<anonymous> (http://localhost:9966/index.js:8:5)"
];
var mockTap = [
"TAP version 13",
"# is true",
"ok 1 true value",
"ok 2 true value",
"not ok 3 arrays match",
" ---"
].concat(rawLines).concat([
" ...",
"not ok 15 plan != count",
" ---",
" operator: fail",
" expected: 4",
" actual: 3",
" ...",
"",
"1..15",
]);
var p = parser();
p.on('output', function (output) {
var assert = output.fail[0];
t.deepEqual(assert.error.raw, rawLines.join('\n'));
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
test('handles multiline error string with |-', function (t) {
t.plan(2);
var mockTap = [
"TAP version 13",
"# is true",
"ok 1 true value",
"not ok 2 object deep equal with cross",
" ---",
" operator: deepEqual",
" expected: |-",
" { a: 1, b: 2 }",
" actual: |-",
" { a: 1, b: 3 }",
" at: Test.<anonymous> (/Users/germ/Projects/a/b/test.js:7:5)",
" ...",
"",
"1..2",
];
var p = parser();
p.on('output', function (output) {
var assert = output.fail[0];
t.equal(assert.error.expected, '{ a: 1, b: 2 }');
t.equal(assert.error.actual, '{ a: 1, b: 3 }');
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
test('handles multiline error stack with |-', function (t) {
t.plan(2);
var mockTap = [
"TAP version 13",
"# promise error",
"not ok 1 TypeError: foo",
" ---",
" operator: error",
" expected: |-",
" undefined",
" actual: |-",
" [TypeError: foo]",
" at: process._tickCallback (internal/process/next_tick.js:103:7)",
" stack: |-",
" TypeError: foo",
" at throwError (/Users/germ/Projects/a/b/test.js:17:9)",
" at Promise.resolve.then (/Users/germ/Projects/a/b/test.js:24:5)",
" at process._tickCallback (internal/process/next_tick.js:103:7)",
" ...",
"",
"1..1",
"# tests 1",
"# pass 0",
"# fail 1"
];
var p = parser();
p.on('output', function (output) {
var assert = output.fail[0];
t.equal(assert.error.stack, 'TypeError: foo\n'
+ 'at throwError (/Users/germ/Projects/a/b/test.js:17:9)\n'
+ 'at Promise.resolve.then (/Users/germ/Projects/a/b/test.js:24:5)\n'
+ 'at process._tickCallback (internal/process/next_tick.js:103:7)\n'
);
t.equal(assert.error.raw, ' operator: error\n'
+ ' expected: |-\n'
+ ' undefined\n'
+ ' actual: |-\n'
+ ' [TypeError: foo]\n'
+ ' at: process._tickCallback (internal/process/next_tick.js:103:7)\n'
+ ' stack: |-\n'
+ 'TypeError: foo\n'
+ 'at throwError (/Users/germ/Projects/a/b/test.js:17:9)\n'
+ 'at Promise.resolve.then (/Users/germ/Projects/a/b/test.js:24:5)\n'
+ 'at process._tickCallback (internal/process/next_tick.js:103:7)'
);
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
test('output without plan', function (t) {
t.plan(1);
var mockTap = [
"# is true",
"ok 1 true value",
];
var p = parser();
p.on('output', function (output) {
t.deepEqual(output, {
asserts: [
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' }
],
fail: [],
pass: [
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' }
],
results: [],
tests: [
{ name: 'is true', number: 1, raw: '# is true', type: 'test' }
],
versions: [],
comments: [],
plans: [],
errors: [
{ message: 'no plan provided', type: 'error' }
]
}, 'output data with empty plans and no plan provided');
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
test('output with assert count and plan mismatch', function (t) {
t.plan(1);
var mockTap = [
"# is true",
"ok 1 true value",
"1..2",
];
var p = parser();
p.on('output', function (output) {
t.deepEqual(output, {
asserts: [
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' }
],
fail: [],
pass: [
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' }
],
results: [],
tests: [
{ name: 'is true', number: 1, raw: '# is true', type: 'test' }
],
versions: [],
comments: [],
plans: [
{ from: 1, to: 2, raw: '1..2', skip: undefined, type: 'plan' }
],
errors: [
{ message: 'incorrect number of assertions made', type: 'error' }
]
}, 'output data with empty assert count and plan mismatch error');
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});
test('output with plan end and assertion number mismatch', function (t) {
t.plan(1);
var mockTap = [
"# is true",
"ok 1 true value",
'ok 3 true value',
"1..2",
];
var p = parser();
p.on('output', function (output) {
t.deepEqual(output, {
asserts: [
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' },
{ name: 'true value', number: 3, ok: true, raw: 'ok 3 true value', test: 1, type: 'assert' }
],
fail: [],
pass: [
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' },
{ name: 'true value', number: 3, ok: true, raw: 'ok 3 true value', test: 1, type: 'assert' }
],
results: [],
tests: [
{ name: 'is true', number: 1, raw: '# is true', type: 'test' }
],
versions: [],
comments: [],
plans: [
{ from: 1, to: 2, raw: '1..2', skip: undefined, type: 'plan' }
],
errors: [
{ message: 'last assertion number does not equal the plan end', type: 'error' }
]
}, 'output data with plan end error');
});
mockTap.forEach(function (line) {
p.write(line + '\n');
});
p.end();
});

36
tests/node_modules/tap-out/test/mock-tap.txt generated vendored Normal file
View File

@@ -0,0 +1,36 @@
TAP version 13
# is true
ok 1 true value
ok 2 true value
not ok 3 strings match
---
operator: equal
expected: 'you'
actual: 'me'
at: Test.<anonymous> (/Users/scott/www/divshot/divshot-cli/test/index.js:8:5)
...
ok 4 true value
ok 5 true value
ok 6 true value
ok 7 true value
this is a console log
# false values
ok 8 should be false
ok 9 false value
ok 10 should have been a false value
ok 11 false value
# with plan
ok 12 is ok
ok 13 is not ok
ok 14 me equals me
not ok 15 plan != count
---
operator: fail
expected: 4
actual: 3
...
1..15
# tests 15
# pass 13
# fail 2