mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-24 08:37:42 +00:00
Hacky way to test LMLayerWorker as if it's inside a Worker.
This commit is contained in:
parent
538393930d
commit
5200b665a1
1 changed files with 25 additions and 4 deletions
|
|
@ -18,10 +18,31 @@ describe('LMLayerWorker', function() {
|
|||
});
|
||||
|
||||
describe('#constructor()', function() {
|
||||
it.skip('should construct with zero arguments', function() {
|
||||
// TODO: This is broken, because the LMLayerWorker needs
|
||||
// to believe it's in a DedicatedWorkerGlobalScope.
|
||||
assert.isOk(new LMLayerWorker);
|
||||
it('should construct with zero arguments', function() {
|
||||
// Create a new "sandboxed" LMLayer. It's only "sandboxed", in that it believes it's in a WebWorker.
|
||||
var fs = require('fs');
|
||||
var sourceCode = fs.readFileSync(require.resolve('../../worker'));
|
||||
var sandbox = `(function (self) {
|
||||
var exports = {}; // TypeScript CommonJS code generation will attempt to write to this.
|
||||
var postMessage = self.postMessage;
|
||||
${sourceCode}
|
||||
return LMLayerWorker;
|
||||
})`;
|
||||
var createSandbox = eval(sandbox);
|
||||
var fakeSelf = {
|
||||
postMessage: sinon.fake()
|
||||
};
|
||||
var WorkerInSandbox = createSandbox(fakeSelf);
|
||||
let worker = new WorkerInSandbox();
|
||||
assert.isOk(worker);
|
||||
console.log(sandbox);
|
||||
|
||||
// Now try it out.
|
||||
worker.onMessage({
|
||||
message: 'initialize',
|
||||
model: 'en-x-dummy'
|
||||
});
|
||||
assert(fakeSelf.postMessage.calledOnce);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue