|
| 1 | +(function () { |
| 2 | + var envKey = new URLSearchParams (location.search).get ("env"); |
| 3 | + |
| 4 | + var link0 = document.createElement ('link'); |
| 5 | + link0.rel = "stylesheet"; |
| 6 | + link0.href = "https://code.jquery.com/qunit/qunit-2.2.0.css"; |
| 7 | + document.head.appendChild (link0); |
| 8 | + |
| 9 | + var link = document.createElement ('link'); |
| 10 | + link.rel = "stylesheet"; |
| 11 | + link.href = "test.css"; |
| 12 | + document.head.appendChild (link); |
| 13 | + |
| 14 | + var meta = document.createElement ('viewport'); |
| 15 | + meta.name = 'viewport'; |
| 16 | + meta.content = "width=device-width"; |
| 17 | + document.head.appendChild (meta); |
| 18 | + |
| 19 | + var a = document.createElement ('a'); |
| 20 | + a.href = '/'; |
| 21 | + a.textContent = 'Top'; |
| 22 | + document.body.appendChild (a); |
| 23 | + |
| 24 | + var qunitLoaded = new Promise (function (ok, error) { |
| 25 | + var script = document.createElement ('script'); |
| 26 | + script.src = 'https://code.jquery.com/qunit/qunit-2.2.0.js'; |
| 27 | + script.onload = ok; |
| 28 | + script.onerror = error; |
| 29 | + document.body.appendChild (script); |
| 30 | + }); |
| 31 | + |
| 32 | + var scriptLoaded = new Promise (function (ok, error) { |
| 33 | + var script = document.createElement ('script'); |
| 34 | + script.src = '../src/time.js'; |
| 35 | + script.onload = ok; |
| 36 | + script.onerror = error; |
| 37 | + document.body.appendChild (script); |
| 38 | + }); |
| 39 | + |
| 40 | + qunitLoaded.then (function () { |
| 41 | + QUnit.config.current = {ignoreGlobalErrors: true}; |
| 42 | + document.querySelectorAll ('test-code').forEach (function (e) { |
| 43 | + QUnit.test (e.getAttribute ('name'), function (assert) { |
| 44 | + var AsyncFunction = Object.getPrototypeOf (async function (){}).constructor; |
| 45 | + var code = new AsyncFunction (e.textContent); |
| 46 | + var context = { |
| 47 | + currentScript: e, |
| 48 | + wait: (n) => new Promise ((ok) => setTimeout (ok, n || 0)), |
| 49 | + assertEqualError: function (actual, expected, name) { |
| 50 | + this.assert.throws (() => { throw actual }, expected, name); |
| 51 | + }, // assertEqualError |
| 52 | + assertWindowError: function (code, expected, name) { |
| 53 | + var onerror = window.onerror; |
| 54 | + var error = undefined; |
| 55 | + window.onerror = function (a, b, c, d, e) { |
| 56 | + error = e || arguments; |
| 57 | + return true; |
| 58 | + }; |
| 59 | + code (); |
| 60 | + window.onerror = onerror; |
| 61 | + this.assertEqualError (error, expected, name); |
| 62 | + }, // assertWindowError |
| 63 | + env: envKey, |
| 64 | + }; |
| 65 | + var originalOnError; |
| 66 | + return scriptLoaded.then (function () { |
| 67 | + context.assert = assert; |
| 68 | + originalOnError = window.onerror; |
| 69 | + if (e.hasAttribute ('ignoreerrors')) window.onerror = undefined; |
| 70 | + return code.apply (context); |
| 71 | + }).then (assert.async (), function (e) { |
| 72 | + assert.equal (true, false, "Should not be rejected"); |
| 73 | + assert.equal (e, null, "Exception"); |
| 74 | + }).then (() => window.onerror = originalOnError); |
| 75 | + }); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + var div2 = document.createElement ('div'); |
| 80 | + div2.id = "qunit"; |
| 81 | + div2.dir = 'ltr'; |
| 82 | + document.body.appendChild (div2); |
| 83 | +}) (); |
| 84 | +/* |
| 85 | +
|
| 86 | +Per CC0 <https://creativecommons.org/publicdomain/zero/1.0/>, to the |
| 87 | +extent possible under law, the author has waived all copyright and |
| 88 | +related or neighboring rights to this work. |
| 89 | +
|
| 90 | +*/ |
0 commit comments