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

4
tests/node_modules/tap-spec/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,4 @@
language: node_js
node_js:
- "0.11"
- "0.10"

21
tests/node_modules/tap-spec/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 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.

52
tests/node_modules/tap-spec/README.md generated vendored Normal file
View File

@@ -0,0 +1,52 @@
# tap-spec [![NPM version](https://img.shields.io/npm/v/tap-spec.svg?style=flat-square)](https://www.npmjs.com/package/tap-spec) [![NPM download count](https://img.shields.io/npm/dm/tap-spec.svg?style=flat-square)](https://www.npmjs.com/package/tap-spec)
Formatted TAP output like Mocha's spec reporter
![iterm - 2 bash - may 29 2015 at 10 17 am screen shot](https://cloud.githubusercontent.com/assets/974723/7888261/03366236-05ec-11e5-9f94-d9c2707526b7.png)
## Install
```
npm install tap-spec --save-dev
```
## Usage
### Streaming
```js
var test = require('tape');
var tapSpec = require('tap-spec');
test.createStream()
.pipe(tapSpec())
.pipe(process.stdout);
```
### CLI
**package.json**
```json
{
"name": "module-name",
"scripts": {
"test": "node ./test/tap-test.js | tap-spec"
}
}
```
Then run with `npm test`
**Terminal**
```
tape test/index.js | node_modules/.bin/tap-spec
```
**Testling**
```
npm install testling -g
testling test/index.js | node_modules/.bin/tap-spec
```

19
tests/node_modules/tap-spec/bin/cmd.js generated vendored Executable file
View File

@@ -0,0 +1,19 @@
#!/usr/bin/env node
var tapSpec = require('../');
var tapSpec = tapSpec();
process.stdin
.pipe(tapSpec)
.pipe(process.stdout);
process.on('exit', function (status) {
if (status === 1) {
process.exit(1);
}
if (tapSpec.failed) {
process.exit(1);
}
});

169
tests/node_modules/tap-spec/index.js generated vendored Normal file
View File

@@ -0,0 +1,169 @@
var fs = require('fs');
var tapOut = require('tap-out');
var through = require('through2');
var duplexer = require('duplexer');
var format = require('chalk');
var prettyMs = require('pretty-ms');
var _ = require('lodash');
var repeat = require('repeat-string');
var symbols = require('figures');
var lTrimList = require('./lib/utils/l-trim-list');
module.exports = function (spec) {
spec = spec || {};
var OUTPUT_PADDING = spec.padding || ' ';
var output = through();
var parser = tapOut();
var stream = duplexer(parser, output);
var startTime = new Date().getTime();
output.push('\n');
parser.on('test', function (test) {
output.push('\n' + pad(format.underline(test.name)) + '\n\n');
});
// Passing assertions
parser.on('pass', function (assertion) {
if (/# SKIP/.test(assertion.name)) {
var name = assertion.name.replace(' # SKIP', '')
name = format.cyan('- ' + name);
output.push(pad(' ' + name + '\n'));
}
else {
var glyph = format.green(symbols.tick);
var name = format.dim(assertion.name);
output.push(pad(' ' + glyph + ' ' + name + '\n'));
}
});
// Failing assertions
parser.on('fail', function (assertion) {
var glyph = symbols.cross;
var title = glyph + ' ' + assertion.name;
var raw = format.cyan(prettifyRawError(assertion.error.raw));
var divider = _.fill(
new Array((title).length + 1),
'-'
).join('');
output.push('\n' + pad(' ' + format.red(title) + '\n'));
output.push(pad(' ' + format.red(divider) + '\n'));
output.push(raw);
stream.failed = true;
});
parser.on('comment', function (comment) {
output.push(pad(' ' + format.yellow(comment.raw)) + '\n');
});
// All done
parser.on('output', function (results) {
output.push('\n\n');
// Most likely a failure upstream
if (results.plans.length < 1) {
process.exit(1);
}
if (results.fail.length > 0) {
output.push(formatErrors(results));
output.push('\n');
}
output.push(formatTotals(results));
output.push('\n\n\n');
// Exit if no tests run. This is a result of 1 of 2 things:
// 1. No tests and asserts were written
// 2. There was some error before the TAP got to the parser
if (results.tests.length === 0 &&
results.asserts.length === 0) {
process.exit(1);
}
});
// Utils
function prettifyRawError (rawError) {
return rawError.split('\n').map(function (line) {
return pad(line);
}).join('\n') + '\n\n';
}
function formatErrors (results) {
var failCount = results.fail.length;
var past = (failCount === 1) ? 'was' : 'were';
var plural = (failCount === 1) ? 'failure' : 'failures';
var out = '\n' + pad(format.red.bold('Failed Tests:') + ' There ' + past + ' ' + format.red.bold(failCount) + ' ' + plural + '\n');
out += formatFailedAssertions(results);
return out;
}
function formatTotals (results) {
if (results.tests.length === 0 &&
results.asserts.length === 0) {
return pad(format.red(symbols.cross + ' No tests found'));
}
return _.filter([
pad('total: ' + results.asserts.length),
pad(format.green('passing: ' + results.pass.length)),
results.fail.length > 0 ? pad(format.red('failing: ' + results.fail.length)) : undefined,
pad('duration: ' + prettyMs(new Date().getTime() - startTime))
], _.identity).join('\n');
}
function formatFailedAssertions (results) {
var out = '';
var groupedAssertions = _.groupBy(results.fail, function (assertion) {
return assertion.test;
});
_.each(groupedAssertions, function (assertions, testNumber) {
// Wrie failed assertion's test name
var test = _.find(results.tests, {number: parseInt(testNumber)});
out += '\n' + pad(' ' + test.name + '\n\n');
// Write failed assertion
_.each(assertions, function (assertion) {
out += pad(' ' + format.red(symbols.cross) + ' ' + format.red(assertion.name)) + '\n';
});
out += '\n';
});
return out;
}
function pad (str) {
return OUTPUT_PADDING + str;
}
return stream;
};

22
tests/node_modules/tap-spec/lib/utils/l-trim-list.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
var _ = require('lodash');
module.exports = function (lines) {
var leftPadding;
// Get minimum padding count
_.each(lines, function (line) {
var spaceLen = line.match(/^\s+/)[0].length;
if (leftPadding === undefined || spaceLen < leftPadding) {
leftPadding = spaceLen;
}
});
// Strip padding at beginning of line
return _.map(lines, function (line) {
return line.slice(leftPadding);
});
}

71
tests/node_modules/tap-spec/package.json generated vendored Normal file
View File

@@ -0,0 +1,71 @@
{
"_from": "tap-spec",
"_id": "tap-spec@5.0.0",
"_inBundle": false,
"_integrity": "sha512-zMDVJiE5I6Y4XGjlueGXJIX2YIkbDN44broZlnypT38Hj/czfOXrszHNNJBF/DXR8n+x6gbfSx68x04kIEHdrw==",
"_location": "/tap-spec",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "tap-spec",
"name": "tap-spec",
"escapedName": "tap-spec",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/tap-spec/-/tap-spec-5.0.0.tgz",
"_shasum": "7329e4e66e8aa68da2a164215abbb903a7c5d352",
"_spec": "tap-spec",
"_where": "/home/lilleman/go/src/gitlab.larvit.se/power-plan/auth/tests",
"author": {
"name": "Scott Corgan"
},
"bin": {
"tspec": "bin/cmd.js",
"tap-spec": "bin/cmd.js"
},
"bugs": {
"url": "https://github.com/scottcorgan/tap-spec/issues"
},
"bundleDependencies": false,
"dependencies": {
"chalk": "^1.0.0",
"duplexer": "^0.1.1",
"figures": "^1.4.0",
"lodash": "^4.17.10",
"pretty-ms": "^2.1.0",
"repeat-string": "^1.5.2",
"tap-out": "^2.1.0",
"through2": "^2.0.0"
},
"deprecated": false,
"description": "Formatted TAP output like Mocha's spec reporter",
"devDependencies": {
"tapes": "^2.0.0"
},
"homepage": "https://github.com/scottcorgan/tap-spec#readme",
"keywords": [
"tape",
"tap",
"mocha",
"spec",
"reporter"
],
"license": "MIT",
"main": "index.js",
"name": "tap-spec",
"repository": {
"type": "git",
"url": "git+https://github.com/scottcorgan/tap-spec.git"
},
"scripts": {
"test": "echo 'Tests are out of date. Not running until fixed.'"
},
"version": "5.0.0"
}

93
tests/node_modules/tap-spec/test/e2e/index.js generated vendored Normal file
View 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
View 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
View 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
View 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();
});