Skip to content

Commit

Permalink
Release: Bring back Rollup, Add coverage, Add browser test
Browse files Browse the repository at this point in the history
Follows-up 3708273. Now that I've had a while to take
inventory, I think we can bring this back to make distribution
and re-use a bit easier for things like browserstack-runner.

Highlights:

* Switch from 'chalk' to 'kleur'.
  Kleur is a a dependency-free alternative that is safe to run
  in a browser environment without needing to do anything extra
  to emulate Node etc.

  Downstream browserstack-runner was having to mock the Node
  'process' global previously because of this. There are ways
  around that, but it's naturally simplest to just not have any
  code that is just naturally agnostic of Node vs browser.

  Ref browserstack/browserstack-runner#179.

* Use Karma to run the unit tests in the browser.

* Use NYC to generate a code coverage report over the unit
  and integration tests.
  • Loading branch information
Krinkle committed Sep 24, 2020
1 parent 1455774 commit 1ddc73a
Show file tree
Hide file tree
Showing 16 changed files with 3,677 additions and 95 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock.json binary
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/.nyc_output
/coverage
/dist
/node_modules
/log
/*.log
2 changes: 0 additions & 2 deletions .npmignore

This file was deleted.

8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ node_js:
- '10' # LTS
- '12' # LTS
- '14' # Current
script:
- "npm test"
jobs:
include:
- name: Code coverage
os: linux
node_js: "14"
script: npm run coveralls
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2014-2020 JS Reporters <https://github.com/js-reporters/>
Copyright 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
@@ -1,10 +1,10 @@
# js-reporters

[![Build Status](https://travis-ci.org/js-reporters/js-reporters.svg?branch=master)](https://travis-ci.org/js-reporters/js-reporters)
[![Chat on Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/js-reporters/js-reporters)
[![Build Status](https://travis-ci.org/js-reporters/js-reporters.svg?branch=master)](https://travis-ci.org/js-reporters/js-reporters)
[![Coverage Status](https://coveralls.io/repos/github/js-reporters/js-reporters/badge.svg?branch=master)](https://coveralls.io/github/js-reporters/js-reporters?branch=master)
[![npm](https://img.shields.io/npm/dm/js-reporters.svg)](https://www.npmjs.com/package/js-reporters)
[![npm](https://img.shields.io/npm/v/js-reporters.svg)](https://www.npmjs.com/package/js-reporters)
[![npm](https://img.shields.io/npm/l/js-reporters.svg?maxAge=2592000)](https://www.npmjs.com/package/js-reporters)

The Common Reporter Interface (CRI) for JavaScript Testing Frameworks.

Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const EventEmitter = require('events');
const QUnitAdapter = require('./lib/adapters/QUnitAdapter.js');
const JasmineAdapter = require('./lib/adapters/JasmineAdapter.js');
const MochaAdapter = require('./lib/adapters/MochaAdapter.js');
Expand All @@ -23,6 +24,7 @@ module.exports = {
TestEnd,
SuiteStart,
SuiteEnd,
EventEmitter,
createSuiteStart,
createTestStart,
createTestEnd,
Expand Down
41 changes: 41 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = function (config) {
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');

config.set({
files: [
'node_modules/sinon/pkg/sinon.js',
'test/unit/tap-reporter.js',
'test/unit/helpers.js'
],
preprocessors: {
'test/unit/**.js': ['rollup']
},
rollupPreprocessor: {
external: ['sinon'],
output: {
globals: {
sinon: 'sinon'
},
format: 'iife',
name: 'JsReporters_Test',
sourcemap: true
},
plugins: [
// For 'events' and 'kleur'
nodeResolve({
preferBuiltins: false
}),
commonjs({
// This makes require() work like in Node.js,
// instead of wrapped in a {default:…} object.
requireReturnsDefault: 'auto'
})
]
},
frameworks: ['qunit'],
browsers: ['FirefoxHeadless', 'ChromeHeadless'],
singleRun: true,
autoWatch: false
});
};
14 changes: 7 additions & 7 deletions lib/reporters/TapReporter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const chalk = require('chalk');
const kleur = require('kleur');

const hasOwn = Object.hasOwnProperty;

Expand Down Expand Up @@ -140,22 +140,22 @@ module.exports = class TapReporter {
if (test.status === 'passed') {
console.log(`ok ${this.testCount} ${test.fullName.join(' > ')}`);
} else if (test.status === 'skipped') {
console.log(chalk.yellow(`ok ${this.testCount} # SKIP ${test.fullName.join(' > ')}`));
console.log(kleur.yellow(`ok ${this.testCount} # SKIP ${test.fullName.join(' > ')}`));
} else if (test.status === 'todo') {
console.log(chalk.cyan(`not ok ${this.testCount} # TODO ${test.fullName.join(' > ')}`));
console.log(kleur.cyan(`not ok ${this.testCount} # TODO ${test.fullName.join(' > ')}`));
test.errors.forEach((error) => this.logError(error, 'todo'));
} else {
console.log(chalk.red(`not ok ${this.testCount} ${test.fullName.join(' > ')}`));
console.log(kleur.red(`not ok ${this.testCount} ${test.fullName.join(' > ')}`));
test.errors.forEach((error) => this.logError(error));
}
}

onRunEnd (globalSuite) {
console.log(`1..${globalSuite.testCounts.total}`);
console.log(`# pass ${globalSuite.testCounts.passed}`);
console.log(chalk.yellow(`# skip ${globalSuite.testCounts.skipped}`));
console.log(chalk.cyan(`# todo ${globalSuite.testCounts.todo}`));
console.log(chalk.red(`# fail ${globalSuite.testCounts.failed}`));
console.log(kleur.yellow(`# skip ${globalSuite.testCounts.skipped}`));
console.log(kleur.cyan(`# todo ${globalSuite.testCounts.todo}`));
console.log(kleur.red(`# fail ${globalSuite.testCounts.failed}`));
}

logError (error, severity) {
Expand Down
Loading

0 comments on commit 1ddc73a

Please sign in to comment.