OLD | NEW |
---|---|
1 /* | 1 /* |
2 * worker-test-harness should be considered a temporary polyfill around | 2 * worker-test-harness should be considered a temporary polyfill around |
3 * testharness.js for supporting Service Worker based tests. It should not be | 3 * testharness.js for supporting Service Worker based tests. It should not be |
4 * necessary once the test harness is able to drive worker based tests natively. | 4 * necessary once the test harness is able to drive worker based tests natively. |
5 * See https://github.com/w3c/testharness.js/pull/82 for status of effort to | 5 * See https://github.com/w3c/testharness.js/pull/82 for status of effort to |
6 * update upstream testharness.js. Once the upstreaming is complete, tests that | 6 * update upstream testharness.js. Once the upstreaming is complete, tests that |
7 * reference worker-test-harness should be updated to directly import | 7 * reference worker-test-harness should be updated to directly import |
8 * testharness.js. | 8 * testharness.js. |
9 */ | 9 */ |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 type: 'complete', | 66 type: 'complete', |
67 tests: results.tests, | 67 tests: results.tests, |
68 status: results.status | 68 status: results.status |
69 }; | 69 }; |
70 port.postMessage(message); | 70 port.postMessage(message); |
71 }); | 71 }); |
72 } | 72 } |
73 }); | 73 }); |
74 })(); | 74 })(); |
75 | 75 |
76 // 'promise_test' is a new kind of testharness test that handles some | 76 importScripts('/resources/testharness-helpers.js'); |
jsbell
2014/10/10 17:18:07
After some pondering, I think we should probably r
asanka
2014/10/10 19:39:11
+1. I also don't feel strongly, but I'm in favor o
Marijn Kruisselbrink
2014/10/10 20:32:55
Done.
| |
77 // boilerplate for testing with promises. | |
78 function promise_test(func, name, properties) { | |
79 properties = properties || {}; | |
80 var test = async_test(name, properties); | |
81 Promise.resolve(test.step(func, test, test)) | |
82 .then(function() { test.done(); }) | |
83 .catch(test.step_func(function(value) { | |
84 throw value; | |
85 })); | |
86 } | |
87 | 77 |
88 // Returns a promise that fulfills after the provided |promise| is fulfilled. | |
89 // The |test| succeeds only if |promise| rejects with an exception matching | |
90 // |code|. Accepted values for |code| follow those accepted for assert_throws(). | |
91 // The optional |description| describes the test being performed. | |
92 // E.g.: | |
93 // assert_promise_rejects( | |
94 // new Promise(...), // something that should throw an exception. | |
95 // 'NotFoundError', | |
96 // 'Should throw NotFoundError.'); | |
97 // | |
98 // assert_promise_rejects( | |
99 // new Promise(...), | |
100 // new TypeError(), | |
101 // 'Should throw TypeError'); | |
102 function assert_promise_rejects(promise, code, description) { | |
103 return promise.then( | |
104 function() { | |
105 throw 'assert_promise_rejects: ' + description + ' Promise did not throw.' ; | |
106 }, | |
107 function(e) { | |
108 if (code !== undefined) { | |
109 assert_throws(code, function() { throw e; }, description); | |
110 } | |
111 }); | |
112 } | |
OLD | NEW |