Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt js reporters standard #1026

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0ed05b1
Core: QUnit logging system uses EventEmitter
JamesMGreene Sep 25, 2014
a167331
fixup! Core: QUnit logging system uses EventEmitter
leobalter Oct 22, 2015
fb7d73c
Build: Improve grunt test-on-node task
leobalter Oct 25, 2015
3a502ef
fixup! Core: QUnit logging system uses EventEmitter
leobalter Oct 27, 2015
2fd7197
fixup! Core: QUnit logging system uses EventEmitter
leobalter Oct 27, 2015
5dfb37f
All: fix linting issues
flore77 Aug 2, 2016
48bab35
Tests: remove from testing non-existing test file
flore77 Aug 2, 2016
31f4313
Core: fix module hooks by notifying tests ran
flore77 Aug 2, 2016
628666a
HTML Reporter: restore the begin callback code
flore77 Aug 2, 2016
b5679b6
All: comment out unused function
flore77 Aug 2, 2016
404918d
Core: export registerLoggingCallbacks function
flore77 Aug 9, 2016
5237b39
Core: keep old events along with the new ones
flore77 Aug 11, 2016
4f15575
All: kepp reporter and grunt tasks on old callbacks
flore77 Aug 13, 2016
8cecfb6
Build: add js-reporters as dependency
flore77 Aug 15, 2016
444ce47
Core: add runStart event with new data
flore77 Aug 15, 2016
85c5b98
Build: add js-reporters into the rollup process
flore77 Aug 19, 2016
82f39b2
Tests: add tests to check the emitting and order of the events
flore77 Aug 19, 2016
fc4a9e1
Core: add all js-reporters events
flore77 Aug 19, 2016
251aa50
All: fix linting issues
flore77 Aug 19, 2016
f522ae6
Core: finish adoption of js-reporters events
flore77 Aug 19, 2016
6ea1edb
Tests: add one test more for events
flore77 Aug 19, 2016
79e4397
All: fix linting
flore77 Aug 20, 2016
1dfaa16
Core: finish adoption of js-reporters events
flore77 Aug 21, 2016
315c9b3
Tests: finish events testing
flore77 Aug 21, 2016
978064f
Tests: add more event testing
flore77 Aug 28, 2016
32c24ca
Core: fix the emitting order of nested modules
flore77 Aug 28, 2016
0a69b20
Tests: enhance events testing
flore77 Aug 31, 2016
9fd2e0e
Tests: add events testing to the browser and browserstack
flore77 Aug 31, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ grunt.initConfig( {
"test/overload.html",
"test/regex-filter.html",
"test/regex-exclude-filter.html",
"test/string-filter.html"
"test/string-filter.html",
"test/events/global-test.html",
"test/events/nested-suites.html",
"test/events/combined.html"
]
},
coveralls: {
Expand All @@ -123,6 +126,9 @@ grunt.initConfig( {
},
"test-on-node": {
files: [
"test/events/global-test",
"test/events/nested-suites",
"test/events/combined",
"test/logs",
"test/main/test",
"test/main/assert",
Expand Down
3 changes: 2 additions & 1 deletion build/browserstack-current-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"test_path": [
"test/index.html",
"test/logs.html",
"test/seed.html"
"test/seed.html",
"test/events/combined.html"
],
"browsers": [
"chrome_current",
Expand Down
3 changes: 2 additions & 1 deletion build/browserstack-legacy-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"test_path": [
"test/index.html",
"test/logs.html",
"test/seed.html"
"test/seed.html",
"test/events/combined.html"
],
"browsers": [
"chrome_previous",
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"qunit/qunit.css",
"LICENSE.txt"
],
"dependencies": {},
"dependencies": {
"js-reporters": "1.1.0"
},
"devDependencies": {
"async": "1.5.2",
"babel-plugin-external-helpers": "6.8.0",
Expand All @@ -47,7 +49,8 @@
"grunt-search": "0.1.8",
"load-grunt-tasks": "3.4.1",
"requirejs": "2.2.0",
"rollup-plugin-babel": "2.6.1"
"rollup-plugin-babel": "2.6.1",
"rollup-plugin-node-resolve": "2.0.0"
},
"scripts": {
"browserstack": "sh build/run-browserstack.sh",
Expand Down
2 changes: 2 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* jshint multistr:true, node:true */

var babel = require( "rollup-plugin-babel" );
var nodeResolve = require( "rollup-plugin-node-resolve" );

module.exports = {
format: "iife",
exports: "none",
plugins: [
nodeResolve(),
babel( {
presets: [

Expand Down
43 changes: 42 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import exportQUnit from "./export";

import config from "./core/config";
import { defined, extend, objectType, is, now } from "./core/utilities";
import { registerLoggingCallbacks, runLoggingCallbacks } from "./core/logging";
import { on, emit, registerLoggingCallbacks,
runLoggingCallbacks } from "./core/logging";
import { sourceFromStacktrace } from "./core/stacktrace";

import {Suite} from "js-reporters/lib/Data";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


const QUnit = {};

var globalStartCalled = false;
Expand Down Expand Up @@ -41,6 +44,7 @@ extend( QUnit, {
}

module = createModule();
createSuite( module );

if ( testEnvironment && ( testEnvironment.setup || testEnvironment.teardown ) ) {
console.warn(
Expand Down Expand Up @@ -94,6 +98,30 @@ extend( QUnit, {
return module;
}

function createSuite( module ) {
var parentSuite;
var fullName;
var suite;

if ( module.parentModule !== null ) {
parentSuite = config.moduleToSuite[ module.parentModule.moduleId ];
} else {
parentSuite = config.globalSuite;
}

fullName = parentSuite.fullName.slice();
fullName.push( module.name );

suite = new Suite( module.name, fullName, [], [] );

parentSuite.childSuites.push( suite );
suite.parent = parentSuite;
suite.finishedTests = 0;
config.moduleToSuite[ module.moduleId ] = suite;

return suite;
}

function setCurrentModule( module ) {
config.currentModule = module;
}
Expand All @@ -106,6 +134,8 @@ extend( QUnit, {

only: only,

on: on,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we can now use ES6 (right?), this can be shortened to just on,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I would leave it like this, to be equal to the others props, this can be changed in another pr.


start: function( count ) {
var globalStartAlreadyCalled = globalStartCalled;

Expand Down Expand Up @@ -224,6 +254,8 @@ export function begin() {
totalTests: Test.count,
modules: modulesLog
} );

emit( "runStart", config.globalSuite );
}

config.blocking = false;
Expand Down Expand Up @@ -272,6 +304,13 @@ function done() {
total: config.moduleStats.all,
runtime: now() - config.moduleStats.started
} );

// Do not emit the "suiteEnd" event for the globalSuite.
if ( config.previousModule.moduleId ) {
var suite = config.moduleToSuite[ config.previousModule.moduleId ];

emit( "suiteEnd", suite );
}
}
delete config.previousModule;

Expand All @@ -284,6 +323,8 @@ function done() {
total: config.stats.all,
runtime: runtime
} );

emit( "runEnd", config.globalSuite );
}

function setHook( module, hookName ) {
Expand Down
8 changes: 7 additions & 1 deletion src/core/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Suite} from "js-reporters/lib/Data";

/**
* Config object: Maintain internal state
* Later exposed as QUnit.config
Expand Down Expand Up @@ -46,7 +48,11 @@ const config = {
tests: []
},

callbacks: {}
callbacks: {},

globalSuite: new Suite( undefined, [], [], [] ),

moduleToSuite: {}
};

// Push a loose unnamed module to the modules collection
Expand Down
41 changes: 40 additions & 1 deletion src/core/logging.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import config from "./config";
import { objectType } from "./utilities";
import { objectType, inArray } from "./utilities";

var listeners = {};

// Register logging callbacks
export function registerLoggingCallbacks( obj ) {
Expand Down Expand Up @@ -41,3 +43,40 @@ export function runLoggingCallbacks( key, args ) {
callbacks[ i ]( args );
}
}

export function emit( type, data ) {
var i, callbacks;

// Validate
if ( objectType( type ) !== "string" ) {
throw new Error( "Emitting QUnit events requires an event type" );
}

// Ensure a consistent event run
callbacks = [].slice.call( listeners[ type ] || [] );
for ( i = 0; i < callbacks.length; i++ ) {
callbacks[ i ]( data );
}
}

export function on( type, listener ) {

// Validate
if ( objectType( type ) !== "string" ) {
throw new Error( "Adding QUnit events requires an event type" );
}

if ( objectType( listener ) !== "function" ) {
throw new Error( "Adding QUnit events requires a listener function" );
}

// Initialize collection of this logging callback
if ( !listeners[ type ] ) {
listeners[ type ] = [];
}

// Filter out duplicate listeners
if ( inArray( listener, listeners[ type ] ) < 0 ) {
listeners[ type ].push( listener );
}
}
Loading