Tests Blobs in the browser only.

This commit is contained in:
Eddie Antonio Santos 2018-11-27 13:53:29 -07:00
parent 02521b1254
commit 6e540f6b6b
No known key found for this signature in database
GPG key ID: DD411EA4D9509D87
4 changed files with 20 additions and 12 deletions

View file

@ -32,15 +32,20 @@
*/
type USVString = string;
// TODO: document
type WorkerFactory = (uri: string) => Worker;
// TODO: document
class LMLayer {
// TODO: document
private _worker: Worker;
// TODO: document
constructor(workerFactory: WorkerFactory = (uri) => new Worker(uri)) {
this._worker = workerFactory("about:blank");
let blob = new Blob([], { type: 'text/javascript' });
let uri = URL.createObjectURL(blob);
this._worker = workerFactory(uri);
}
}
// Let LMLayerWorker be available both in browser and in Node.

View file

@ -5,16 +5,8 @@ let LMLayer = require('../../');
describe('LMLayer', function() {
describe('[[constructor]]', function () {
it('should be given a WorkerFactory to instantiate', function () {
let createWorker = sinon.fake();
new LMLayer(createWorker);
assert.strictEqual(createWorker.callCount, 1);
});
it('should give the worker factory a blob URI', function () {
let createWorker = sinon.fake();
new LMLayer(createWorker);
assert.match(createWorker.lastArg, /^blob:/);
it.skip('should be take a URI to instantiate', function () {
new LMLayer(uri);
});
});
});

View file

@ -35,6 +35,7 @@ module.exports = {
// Include the generated worker code.
'../../embedded_worker.js',
'../../build/index.js',
// We don't have anything in these locations... yet. But they'll be useful for test resources.
'json/**/*.json', // Where pre-loaded JSON resides.

View file

@ -0,0 +1,10 @@
var assert = chai.assert;
describe('LMLayer', function () {
describe('[[constructor]]', function () {
it('should construct with zero arguments', function () {
let lmlayer = new LMLayer();
assert.instanceOf(lmlayer, LMLayer);
});
});
});