Skip to content

Commit

Permalink
[BREAKING CHANGE] Build: Use ES6 plainly (remove Rollup and Babel)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Krinkle committed Sep 7, 2020
1 parent 04bdd8a commit 3708273
Show file tree
Hide file tree
Showing 29 changed files with 2,850 additions and 6,734 deletions.
8 changes: 0 additions & 8 deletions .babelrc

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/dist
/node_modules
/*.log
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ node_js:
- '12' # LTS
- '14' # Current
script:
- "npm run build"
- "npm test"
4 changes: 1 addition & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
The MIT License (MIT)

Copyright (c) 2014 JS Reporters
Copyright 2014-2020 JS Reporters <https://github.com/js-reporters/>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ Listen to the events and receive the emitted data:

```js
// Attach one of the exiting adapters.
var runner = JsReporters.autoRegister();
const runner = JsReporters.autoRegister();

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

runner.on('runEnd', function(globalSuite) {
var testCounts = globalSuite.testCounts;
const testCounts = globalSuite.testCounts;

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

Expand Down
23 changes: 14 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import QUnitAdapter from './lib/adapters/QUnitAdapter.js';
import JasmineAdapter from './lib/adapters/JasmineAdapter.js';
import MochaAdapter from './lib/adapters/MochaAdapter.js';
import TapReporter from './lib/reporters/TapReporter.js';
import ConsoleReporter from './lib/reporters/ConsoleReporter.js';
import {Assertion, TestStart, TestEnd, SuiteStart, SuiteEnd} from './lib/Data.js';
import {autoRegister, createSuiteStart, createTestStart,
createTestEnd, createSuiteEnd} from './lib/helpers.js';
const QUnitAdapter = require('./lib/adapters/QUnitAdapter.js');
const JasmineAdapter = require('./lib/adapters/JasmineAdapter.js');
const MochaAdapter = require('./lib/adapters/MochaAdapter.js');
const TapReporter = require('./lib/reporters/TapReporter.js');
const ConsoleReporter = require('./lib/reporters/ConsoleReporter.js');
const { Assertion, TestStart, TestEnd, SuiteStart, SuiteEnd } = require('./lib/Data.js');
const {
createSuiteStart,
createTestStart,
createTestEnd,
createSuiteEnd
} = require('./lib/helpers.js');
const { autoRegister } = require('./lib/auto.js');

export default {
module.exports = {
QUnitAdapter,
JasmineAdapter,
MochaAdapter,
Expand Down
46 changes: 0 additions & 46 deletions karma.conf.js

This file was deleted.

36 changes: 22 additions & 14 deletions lib/Data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function getAllTests (suite) {
var childSuiteTests = suite.childSuites
const childSuiteTests = suite.childSuites
.map((childSuite) => getAllTests(childSuite))
.reduce((allTests, a) => allTests.concat(a), []);

Expand All @@ -17,14 +17,14 @@ function getRuntime (suite) {
}

function getStatus (suite) {
var passed = 0;
var failed = 0;
var skipped = 0;
var todo = 0;
var tests = getAllTests(suite);
let passed = 0;
let failed = 0;
let skipped = 0;
let todo = 0;
const tests = getAllTests(suite);

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

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

function getSuiteStartTestCounts (suite) {
var tests = getAllTests(suite);
const tests = getAllTests(suite);

return {
total: tests.length
};
}

function getSuiteEndTestCounts (suite) {
var tests = getAllTests(suite);
const tests = getAllTests(suite);

return {
passed: tests.filter((test) => test.status === 'passed').length,
Expand All @@ -72,7 +72,7 @@ function getSuiteEndTestCounts (suite) {
};
}

export class Assertion {
class Assertion {
/**
* @param {Boolean} passed
* @param {*} actual
Expand All @@ -91,7 +91,7 @@ export class Assertion {
}
}

export class TestStart {
class TestStart {
/**
* @param {String} name
* @param {String} suiteName
Expand All @@ -104,7 +104,7 @@ export class TestStart {
}
}

export class TestEnd {
class TestEnd {
/**
* @param {String} name
* @param {String} suiteName
Expand All @@ -125,7 +125,7 @@ export class TestEnd {
}
}

export class SuiteStart {
class SuiteStart {
/**
* @param {String} name
* @param {String[]} fullName
Expand All @@ -141,7 +141,7 @@ export class SuiteStart {
}
}

export class SuiteEnd {
class SuiteEnd {
/**
* @param {String} name
* @param {String[]} fullName
Expand All @@ -166,3 +166,11 @@ export class SuiteEnd {
this.runtime = runtime || getRuntime(this);
}
}

module.exports = {
Assertion,
TestStart,
TestEnd,
SuiteStart,
SuiteEnd
};
31 changes: 15 additions & 16 deletions lib/adapters/JasmineAdapter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import EventEmitter from 'events';
import {Assertion, TestEnd, SuiteStart} from '../Data.js';
import * as helpers from '../helpers.js';
const EventEmitter = require('events');
const { Assertion, TestEnd, SuiteStart } = require('../Data.js');
const helpers = require('../helpers.js');

/**
* Limitations:
* - Errors in afterAll are ignored.
*/
export default class JasmineAdapter extends EventEmitter {
module.exports = class JasmineAdapter extends EventEmitter {
constructor (jasmine) {
super();

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

var reporter = {
const reporter = {
jasmineStarted: this.onJasmineStarted.bind(this),
specDone: this.onSpecDone.bind(this),
specStarted: this.onSpecStarted.bind(this),
Expand All @@ -35,14 +35,14 @@ export default class JasmineAdapter extends EventEmitter {
}

createAssertion (expectation) {
let stack = expectation.stack !== '' ? expectation.stack : undefined;
const stack = expectation.stack !== '' ? expectation.stack : undefined;

return new Assertion(expectation.passed, expectation.actual,
expectation.expected, expectation.message, stack);
}

saveTestDetails (jasmineSpec) {
var test = this.tests[jasmineSpec.id];
const test = this.tests[jasmineSpec.id];

test.errors = [];
test.assertions = [];
Expand Down Expand Up @@ -77,9 +77,9 @@ export default class JasmineAdapter extends EventEmitter {
* object using as key their unique ids provided by Jasmine.
*/
createGlobalSuite (jasmineSuite, fullName) {
var childSuites = [];
var tests = [];
var isGlobalSuite = this.isJasmineGlobalSuite(jasmineSuite);
const childSuites = [];
const tests = [];
const isGlobalSuite = this.isJasmineGlobalSuite(jasmineSuite);

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

fullName.push(child.description);

test = new TestEnd(child.description, suiteName, fullName.slice());
const test = new TestEnd(child.description, suiteName, fullName.slice());

fullName.pop();

Expand All @@ -103,8 +102,8 @@ export default class JasmineAdapter extends EventEmitter {
}
});

let name = !isGlobalSuite ? jasmineSuite.description : undefined;
let suite = new SuiteStart(name, fullName.slice(), tests, childSuites);
const name = !isGlobalSuite ? jasmineSuite.description : undefined;
const suite = new SuiteStart(name, fullName.slice(), tests, childSuites);

this.suites[jasmineSuite.id] = suite;

Expand Down Expand Up @@ -139,4 +138,4 @@ export default class JasmineAdapter extends EventEmitter {
onJasmineDone () {
this.emit('runEnd', helpers.createSuiteEnd(this.globalSuite));
}
}
};
26 changes: 13 additions & 13 deletions lib/adapters/MochaAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import EventEmitter from 'events';
import {Assertion, TestStart, TestEnd, SuiteStart, SuiteEnd} from '../Data.js';
const EventEmitter = require('events');
const { Assertion, TestStart, TestEnd, SuiteStart, SuiteEnd } = require('../Data.js');

export default class MochaAdapter extends EventEmitter {
module.exports = class MochaAdapter extends EventEmitter {
constructor (mocha) {
super();

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

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

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

convertTest (mochaTest) {
var suiteName;
var fullName;
let suiteName;
let fullName;

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

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

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

onStart () {
var globalSuiteStart = this.convertToSuiteStart(this.runner.suite);
const globalSuiteStart = this.convertToSuiteStart(this.runner.suite);
globalSuiteStart.name = undefined;

this.emit('runStart', globalSuiteStart);
Expand Down Expand Up @@ -144,9 +144,9 @@ export default class MochaAdapter extends EventEmitter {
}

onEnd () {
var globalSuiteEnd = this.convertToSuiteEnd(this.runner.suite);
const globalSuiteEnd = this.convertToSuiteEnd(this.runner.suite);
globalSuiteEnd.name = undefined;

this.emit('runEnd', globalSuiteEnd);
}
}
};
Loading

0 comments on commit 3708273

Please sign in to comment.