Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81155 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @emails react-core
10
*/
11
12
/*jslint evil: true */
13
14
"use strict";
15
16
describe('ReactWebWorker', function() {
17
;(typeof Worker == 'undefined' ? xit : it)('can run React in a web worker', function() {
18
var done = false;
19
var error;
20
21
var worker = new Worker(window.ReactWebWorker_URL || '/src/test/worker.js?_=' + Date.now().toString(36));
22
worker.addEventListener('message', function(e) {
23
var data = JSON.parse(e.data);
24
if (data.type == 'error') {
25
error = data.message + "\n" + data.stack;
26
done = true;
27
} else if (data.type == 'log') {
28
console.log(data.message);
29
} else {
30
expect(data.type).toBe('done');
31
done = true;
32
}
33
});
34
35
waitsFor(function() {
36
return done;
37
}, "the final message to arrive from the worker", 2e4);
38
39
runs(function() {
40
if (error) {
41
console.error(error);
42
throw new Error(error);
43
}
44
});
45
});
46
});
47
48