From eeb0e1f736dca8143a748ddd974c32a9fbd6c32c Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Thu, 9 Apr 2020 12:16:16 -0600 Subject: [PATCH] Fixing tests in IE11 (#2167) --- package.json | 3 ++- src/extras/global.js | 2 +- test/browser/core.js | 34 +++++++++++++++++++++++----------- test/browser/transform.js | 7 +++++-- test/browser/worker.js | 1 + test/system-node.js | 2 +- test/test.html | 12 ++++++++++-- 7 files changed, 43 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 5352512d..43d87657 100644 --- a/package.json +++ b/package.json @@ -34,11 +34,12 @@ "rollup": "^2.2.0", "rollup-plugin-terser": "^5.3.0", "source-map-support": "^0.5.16", + "symbol-es6": "^0.1.2", "terser": "^4.6.7", "whatwg-fetch": "^3.0.0" }, "scripts": { - "build": "rimraf dist && concurrently -n w: 'yarn:build:*'", + "build": "rimraf dist && concurrently -n w: 'npm:build:*'", "build:node": "node --experimental-modules build-node.js", "build:browser": "rollup -c", "build-browser-dev": "rollup -c --environment dev", diff --git a/src/extras/global.js b/src/extras/global.js index 91d1cfee..430a5374 100644 --- a/src/extras/global.js +++ b/src/extras/global.js @@ -85,6 +85,6 @@ function shouldSkipProperty(p) { return !global.hasOwnProperty(p) || !isNaN(p) && p < global.length - || isIE11 && global[p] && global[p].parent === window; + || isIE11 && global[p] && typeof window !== 'undefined' && global[p].parent === window; } })(typeof self !== 'undefined' ? self : global); diff --git a/test/browser/core.js b/test/browser/core.js index d2ae6745..28cf20a2 100644 --- a/test/browser/core.js +++ b/test/browser/core.js @@ -159,17 +159,19 @@ suite('SystemJS Standard Tests', function() { }); }); - test('should load a css module', async function () { - const m = await System.import('fixturesbase/css-modules/a.css'); - assert.ok(m); - assert.ok(m.default instanceof CSSStyleSheet); - document.adoptedStyleSheets = [...document.adoptedStyleSheets, m.default]; + test('should load a css module', function () { + return System.import('fixturesbase/css-modules/a.css').then(function (m) { + assert.ok(m); + assert.ok(isCSSStyleSheet(m.default)); + document.adoptedStyleSheets = document.adoptedStyleSheets.concat(m.default); + }); }); - test('should support application/javascript css module override', async function () { - const m = await System.import('fixturesbase/css-modules/javascript.css'); - assert.ok(m); - assert.ok(m.css, 'module'); + test('should support application/javascript css module override', function () { + return System.import('fixturesbase/css-modules/javascript.css').then(function (m) { + assert.ok(m); + assert.ok(m.css, 'module'); + }); }); test('should throw when trying to load an HTML module', function () { @@ -208,14 +210,24 @@ suite('SystemJS Standard Tests', function() { test('should not get confused by filenames in url hash when resolving module type', function () { return System.import('fixturesbase/css-modules/hash.css?foo=bar.html').then(function (m) { assert.ok(m); - assert.ok(m.default instanceof CSSStyleSheet); + assert.ok(isCSSStyleSheet(m.default)); }); }); test('should not get confused by filenames in search params hash when resolving module type', function () { return System.import('fixturesbase/css-modules/search-param.css?param=foo.html').then(function (m) { assert.ok(m); - assert.ok(m.default instanceof CSSStyleSheet); + assert.ok(isCSSStyleSheet(m.default)); }); }); + + var isIE11 = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('Trident') !== -1; + + function isCSSStyleSheet(obj) { + if (isIE11) { + return obj.cssRules; + } else { + return obj instanceof CSSStyleSheet; + } + } }); diff --git a/test/browser/transform.js b/test/browser/transform.js index 682b64fb..68bae7d2 100644 --- a/test/browser/transform.js +++ b/test/browser/transform.js @@ -6,6 +6,8 @@ suite('Transform Loader', function() { return source; }; + const supportsWebAssembly = typeof WebAssembly !== 'undefined' && typeof process === 'undefined'; + suite('SystemJS standard tests', function () { test('String encoding', function () { @@ -67,7 +69,7 @@ suite('Transform Loader', function() { }); }); - if (typeof WebAssembly !== 'undefined' && typeof process === 'undefined') + if (supportsWebAssembly) test('Loading WASM', function () { return System.import('fixtures/wasm/example.wasm') .then(function (m) { @@ -76,7 +78,8 @@ suite('Transform Loader', function() { }); test('Verification', function () { - assert.equal(translateCnt, 8); + const expected = supportsWebAssembly ? 8 : 7; + assert.equal(translateCnt, expected); }); }); }); diff --git a/test/browser/worker.js b/test/browser/worker.js index 631a3886..558de5e9 100644 --- a/test/browser/worker.js +++ b/test/browser/worker.js @@ -1,3 +1,4 @@ +importScripts('../../node_modules/bluebird/js/browser/bluebird.core.js'); importScripts('../../dist/system.js'); System.import('../fixtures/register-modules/es6-withdep.js').then(function(m) { diff --git a/test/system-node.js b/test/system-node.js index 3c117a6b..1d0e5a9b 100644 --- a/test/system-node.js +++ b/test/system-node.js @@ -15,7 +15,7 @@ describe('NodeJS version of SystemJS', () => { describe('resolve', () => { it('provides a default base url if one is not specified', () => { - assert.equal(System.resolve('./foo.js'), pathToFileURL(process.cwd()) + path.sep + 'foo.js'); + assert.equal(System.resolve('./foo.js'), pathToFileURL(process.cwd()).href + '/foo.js'); }); it('works if a full url is provided', () => { diff --git a/test/test.html b/test/test.html index 16ce24b8..e5e23e51 100644 --- a/test/test.html +++ b/test/test.html @@ -6,9 +6,17 @@ + + -