Skip to content

Commit 3708273

Browse files
committed
[BREAKING CHANGE] Build: Use ES6 plainly (remove Rollup and Babel)
The current stack is imho too complicated to maintain and not worth the benefit. I'm expecting this to have fairly little impact since apart from browserstack and qunit, there are no dependants of this package on npm. To allow me to effectively pick up maintenance for js-reporters, optimise it for use in Node.js For now, use in a browser will require downstream to bundle this module as a library with their payload. I'm open to reconsidering this in the future if there's demand for it, e.g. by documenting how to create a simple ES5-compatible bundle and perhaps by offering a premade es5/commonjs artefact for download.
1 parent 04bdd8a commit 3708273

29 files changed

+2850
-6734
lines changed

.babelrc

Lines changed: 0 additions & 8 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
/dist
21
/node_modules
32
/*.log

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ node_js:
44
- '12' # LTS
55
- '14' # Current
66
script:
7-
- "npm run build"
87
- "npm test"

LICENSE

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
The MIT License (MIT)
2-
3-
Copyright (c) 2014 JS Reporters
1+
Copyright 2014-2020 JS Reporters <https://github.com/js-reporters/>
42

53
Permission is hereby granted, free of charge, to any person obtaining a copy
64
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ Listen to the events and receive the emitted data:
141141

142142
```js
143143
// Attach one of the exiting adapters.
144-
var runner = JsReporters.autoRegister();
144+
const runner = JsReporters.autoRegister();
145145

146146
// Listen to the same events for any testing framework.
147147
runner.on('testEnd', function(test) {
148148
console.log('Test %s has errors:', test.fullname.join(' '), test.errors);
149149
});
150150

151151
runner.on('runEnd', function(globalSuite) {
152-
var testCounts = globalSuite.testCounts;
152+
const testCounts = globalSuite.testCounts;
153153

154154
console.log('Testsuite status: %s', globalSuite.status);
155155

index.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import QUnitAdapter from './lib/adapters/QUnitAdapter.js';
2-
import JasmineAdapter from './lib/adapters/JasmineAdapter.js';
3-
import MochaAdapter from './lib/adapters/MochaAdapter.js';
4-
import TapReporter from './lib/reporters/TapReporter.js';
5-
import ConsoleReporter from './lib/reporters/ConsoleReporter.js';
6-
import {Assertion, TestStart, TestEnd, SuiteStart, SuiteEnd} from './lib/Data.js';
7-
import {autoRegister, createSuiteStart, createTestStart,
8-
createTestEnd, createSuiteEnd} from './lib/helpers.js';
1+
const QUnitAdapter = require('./lib/adapters/QUnitAdapter.js');
2+
const JasmineAdapter = require('./lib/adapters/JasmineAdapter.js');
3+
const MochaAdapter = require('./lib/adapters/MochaAdapter.js');
4+
const TapReporter = require('./lib/reporters/TapReporter.js');
5+
const ConsoleReporter = require('./lib/reporters/ConsoleReporter.js');
6+
const { Assertion, TestStart, TestEnd, SuiteStart, SuiteEnd } = require('./lib/Data.js');
7+
const {
8+
createSuiteStart,
9+
createTestStart,
10+
createTestEnd,
11+
createSuiteEnd
12+
} = require('./lib/helpers.js');
13+
const { autoRegister } = require('./lib/auto.js');
914

10-
export default {
15+
module.exports = {
1116
QUnitAdapter,
1217
JasmineAdapter,
1318
MochaAdapter,

karma.conf.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

lib/Data.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function getAllTests (suite) {
2-
var childSuiteTests = suite.childSuites
2+
const childSuiteTests = suite.childSuites
33
.map((childSuite) => getAllTests(childSuite))
44
.reduce((allTests, a) => allTests.concat(a), []);
55

@@ -17,14 +17,14 @@ function getRuntime (suite) {
1717
}
1818

1919
function getStatus (suite) {
20-
var passed = 0;
21-
var failed = 0;
22-
var skipped = 0;
23-
var todo = 0;
24-
var tests = getAllTests(suite);
20+
let passed = 0;
21+
let failed = 0;
22+
let skipped = 0;
23+
let todo = 0;
24+
const tests = getAllTests(suite);
2525

2626
for (let i = 0; i < tests.length; i++) {
27-
let test = tests[i];
27+
const test = tests[i];
2828

2929
// If a suite contains a test whose status is still undefined,
3030
// there is no final status for the suite as well.
@@ -53,15 +53,15 @@ function getStatus (suite) {
5353
}
5454

5555
function getSuiteStartTestCounts (suite) {
56-
var tests = getAllTests(suite);
56+
const tests = getAllTests(suite);
5757

5858
return {
5959
total: tests.length
6060
};
6161
}
6262

6363
function getSuiteEndTestCounts (suite) {
64-
var tests = getAllTests(suite);
64+
const tests = getAllTests(suite);
6565

6666
return {
6767
passed: tests.filter((test) => test.status === 'passed').length,
@@ -72,7 +72,7 @@ function getSuiteEndTestCounts (suite) {
7272
};
7373
}
7474

75-
export class Assertion {
75+
class Assertion {
7676
/**
7777
* @param {Boolean} passed
7878
* @param {*} actual
@@ -91,7 +91,7 @@ export class Assertion {
9191
}
9292
}
9393

94-
export class TestStart {
94+
class TestStart {
9595
/**
9696
* @param {String} name
9797
* @param {String} suiteName
@@ -104,7 +104,7 @@ export class TestStart {
104104
}
105105
}
106106

107-
export class TestEnd {
107+
class TestEnd {
108108
/**
109109
* @param {String} name
110110
* @param {String} suiteName
@@ -125,7 +125,7 @@ export class TestEnd {
125125
}
126126
}
127127

128-
export class SuiteStart {
128+
class SuiteStart {
129129
/**
130130
* @param {String} name
131131
* @param {String[]} fullName
@@ -141,7 +141,7 @@ export class SuiteStart {
141141
}
142142
}
143143

144-
export class SuiteEnd {
144+
class SuiteEnd {
145145
/**
146146
* @param {String} name
147147
* @param {String[]} fullName
@@ -166,3 +166,11 @@ export class SuiteEnd {
166166
this.runtime = runtime || getRuntime(this);
167167
}
168168
}
169+
170+
module.exports = {
171+
Assertion,
172+
TestStart,
173+
TestEnd,
174+
SuiteStart,
175+
SuiteEnd
176+
};

lib/adapters/JasmineAdapter.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import EventEmitter from 'events';
2-
import {Assertion, TestEnd, SuiteStart} from '../Data.js';
3-
import * as helpers from '../helpers.js';
1+
const EventEmitter = require('events');
2+
const { Assertion, TestEnd, SuiteStart } = require('../Data.js');
3+
const helpers = require('../helpers.js');
44

55
/**
66
* Limitations:
77
* - Errors in afterAll are ignored.
88
*/
9-
export default class JasmineAdapter extends EventEmitter {
9+
module.exports = class JasmineAdapter extends EventEmitter {
1010
constructor (jasmine) {
1111
super();
1212

@@ -16,7 +16,7 @@ export default class JasmineAdapter extends EventEmitter {
1616
this.suites = {};
1717
this.tests = {};
1818

19-
var reporter = {
19+
const reporter = {
2020
jasmineStarted: this.onJasmineStarted.bind(this),
2121
specDone: this.onSpecDone.bind(this),
2222
specStarted: this.onSpecStarted.bind(this),
@@ -35,14 +35,14 @@ export default class JasmineAdapter extends EventEmitter {
3535
}
3636

3737
createAssertion (expectation) {
38-
let stack = expectation.stack !== '' ? expectation.stack : undefined;
38+
const stack = expectation.stack !== '' ? expectation.stack : undefined;
3939

4040
return new Assertion(expectation.passed, expectation.actual,
4141
expectation.expected, expectation.message, stack);
4242
}
4343

4444
saveTestDetails (jasmineSpec) {
45-
var test = this.tests[jasmineSpec.id];
45+
const test = this.tests[jasmineSpec.id];
4646

4747
test.errors = [];
4848
test.assertions = [];
@@ -77,9 +77,9 @@ export default class JasmineAdapter extends EventEmitter {
7777
* object using as key their unique ids provided by Jasmine.
7878
*/
7979
createGlobalSuite (jasmineSuite, fullName) {
80-
var childSuites = [];
81-
var tests = [];
82-
var isGlobalSuite = this.isJasmineGlobalSuite(jasmineSuite);
80+
const childSuites = [];
81+
const tests = [];
82+
const isGlobalSuite = this.isJasmineGlobalSuite(jasmineSuite);
8383

8484
if (!isGlobalSuite) {
8585
fullName.push(jasmineSuite.description);
@@ -89,12 +89,11 @@ export default class JasmineAdapter extends EventEmitter {
8989
if (child.id.indexOf('suite') === 0) {
9090
childSuites.push(this.createGlobalSuite(child, fullName));
9191
} else {
92-
let test;
93-
let suiteName = !isGlobalSuite ? jasmineSuite.description : undefined;
92+
const suiteName = !isGlobalSuite ? jasmineSuite.description : undefined;
9493

9594
fullName.push(child.description);
9695

97-
test = new TestEnd(child.description, suiteName, fullName.slice());
96+
const test = new TestEnd(child.description, suiteName, fullName.slice());
9897

9998
fullName.pop();
10099

@@ -103,8 +102,8 @@ export default class JasmineAdapter extends EventEmitter {
103102
}
104103
});
105104

106-
let name = !isGlobalSuite ? jasmineSuite.description : undefined;
107-
let suite = new SuiteStart(name, fullName.slice(), tests, childSuites);
105+
const name = !isGlobalSuite ? jasmineSuite.description : undefined;
106+
const suite = new SuiteStart(name, fullName.slice(), tests, childSuites);
108107

109108
this.suites[jasmineSuite.id] = suite;
110109

@@ -139,4 +138,4 @@ export default class JasmineAdapter extends EventEmitter {
139138
onJasmineDone () {
140139
this.emit('runEnd', helpers.createSuiteEnd(this.globalSuite));
141140
}
142-
}
141+
};

lib/adapters/MochaAdapter.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import EventEmitter from 'events';
2-
import {Assertion, TestStart, TestEnd, SuiteStart, SuiteEnd} from '../Data.js';
1+
const EventEmitter = require('events');
2+
const { Assertion, TestStart, TestEnd, SuiteStart, SuiteEnd } = require('../Data.js');
33

4-
export default class MochaAdapter extends EventEmitter {
4+
module.exports = class MochaAdapter extends EventEmitter {
55
constructor (mocha) {
66
super();
77

@@ -12,7 +12,7 @@ export default class MochaAdapter extends EventEmitter {
1212
this.runner = runner;
1313

1414
// eslint-disable-next-line no-unused-vars
15-
let origReporterInstance = new (this.origReporter.bind(this.mocha,
15+
const origReporterInstance = new (this.origReporter.bind(this.mocha,
1616
this.runner))();
1717

1818
runner.on('start', this.onStart.bind(this));
@@ -45,8 +45,8 @@ export default class MochaAdapter extends EventEmitter {
4545
}
4646

4747
convertTest (mochaTest) {
48-
var suiteName;
49-
var fullName;
48+
let suiteName;
49+
let fullName;
5050

5151
if (!mochaTest.parent.root) {
5252
suiteName = mochaTest.parent.title;
@@ -60,8 +60,8 @@ export default class MochaAdapter extends EventEmitter {
6060
// If the test has the errors attached a "test end" must be emitted, else
6161
// a "test start".
6262
if (mochaTest.errors !== undefined) {
63-
var status = (mochaTest.state === undefined) ? 'skipped' : mochaTest.state;
64-
let errors = [];
63+
const status = (mochaTest.state === undefined) ? 'skipped' : mochaTest.state;
64+
const errors = [];
6565

6666
mochaTest.errors.forEach(function (error) {
6767
errors.push(new Assertion(false, error.actual, error.expected,
@@ -81,8 +81,8 @@ export default class MochaAdapter extends EventEmitter {
8181
* Builds an array with the names of nested suites.
8282
*/
8383
buildSuiteFullName (mochaSuite) {
84-
var fullName = [];
85-
var parent = mochaSuite.parent;
84+
const fullName = [];
85+
let parent = mochaSuite.parent;
8686

8787
if (!mochaSuite.root) {
8888
fullName.push(mochaSuite.title);
@@ -97,7 +97,7 @@ export default class MochaAdapter extends EventEmitter {
9797
}
9898

9999
onStart () {
100-
var globalSuiteStart = this.convertToSuiteStart(this.runner.suite);
100+
const globalSuiteStart = this.convertToSuiteStart(this.runner.suite);
101101
globalSuiteStart.name = undefined;
102102

103103
this.emit('runStart', globalSuiteStart);
@@ -144,9 +144,9 @@ export default class MochaAdapter extends EventEmitter {
144144
}
145145

146146
onEnd () {
147-
var globalSuiteEnd = this.convertToSuiteEnd(this.runner.suite);
147+
const globalSuiteEnd = this.convertToSuiteEnd(this.runner.suite);
148148
globalSuiteEnd.name = undefined;
149149

150150
this.emit('runEnd', globalSuiteEnd);
151151
}
152-
}
152+
};

0 commit comments

Comments
 (0)