-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vadim Demedes
committed
Dec 9, 2017
0 parents
commit 291f20e
Showing
23 changed files
with
1,869 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.yml] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* text=auto | ||
*.js text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- '8' | ||
- '6' | ||
- '4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
'use strict'; | ||
|
||
const serializeErr = require('serialize-error'); | ||
const indentString = require('indent-string'); | ||
const stripAnsi = require('strip-ansi'); | ||
const arrify = require('arrify'); | ||
const yaml = require('js-yaml'); | ||
|
||
const serializeError = err => { | ||
const obj = serializeErr(err); | ||
obj.at = obj.stack | ||
.split('\n') | ||
.slice(1, 2) | ||
.map(line => line.replace(/at/, '').trim()) | ||
.shift(); | ||
|
||
delete obj.stack; | ||
|
||
return obj; | ||
}; | ||
|
||
exports.start = () => 'TAP version 13'; | ||
|
||
exports.test = (title, options) => { | ||
const error = options.error; | ||
let passed = options.passed; | ||
let directive = ''; | ||
|
||
if (!error) { | ||
if (options.todo) { | ||
directive = '# TODO'; | ||
passed = false; | ||
} else if (options.skip) { | ||
directive = '# SKIP'; | ||
passed = true; | ||
} | ||
} | ||
|
||
const comment = arrify(options.comment) | ||
.map(line => indentString(line, 4).replace(/^ {4}/, ' * ')) | ||
.join('\n'); | ||
|
||
const output = [ | ||
`# ${stripAnsi(title)}`, | ||
`${passed ? 'ok' : 'not ok'} ${options.index} - ${title} ${directive}`.trim(), | ||
comment | ||
]; | ||
|
||
if (error) { | ||
const obj = error instanceof Error ? serializeError(error) : error; | ||
|
||
output.push([ | ||
' ---', | ||
indentString(yaml.safeDump(obj).trim(), 4), | ||
' ...' | ||
].join('\n')); | ||
} | ||
|
||
return output.filter(Boolean).join('\n'); | ||
}; | ||
|
||
exports.finish = stats => { | ||
stats = stats || {}; | ||
|
||
const passed = stats.passed || 0; | ||
const failed = stats.failed || 0; | ||
const skipped = stats.skipped || 0; | ||
const todo = stats.todo || 0; | ||
const crashed = stats.crashed || 0; | ||
|
||
return [ | ||
`\n1..${passed + failed + skipped + todo}`, | ||
`# tests ${passed + failed + skipped}`, | ||
`# pass ${passed}`, | ||
skipped > 0 ? `# skip ${skipped}` : null, | ||
`# fail ${failed + crashed + todo}\n` | ||
].filter(Boolean).join('\n'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
MIT License | ||
|
||
Copyright (c) Vadim Demedes <vdemedes@gmail.com> (github.com/vadimdemedes) | ||
|
||
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. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"name": "supertap", | ||
"version": "0.0.0", | ||
"description": "Generate TAP output", | ||
"license": "MIT", | ||
"repository": "vadimdemedes/supertap", | ||
"author": { | ||
"name": "Vadim Demedes", | ||
"email": "vdemedes@gmail.com", | ||
"url": "github.com/vadimdemedes" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"tap", | ||
"tape", | ||
"output" | ||
], | ||
"dependencies": { | ||
"arrify": "^1.0.1", | ||
"indent-string": "^3.2.0", | ||
"js-yaml": "^3.10.0", | ||
"serialize-error": "^2.1.0", | ||
"strip-ansi": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.20.0", | ||
"ctrlc-exit": "^1.0.0", | ||
"execa": "^0.8.0", | ||
"faucet": "^0.0.1", | ||
"p-each-series": "^1.0.0", | ||
"tap-dot": "^1.0.5", | ||
"tap-json": "^1.0.0", | ||
"tap-min": "^1.2.2", | ||
"tap-nyan": "^1.1.0", | ||
"tap-out": "^2.0.0", | ||
"tap-pessimist": "^1.0.1", | ||
"tap-spec": "^4.1.1", | ||
"tap-summary": "^4.0.0", | ||
"wait-for-enter": "^1.0.0", | ||
"xo": "^0.18.2" | ||
}, | ||
"ava": { | ||
"serial": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<h1 align="center"> | ||
<br> | ||
<img width="300" src="media/logo.png" alt="SUPERTAP"> | ||
<br> | ||
<br> | ||
<br> | ||
</h1> | ||
|
||
[![Build Status](https://travis-ci.org/vadimdemedes/supertap.svg?branch=master)](https://travis-ci.org/vadimdemedes/supertap) | ||
|
||
> Generate TAP output | ||
|
||
## Install | ||
|
||
``` | ||
$ npm install supertap | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
```js | ||
const supertap = require('supertap'); | ||
|
||
console.log(supertap.start()); | ||
|
||
console.log(supertap.test('passing', { | ||
index: 1, | ||
passed: true | ||
})); | ||
|
||
console.log(supertap.finish({ | ||
passed: 1 | ||
})); | ||
``` | ||
|
||
Output: | ||
|
||
``` | ||
TAP version 13 | ||
# passing | ||
ok 1 - passing | ||
1..1 | ||
# tests 1 | ||
# pass 1 | ||
# fail 0 | ||
``` | ||
|
||
|
||
## API | ||
|
||
### start() | ||
|
||
Always returns `'TAP version 13'` string. | ||
|
||
### test(title, options) | ||
|
||
#### title | ||
|
||
Type: `string` | ||
|
||
Test title. | ||
|
||
#### options | ||
|
||
##### index | ||
|
||
Type: `number` | ||
|
||
Index of the test. Should start with one, not zero. | ||
|
||
##### passed | ||
|
||
Type: `boolean`<br> | ||
Default: `false` | ||
|
||
Status of the test. | ||
|
||
##### error | ||
|
||
Type: `Error` | ||
|
||
If test has failed (`passed` is `false`), `error` is an instance of an actual error. | ||
|
||
```js | ||
supertest.test('failing', { | ||
index: 1, | ||
passed: false, | ||
error: new Error() | ||
}); | ||
``` | ||
|
||
##### todo | ||
##### skip | ||
|
||
Type: `boolean`<br> | ||
Default: `false` | ||
|
||
Mark test as to-do or as skipped. | ||
|
||
##### comment | ||
|
||
Type: `string` `array` | ||
|
||
Comments for that test. | ||
|
||
### finish(stats) | ||
|
||
#### stats | ||
|
||
##### passed | ||
##### failed | ||
##### skipped | ||
##### todo | ||
##### crashed | ||
|
||
Type: `number`<br> | ||
Default: `0` | ||
|
||
Number of tests that passed, failed, skipped or marked as todo. `crashed` is a special option, which adds to failed test count in the output, but not total test count. AVA uses it to count unhandled exceptions. | ||
|
||
|
||
## License | ||
|
||
MIT © [Vadim Demedes](https://github.com/vadimdemedes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
const fs = require('fs'); | ||
const waitForEnter = require('wait-for-enter'); | ||
const eachSeries = require('p-each-series'); | ||
const ctrlcExit = require('ctrlc-exit'); | ||
const execa = require('execa'); | ||
|
||
ctrlcExit(); | ||
|
||
const exec = cmd => { | ||
return execa.shell(cmd) | ||
.catch(err => err) | ||
.then(result => result.stdout); | ||
}; | ||
|
||
const fixtures = fs.readdirSync(`${__dirname}/../test/fixtures`); | ||
const reporter = process.argv[2]; | ||
|
||
eachSeries(fixtures, async fixture => { | ||
const fixturePath = `${__dirname}/../test/fixtures/${fixture}`; | ||
const reporterPath = `${__dirname}/../node_modules/.bin/${reporter}`; | ||
const stdout = await exec(`node ${fixturePath} | ${reporterPath}`); | ||
console.log(fixture); | ||
console.log(stdout); | ||
|
||
return waitForEnter(); | ||
}).then(() => process.exit()); // eslint-disable-line unicorn/no-process-exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
const supertap = require('../..'); | ||
|
||
console.log(supertap.start()); | ||
|
||
console.log(supertap.test('fail', { | ||
index: 1, | ||
passed: false | ||
})); | ||
|
||
console.log(supertap.finish({ | ||
passed: 0, | ||
failed: 1 | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
const supertap = require('../..'); | ||
|
||
console.log(supertap.start()); | ||
|
||
const err = new Error('error'); | ||
err.stack = 'error\n at fn (test.js:1:2)'; | ||
err.actual = 1; | ||
err.expected = 2; | ||
err.operator = '==='; | ||
|
||
console.log(supertap.test('fail', { | ||
index: 1, | ||
passed: false, | ||
error: err | ||
})); | ||
|
||
console.log(supertap.finish({ | ||
passed: 0, | ||
failed: 1 | ||
})); |
Oops, something went wrong.