mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-11 21:43:58 -04:00
Add integration test for a non-worker extension
This commit is contained in:
parent
06252e020b
commit
772da24d9e
2 changed files with 53 additions and 1 deletions
test/integration
51
test/integration/internal-extension.js
Normal file
51
test/integration/internal-extension.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
const test = require('tap').test;
|
||||
const Worker = require('tiny-worker');
|
||||
|
||||
const dispatch = require('../../src/dispatch/central-dispatch');
|
||||
const VirtualMachine = require('../../src/virtual-machine');
|
||||
|
||||
// By default Central Dispatch works with the Worker class built into the browser. Tell it to use TinyWorker instead.
|
||||
dispatch.workerClass = Worker;
|
||||
|
||||
class TestInternalExtension {
|
||||
constructor () {
|
||||
this.status = {};
|
||||
this.status.constructorCalled = true;
|
||||
}
|
||||
|
||||
getInfo () {
|
||||
this.status.getInfoCalled = true;
|
||||
return {
|
||||
id: 'test-internal-extension',
|
||||
name: 'Test Internal Extension',
|
||||
blocks: [
|
||||
{
|
||||
opcode: 'go'
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
go () {
|
||||
this.status.goCalled = true;
|
||||
}
|
||||
}
|
||||
|
||||
test('internal extension', t => {
|
||||
const vm = new VirtualMachine();
|
||||
|
||||
const extension = new TestInternalExtension();
|
||||
t.ok(extension.status.constructorCalled);
|
||||
|
||||
t.notOk(extension.status.getInfoCalled);
|
||||
return vm.extensionManager._registerInternalExtension(extension).then(() => {
|
||||
t.ok(extension.status.getInfoCalled);
|
||||
|
||||
const func = vm.runtime.getOpcodeFunction('test-internal-extension.go');
|
||||
t.type(func, 'function');
|
||||
|
||||
t.notOk(extension.status.goCalled);
|
||||
func();
|
||||
t.ok(extension.status.goCalled);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue