-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from canjs/fix-worker-error
Allow can-zone to run in Worker contexts
- Loading branch information
Showing
10 changed files
with
156 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,7 @@ | |
end_of_line = LF | ||
indent_style = tab | ||
indent_size = 4 | ||
|
||
[{*.json,*.yml,*.md}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<!doctype html> | ||
<title>can-zone tests</title> | ||
<meta charset="UTF-8"> | ||
<script src="../node_modules/steal/steal.js" main="test/test_worker" | ||
data-mocha="bdd" data-transpiler="babel"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
var steal = require("@steal"); | ||
var mocha = require("steal-mocha"); | ||
var assert = require("assert"); | ||
|
||
|
||
var workerUrl = steal.loader.stealURL + "?main=~/test/worker_main"; | ||
var worker = new Worker(workerUrl); | ||
|
||
worker.addEventListener("message", function onMsg(ev){ | ||
var msg = ev.data; | ||
|
||
switch(msg.type) { | ||
case "suites": | ||
defineSuites(ev.data.suites); | ||
break; | ||
case "test": | ||
setTestResults(ev.data); | ||
break; | ||
} | ||
}); | ||
|
||
var testMap = new Map(); | ||
|
||
function clearUI() { | ||
var stats = document.getElementById("mocha-stats"); | ||
var report = document.getElementById("mocha-report"); | ||
stats.parentNode.removeChild(stats); | ||
report.parentNode.removeChild(report); | ||
} | ||
|
||
function defineSuites(suites) { | ||
clearUI(); | ||
|
||
suites.forEach(function(suite){ | ||
suite.tests.forEach(function(test){ | ||
var dfd = {}; | ||
dfd.promise = new Promise(function(resolve){ | ||
dfd.resolve = resolve; | ||
}); | ||
var key = suite.title + " - " + test.title; | ||
testMap.set(key, dfd); | ||
}); | ||
|
||
describe(suite.title, function(){ | ||
suite.tests.forEach(function(test){ | ||
it(test.title, function(done) { | ||
var key = suite.title + " - " + test.title; | ||
testMap.get(key).resolve(done); | ||
}); | ||
}) | ||
}) | ||
}); | ||
|
||
mocha.run(); | ||
} | ||
|
||
function setTestResults(msg) { | ||
var key = msg.suite + " - " + msg.title; | ||
var dfd = testMap.get(key); | ||
|
||
if(dfd) { | ||
dfd.promise.then(function(done){ | ||
assert.equal(msg.state, "passed"); | ||
|
||
if(typeof done === "undefined") { | ||
debugger; | ||
} | ||
|
||
done(); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var steal = require("@steal"); | ||
|
||
steal.config({ | ||
map: { | ||
"steal-mocha": "node_modules/mocha/mocha" | ||
}, | ||
meta: { | ||
"node_modules/mocha/mocha": { | ||
"format": "global", | ||
"exports": "mocha" | ||
} | ||
} | ||
}); | ||
|
||
steal.import("~/test/worker_test"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var mocha = require("steal-mocha"); | ||
|
||
mocha.setup({ | ||
ui: 'bdd', | ||
reporter: null, | ||
}); | ||
|
||
require("./test"); | ||
|
||
var runResults = mocha.run(); | ||
|
||
var suiteInfo = runResults.suite.suites.map(function(suite){ | ||
return { | ||
title: suite.title, | ||
tests: suite.tests.map(function(test){ | ||
return { | ||
title: test.title | ||
} | ||
}) | ||
}; | ||
}); | ||
|
||
postMessage({ | ||
type: "suites", | ||
suites: suiteInfo | ||
}); | ||
|
||
runResults.on("test end", function(test) { | ||
postMessage({ | ||
type: "test", | ||
title: test.title, | ||
state: test.state, | ||
suite: test.parent.title | ||
}); | ||
}); | ||
|
||
runResults.on("end", function() { | ||
postMessage({ | ||
type: "run end" | ||
}); | ||
//console.log(`${runResults.failures} out of ${runResults.total} failures.`); | ||
}); |