Skip to content

Commit

Permalink
Skip worker test when running via file URI scheme (Fix #272)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-risney committed Jul 15, 2014
1 parent 6439a31 commit fe0957a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion test/worker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,20 @@ describe('Worker', function() {
errorText += ": " + errorEvent.message;
}
return new Error(errorText);
},
canRunWorkerTestInCurrentContext = function () {
var workerConstructorExists = typeof Worker !== 'undefined',
locationPropertyExists = typeof location !== 'undefined',
runningOnFileUriScheme = locationPropertyExists && location.protocol === 'file:';

// The Worker constructor doesn't exist in some older browsers nor does it exist in non-browser contexts like Node.
// Additionally some browsers (at least Chrome) don't allow Workers over file URIs.
// To prevent false negative test failures in the cases where Workers are unavailable for either of those reasons
// we skip this test.
return workerConstructorExists && !runningOnFileUriScheme;
};

if (typeof Worker !== 'undefined') {
if (canRunWorkerTestInCurrentContext()) {
it('can import es6-shim', function (done) {
var worker = new Worker('worker-runner.workerjs');
worker.addEventListener('error', function (errorEvent) { throw workerErrorEventToError(errorEvent); });
Expand Down

0 comments on commit fe0957a

Please sign in to comment.