Skip to content

Commit

Permalink
Core: Restore IE9-10 support
Browse files Browse the repository at this point in the history
The cost of supporting IE9-10, given we support IE11 is tiny it is
only a handful of lines of code. In order to reduce the size of the
3.0 release and get it out the door, bring this back.

This also allows it to be used by the latest jQuery 3.x which supports
IE9 still.

Note that an ESM bundle was introduced in QUnit 3.0.0-alpha.4,
which is native ES6 and drops support for IE 9, IE 10 and IE 11, and
indeed all down-compilation for ES5-era browsers. You can use that
in order to get the same benefit in terms of bundle size.

Having said that, QUnit has one of the leanest bundle sizes of any
test framework even with IE9 support included.
  • Loading branch information
Krinkle committed Jan 16, 2025
1 parent 4a8410a commit 038672d
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"no-console": "error",
"compat/compat": [
"error",
"android >= 4.3, firefox >= 45, ie >= 11, safari >= 9.1, ios_saf >= 7, chrome >= 58"
"android >= 4.3, firefox >= 45, ie >= 9, safari >= 9.1, ios_saf >= 7, chrome >= 58"
]
}
},
Expand All @@ -61,7 +61,7 @@
"rules": {
"compat/compat": [
"error",
"android >= 4.3, firefox >= 45, ie >= 11, safari >= 9.1, chrome >= 58"
"android >= 4.3, firefox >= 45, ie >= 9, safari >= 9.1, chrome >= 58"
],
"max-len": "off",
"no-throw-literal": "off",
Expand Down
5 changes: 2 additions & 3 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ QUnit 3.0 Roadmap and feedback: https://github.com/qunitjs/qunit/issues/1498
### Removed

* Core: Remove support for Node.js 10-16. Node.js 18 or later is required. [#1727](https://github.com/qunitjs/qunit/issues/1727)
* Core: Remove support for IE 9 and IE 10. IE 11 remains supported. [#1725](https://github.com/qunitjs/qunit/issues/1725)
* Core: Remove support for PhantomJS.
* Core: Remove support for PhantomJS. (Steve McClure) [#1505](https://github.com/qunitjs/qunit/pull/1505)
* Core: Remove built-in export for AMD. You can still load your application and your QUnit tests with AMD/RequireJS. This only affects the loading of the qunit.js file itself. [Example: Loading with RequireJS](https://qunitjs.com/api/config/autostart/#loading-with-requirejs). (NullVoxPopuli) [#1729](https://github.com/qunitjs/qunit/issues/1729)
* Core: Remove deprecated [`QUnit.load()`](https://qunitjs.com/api/QUnit/load/). [#1084](https://github.com/qunitjs/qunit/issues/1084)
* Core: Remove deprecated `QUnit.onError()` and `QUnit.onUnhandledRejection()` in favor of [QUnit.onUncaughtException()](https://qunitjs.com/api/extension/QUnit.onUncaughtException/).
Expand Down Expand Up @@ -355,7 +354,7 @@ QUnit 3.0 Roadmap and feedback: https://github.com/qunitjs/qunit/issues/1498

### Deprecated

* HTML Reporter: Deprecate PhantomJS. (Steve McClure)
* HTML Reporter: Deprecate PhantomJS. (Steve McClure) [#1505](https://github.com/qunitjs/qunit/pull/1505)

### Fixed

Expand Down
2 changes: 2 additions & 0 deletions build/browserstack-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"firefox_78",
"firefox_previous",
"firefox_current",
"ie_9",
"ie_10",
"ie_11",
"edge_15",
"edge_18",
Expand Down
2 changes: 1 addition & 1 deletion build/browserstack-quick.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"browsers": [
"firefox_45",
"firefox_current",
"ie_11",
"ie_9",
"safari_9.1",
"safari_current",
"opera_current",
Expand Down
2 changes: 1 addition & 1 deletion src/core/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const sessionStorage = (function () {

// Fallback for ES6 Map, `new Map(iterable)`, and ES7 Map#keys
//
// Support: Safari 7; Map is undefined
// Support: IE 9-11, iOS 7; Map is undefined
// Support: iOS 8; `new Map(iterable)` is not supported
// Support: IE 11; Map#keys is undefined
export const StringMap = typeof g.Map === 'function'
Expand Down
6 changes: 5 additions & 1 deletion src/core/logger.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { console } from './globals.js';

// Support IE 9: No console object, unless the developer tools are not open.

// Support IE 9: Function#bind is supported, but no console.log.bind().

// Support: SpiderMonkey (mozjs 68+)
// The console object has a log method, but no warn method.

export default {
warn: console
? (console.warn || console.log).bind(console)
? Function.prototype.bind.call(console.warn || console.log, console)
: function () {}
};
3 changes: 2 additions & 1 deletion src/core/reporters/ConsoleReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export default class ConsoleReporter {
// Cache references to console methods to ensure we can report failures
// from tests tests that mock the console object itself.
// https://github.com/qunitjs/qunit/issues/1340
this.log = options.log || console.log.bind(console);
// Support IE 9: Function#bind is supported, but no console.log.bind().
this.log = options.log || Function.prototype.bind.call(console.log, console);

runner.on('error', this.onError.bind(this));
runner.on('runStart', this.onRunStart.bind(this));
Expand Down
12 changes: 10 additions & 2 deletions src/core/reporters/HtmlReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ const DOM = {
}

// Trim for prettiness
elem.className = set.trim();
elem.className = trim(set);
}
};

function trim (string) {
if (typeof string.trim === 'function') {
return string.trim();
} else {
return string.replace(/^\s+|\s+$/g, '');
}
}

function stripHtml (string) {
// Strip tags, html entity and whitespaces
return string
Expand Down Expand Up @@ -177,7 +185,7 @@ export default class HtmlReporter {
onFilterSubmit (ev) {
// Trim potential accidental whitespace so that QUnit doesn't throw an error about no tests matching the filter.
const filterInputElem = this.element.querySelector('#qunit-filter-input');
filterInputElem.value = filterInputElem.value.trim();
filterInputElem.value = trim(filterInputElem.value);

this.applyUrlParams();

Expand Down
7 changes: 4 additions & 3 deletions src/core/reporters/TapReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function prettyYamlValue (value, indent = 4) {
value = String(value);
}

// Support IE 11: Use isFinite instead of ES6 Number.isFinite
// Support IE 9-11: Use isFinite instead of ES6 Number.isFinite
if (typeof value === 'number' && !isFinite(value)) {
// Turn NaN and Infinity into simple strings.
// Paranoia: Don't return directly just in case there's
Expand Down Expand Up @@ -93,7 +93,7 @@ function prettyYamlValue (value, indent = 4) {
}

// See also <https://yaml-multiline.info/>
// Support IE 11: Avoid ES6 String#repeat
// Support IE 9-11: Avoid ES6 String#repeat
const prefix = (new Array(indent + 1)).join(' ');

const trailingLinebreakMatch = value.match(/\n+$/);
Expand Down Expand Up @@ -174,7 +174,8 @@ export default class TapReporter {
// Cache references to console methods to ensure we can report failures
// from tests tests that mock the console object itself.
// https://github.com/qunitjs/qunit/issues/1340
this.log = options.log || console.log.bind(console);
// Support IE 9: Function#bind is supported, but no console.log.bind().
this.log = options.log || Function.prototype.bind.call(console.log, console);

this.testCount = 0;
this.started = false;
Expand Down
6 changes: 3 additions & 3 deletions src/core/stacktrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function qunitFileName () {
let error = new Error();
if (!error.stack) {
// Copy of sourceFromStacktrace() to avoid circular dependency
// Support: IE 11
// Support: IE 9-11
try {
throw error;
} catch (err) {
Expand Down Expand Up @@ -83,7 +83,7 @@ export function annotateStacktrace (stack, formatInternal, eToString = null) {
let initialInternal = true;
for (let i = 0; i < frames.length; i++) {
const frame = frames[i];
const isInternal = (frame.indexOf(fileName) !== -1 || frame.indexOf('node:internal/') !== -1);
const isInternal = ((fileName && frame.indexOf(fileName) !== -1) || frame.indexOf('node:internal/') !== -1);
if (!isInternal) {
initialInternal = false;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ export function extractStacktrace (e, offset) {
export function sourceFromStacktrace (offset) {
let error = new Error();

// Support: IE 11, iOS 7
// Support: IE 9-11, iOS 7
// Not all browsers generate the `stack` property for `new Error()`
// See also https://github.com/qunitjs/qunit/issues/636
if (!error.stack) {
Expand Down
1 change: 1 addition & 0 deletions test/main/promise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Support IE 9: Promise not supported.
// Support SpiderMonkey: setTimeout is not supported, but native Promise is.
var defer = typeof setTimeout !== 'undefined'
// eslint-disable-next-line no-undef
Expand Down
1 change: 1 addition & 0 deletions test/webWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ QUnit.module('Web Worker');
QUnit.test('main tests', function (assert) {
assert.timeout(10000);
var done = assert.async();
// eslint-disable-next-line compat/compat -- Test skipped in IE9
var worker = new Worker('webWorker-worker.js');

worker.onmessage = function (event) {
Expand Down

0 comments on commit 038672d

Please sign in to comment.