Skip to content

Commit

Permalink
Remove use of deprecated QUnit.load() (#184)
Browse files Browse the repository at this point in the history
QUnit 2.21.0 will be emitting a deprecation warning from QUnit.load.

Calling this method has not been needed for several years, since
QUnit 2.1.1, released in 2017.
https://github.com/qunitjs/qunit/releases/tag/2.1.1

Also:
* document how this works.
* remove unused `defaultConfig` parameter.
  It is only ever used one way in src/, and tests didn't cover
  other input anyway. It now improves test coverage by covering
  the actual value instead of relying on tests passing the same as
  the real code.
  • Loading branch information
Krinkle authored Feb 9, 2024
1 parent 289106e commit 8fe30fb
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 28 deletions.
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
"peerDependencies": {
"karma": "^4.0.0 || ^5.0.0 || ^6.0.0",
"qunit": "^2.0.0"
"qunit": "^2.1.1"
},
"license": "MIT",
"contributors": [
Expand Down
28 changes: 18 additions & 10 deletions src/adapter.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict'

function createQUnitConfig (karma, defaultConfig) { // eslint-disable-line no-unused-vars
var config = defaultConfig || {}

if (!karma.config || !karma.config.qunit) {
return config
function createQUnitConfig (karma) { // eslint-disable-line no-unused-vars
var config = {
autostart: false
}

for (var key in karma.config.qunit) {
config[key] = karma.config.qunit[key]
if (karma.config && karma.config.qunit) {
for (var key in karma.config.qunit) {
config[key] = karma.config.qunit[key]
}
}

return config
Expand Down Expand Up @@ -111,9 +111,17 @@ function createQUnitStartFn (tc, runnerPassedIn) { // eslint-disable-line no-unu
tc.result(result)
})

runner.load()

// honor autostart config, useful for tests loaded asynchronously
// karma-qunit uses `QUnit.config.autostart = false` internally
// so window.__karma__.start (points to here) controls QUnit.start
// and thus naturally waits for any file-loading karma plugins
// (especially async like AMD/RequireJS).
//
// ensure the the option to turn off QUnit autostart is also
// available to end-users, by letting them set `qunit.autostart: false`
// in karma.config.js. The end-user may then call QUnit.start() when
// they are ready.
//
// https://github.com/karma-runner/karma-qunit/issues/27
if (config.autostart !== false) {
setTimeout(function () {
runner.start()
Expand Down
10 changes: 1 addition & 9 deletions src/adapter.wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@

%CONTENT%

var config = createQUnitConfig(window.__karma__, {
autostart: false
});
var config = createQUnitConfig(window.__karma__);

for (var key in config) {
window.QUnit.config[key] = config[key];
}

if (window.removeEventListener) {
window.removeEventListener('load', window.QUnit.load, false);
} else if (window.detachEvent) {
window.detachEvent('onload', window.QUnit.load);
}

window.__karma__.start = createQUnitStartFn(window.__karma__);
})(typeof window !== 'undefined' ? window : global);
6 changes: 3 additions & 3 deletions test/src/adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('adapter qunit', function () {
it('should return the default configuration passed', function () {
tc.config = {}
tc.config.qunit = {}
config = createQUnitConfig(tc, { autostart: false })
config = createQUnitConfig(tc)
expect(config.autostart).toBe(false)
})

Expand All @@ -42,12 +42,12 @@ describe('adapter qunit', function () {
tc.config.qunit = {
autostart: true
}
config = createQUnitConfig(tc, { autostart: false })
config = createQUnitConfig(tc)
expect(config.autostart).toBe(true)
})

it('should return the default config for no client config', function () {
config = createQUnitConfig(tc, { autostart: false })
config = createQUnitConfig(tc)
expect(config).toEqual({ autostart: false })
})
})
Expand Down
4 changes: 0 additions & 4 deletions test/src/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ var MockRunner = function () { // eslint-disable-line no-unused-vars
this.on('log', fn)
}

this.load = function () {
// NOOP
}

this.start = function () {
// NOOP
}
Expand Down

0 comments on commit 8fe30fb

Please sign in to comment.