From f5fe8bfbb23e915f8b423bf01a1f50cc403c91e6 Mon Sep 17 00:00:00 2001 From: AKFish Date: Mon, 28 Jul 2014 19:43:51 +0800 Subject: [PATCH] Add test for web worker --- tests/specs/web-worker/test.html | 25 +++++++++++++++++++++++++ tests/specs/web-worker/tests.js | 26 ++++++++++++++++++++++++++ tests/specs/web-worker/worker.js | 13 +++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 tests/specs/web-worker/test.html create mode 100644 tests/specs/web-worker/tests.js create mode 100644 tests/specs/web-worker/worker.js diff --git a/tests/specs/web-worker/test.html b/tests/specs/web-worker/test.html new file mode 100644 index 00000000..79faa91b --- /dev/null +++ b/tests/specs/web-worker/test.html @@ -0,0 +1,25 @@ + + + + + + test + + + + + + +
+ + + diff --git a/tests/specs/web-worker/tests.js b/tests/specs/web-worker/tests.js new file mode 100644 index 00000000..2309438f --- /dev/null +++ b/tests/specs/web-worker/tests.js @@ -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') + } + }) +}) diff --git a/tests/specs/web-worker/worker.js b/tests/specs/web-worker/worker.js new file mode 100644 index 00000000..35b3d5f1 --- /dev/null +++ b/tests/specs/web-worker/worker.js @@ -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");