enable coverage logging from the worker
Thomas Aylott committed
Nov 15, 2013 at 16:28 UTC
ef5a02c16485707acdfd38f612c16513beeb4a6a
2 files changed
+26
-6
src/environment/__tests__/ReactWebWorker-test.js
+3
-1
@@ -31,6 +31,8 @@ describe('ReactWebWorker', function() {
31
var data = JSON.parse(e.data);
32
if (data.type == 'error') {
33
error = data.message + "\n" + data.stack;
34
+ } else if (data.type == 'log') {
35
+ console.log(data.message);
36
} else {
37
expect(data.type).toBe('done');
38
done = true;
@@ -42,7 +44,7 @@ describe('ReactWebWorker', function() {
44
});
45
runs(function() {
46
if (error) {
45
- console.log(error);
47
+ console.error(error);
48
throw new Error(error);
49
}
50
});
src/test/worker.js
+23
-5
@@ -1,6 +1,26 @@
1
/* jshint worker: true */
2
"use strict";
3
4
+if (typeof console == 'undefined') {
5
+ this.console = {
6
+ error: function(e){
7
+ postMessage(JSON.stringify({
8
+ type: 'error',
9
+ message: e.message,
10
+ stack: e.stack
11
+ }));
12
+ },
13
+ log: function(message){
14
+ postMessage(JSON.stringify({
15
+ type: 'log',
16
+ message: message
17
+ }));
18
+ }
19
+ }
20
+}
21
+
22
+console.log('worker BEGIN');
23
+
24
// The UMD wrapper tries to store on `global` if `window` isn't available
25
var global = {};
26
importScripts("phantomjs-shims.js");
@@ -8,13 +28,11 @@ importScripts("phantomjs-shims.js");
28
try {
29
importScripts("../../build/react.js");
30
} catch (e) {
11
- postMessage(JSON.stringify({
12
- type: 'error',
13
- message: e.message,
14
- stack: e.stack
15
- }));
31
+ console.error(e);
32
}
33
34
postMessage(JSON.stringify({
35
type: 'done'
36
}));
37
+
38
+console.log('worker END');