Skip to content

Commit

Permalink
Add test for web worker
Browse files Browse the repository at this point in the history
  • Loading branch information
akfish committed Jul 28, 2014
1 parent dc5d373 commit f5fe8bf
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/specs/web-worker/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=0">
<title>test</title>
<script src="../../../dist/sea-debug.js"></script>
<script src="../../../dist/standalone.js"></script>
<script src="../../test-standalone.js"></script>

</head>
<body>
<div id="out"></div>
<script>
var test = require('test')
var worker = new Worker('worker.js');
worker.addEventListener('message', function (e){
var message = e.data.message;
var result = e.data.result;
test.assert(result, message);
});
worker.postMessage("start");
</script>
</body>
</html>
26 changes: 26 additions & 0 deletions tests/specs/web-worker/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
define(function(require) {
function assert(value, message) {
self.postMessage({message: message, result: value});
}
console.log("Start runner in worker")
self.addEventListener('message', function (e) {
console.log("On message: " + e.data);
if (e.data === 'start') {
console.log("Start running tests");
var a = require('a');
assert(a === 'a', 'a is a');

var b = require('b')
assert(JSON.stringify(b) == '{}', 'b is {}')

var c = require('c')
assert(JSON.stringify(c) == '{}', 'c is {}')

assert(b === c, 'b returns c')


var e = require('e')
assert(e === 'e', 'e is e')
}
})
})
13 changes: 13 additions & 0 deletions tests/specs/web-worker/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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 f5fe8bf

Please sign in to comment.