Skip to content

Commit

Permalink
Use documented mechanism to find example type
Browse files Browse the repository at this point in the history
  • Loading branch information
HookyQR committed Jul 2, 2019
1 parent ac733d6 commit b20f2da
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
9 changes: 5 additions & 4 deletions README.md
Expand Up @@ -15,10 +15,10 @@ subscribe to specRunner events:
```javascript
specRunner.on('fileStart' (specRunner, absoluteFilename) => {});
specRunner.on('fileEnd' (specRunner, absoluteFilename) => {});
specRunner.on('contextStart' (specRunner) => {});
specRunner.on('contextEnd' (specRunner) => {});
specRunner.on('exampleStart' (specRunner) => {});
specRunner.on('exampleEnd' (specRunner) => {});
specRunner.on('contextStart' (specRunner, id, contextType, description) => {});
specRunner.on('contextEnd' (specRunner, id) => {});
specRunner.on('exampleStart' (specRunner, example) => {});
specRunner.on('exampleEnd' (specRunner, example) => {});
specRunner.on('runEnd' (specRunner) => {});
```

Expand All @@ -34,6 +34,7 @@ context.initialisedBy // string: 'context' || 'describe'
`example` is an instance of `Example` and responds to:
`kind` with:
```javascript
"pending" // the block won't be run in this case
"it"
"before"
"beforeEach"
Expand Down
14 changes: 7 additions & 7 deletions formatters/documentation.js
Expand Up @@ -27,7 +27,7 @@ class Documentation extends Null {
contextStart(_, id, contextType = '', description) {
this.pendingContexts[id] = { contextType, description, kind: 'context' };
if (contextType[0] === 'X') {
this.pendingTotal ++;
this.pendingTotal++;
description = ansi.light(ansi.yellow(description));
}
this.depth++;
Expand All @@ -37,15 +37,16 @@ class Documentation extends Null {
contextEnd() {
this.depth--;
}

exampleStart() {
this.stack.push(process.hrtime.bigint());
}

exampleEnd(_, example = {}) {
let line = ' '.repeat(this.depth + 1);

if ( example.constructor.name.startsWith('X') ){
this.pendingTotal ++;
if (example.kind === 'pending') {
this.pendingTotal++;
line += ansi.yellow('·· ') + ansi.light(example.description || '');
console.log(line);
return;
Expand Down Expand Up @@ -81,14 +82,13 @@ class Documentation extends Null {
this.failures.map((example, index) => {
console.log((index + 1).toString().padStart(3, ' ') + ')' + example.fullDescription);

if (example.failure.constructor.name === 'AssertionError'){
if (example.failure.constructor.name === 'AssertionError') {
console.log(ansi.red(' ' + example.failure.message) + '\n');
const stack = example.failure.stack.split('\n');
stack.shift();

console.log(ansi.light(stack.join('\n')));
}
else
} else
console.log(ansi.light(example.failure.stack));
if (example.failure.expected && example.failure.actual) {
console.log(' ' + ansi.red(' - Actual ') + ansi.green(' + Expected') + '\n');
Expand Down
7 changes: 4 additions & 3 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "@jsspec/format",
"version": "0.0.9",
"description": "Command line option parser",
"version": "0.0.10",
"description": "Output formatter for jsspec",
"main": "index.js",
"scripts": {
"test": "c8 mocha --recursive"
Expand All @@ -11,7 +11,8 @@
"url": "git+https://github.com/JSSpec/format.git"
},
"keywords": [
"jsspec"
"jsspec",
"test output"
],
"author": "HookyQR",
"license": "MIT",
Expand Down
4 changes: 1 addition & 3 deletions test/formatters/documentation.test.js
Expand Up @@ -10,8 +10,6 @@ const sinonChai = require('sinon-chai');

chai.use(sinonChai);

class XTest {}

const ansi = require('../../lib/ansi');

const withoutConsole = block => {
Expand Down Expand Up @@ -164,7 +162,7 @@ describe('Documentation', () => {
it('sets it to yellow', () => {
const yellow = sinon.spy(ansi, 'yellow');
withoutConsole(() => {
formatter.exampleEnd(null, new XTest());
formatter.exampleEnd(null, {kind: 'pending'});
formatter.contextStart(null, 1, 'XContext', 'hello');
formatter.contextEnd();
formatter.contextStart(null, 1, 'XContext', 'hello yourself');
Expand Down

0 comments on commit b20f2da

Please sign in to comment.