Skip to content

Commit

Permalink
Add inline worker test
Browse files Browse the repository at this point in the history
  • Loading branch information
akfish committed Jul 30, 2014
1 parent 3c5b19f commit 2ef12c2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
23 changes: 21 additions & 2 deletions tests/specs/web-worker/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,33 @@
<body>
<div id="out"></div>
<script>
console.log(seajs.data.loader);
var test = require('test')
// Test worker from script file
var worker = new Worker('worker.js');
worker.addEventListener('message', function (e){
function assertWorkerMessage(e) {
var message = e.data.message;
var result = e.data.result;
test.assert(result, message);
});
}
worker.onmessage = assertWorkerMessage;
worker.postMessage("start");

// Test inline worker
// Note: this won't run on IE
// See: http://connect.microsoft.com/IE/feedback/details/801810/web-workers-from-blob-urls-in-ie-10-and-11
var src = "console.log('Inline worker Up!');\n" +
"importScripts('" + seajs.data.loader + "');\n" +
"console.log(JSON.stringify(seajs.data, null, 4));\n" +
// Inline worker's cwd is loaderDir, use path relative to loader
// Or absolute path
"seajs.use('../tests/specs/web-worker/tests');";
console.log(src);
var blob = new Blob([src]);
var blobUrl = window.URL.createObjectURL(blob);
var inlineWorker = new Worker(blobUrl);
inlineWorker.onmessage = assertWorkerMessage;
inlineWorker.postMessage("start");
</script>
</body>
</html>
8 changes: 8 additions & 0 deletions tests/specs/web-worker/tests.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
define('a', [], function() { return 'a' })
define('b', ['c'], function(require) { var c = require('c'); return c })
define('c', [], {})
define('e', [], function(require, exports, module) {
module.exports = 'e'
console.log('huh?')
})

define(function(require) {
function assert(value, message) {
self.postMessage({message: message, result: value});
Expand Down
8 changes: 0 additions & 8 deletions tests/specs/web-worker/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,4 @@ console.log("Worker Up!")
console.log(location)
importScripts("../../../dist/sea.js");

define('a', [], function() { return 'a' })
define('b', ['c'], function(require) { var c = require('c'); return c })
define('c', [], {})
define('e', [], function(require, exports, module) {
module.exports = 'e'
console.log('huh?')
})

seajs.use("./tests");

0 comments on commit 2ef12c2

Please sign in to comment.