UNPKG

1.57 kBJavaScriptView Raw
1describe('Worker', function () {
2 var workerErrorEventToError = function (errorEvent) {
3 var errorText = 'Error in Worker';
4 if (errorEvent.filename !== undefined) {
5 errorText += ' ' + errorEvent.filename;
6 }
7 if (errorEvent.lineno !== undefined) {
8 errorText += '(' + errorEvent.lineno + ')';
9 }
10 if (errorEvent.message !== undefined) {
11 errorText += ': ' + errorEvent.message;
12 }
13 return new Error(errorText);
14 };
15 var canRunWorkerTestInCurrentContext = function () {
16 var workerConstructorExists = typeof Worker !== 'undefined';
17 var locationPropertyExists = typeof location !== 'undefined';
18 var runningOnFileUriScheme = locationPropertyExists && location.protocol === 'file:';
19
20 // The Worker constructor doesn't exist in some older browsers nor does it exist in non-browser contexts like Node.
21 // Additionally some browsers (at least Chrome) don't allow Workers over file URIs.
22 // To prevent false negative test failures in the cases where Workers are unavailable for either of those reasons
23 // we skip this test.
24 return workerConstructorExists && !runningOnFileUriScheme;
25 };
26
27 if (canRunWorkerTestInCurrentContext()) {
28 it('can import es6-shim', function (done) {
29 var worker = new Worker('worker-runner.workerjs');
30 worker.addEventListener('error', function (errorEvent) { throw workerErrorEventToError(errorEvent); });
31 worker.addEventListener('message', function (messageEvent) {
32 expect(messageEvent.data).to.eql('ready');
33 done();
34 });
35 });
36 }
37});