diff --git a/__tests__/inject.spec.ts b/__tests__/inject.spec.ts index 07f685b..59db734 100644 --- a/__tests__/inject.spec.ts +++ b/__tests__/inject.spec.ts @@ -2,11 +2,12 @@ import test from 'ava' import { len } from '../dist/shared' import { createInjectScript } from '../dist/inject' import { jsdelivr } from '../dist/url' -import type { TrackModule } from '../dist/interface' +import type { TrackModule } from '../dist' interface MockIIFEMdoule extends TrackModule{ relativeModule: string version: string + bindings: Set } test('inject', (t) => { @@ -15,7 +16,8 @@ test('inject', (t) => { relativeModule: 'fake.js', version: '0.0.0.', name: 'fake', - spare: ['fake.css', 'fake2.css', 'fake2.js'] + spare: ['fake.css', 'fake2.css', 'fake2.js'], + bindings: new Set() }) const injectScript = createInjectScript(modules, jsdelivr) t.is(len(injectScript.toTags()), 4) diff --git a/__tests__/vm.spec.ts b/__tests__/vm.spec.ts index a28b4c7..35e619a 100644 --- a/__tests__/vm.spec.ts +++ b/__tests__/vm.spec.ts @@ -1,27 +1,28 @@ import test from 'ava' import { MAX_CONCURRENT, createConcurrentQueue, createVM } from '../dist/vm' +import type{ ModuleInfo } from '../dist/interface' test('native vm', async (t) => { const vm = createVM() - await vm.run('var nonzzz = \'test plugin\'', { name: 'nonzzz' }) + await vm.run('var nonzzz = \'test plugin\'', { name: 'nonzzz' } as ModuleInfo, (err) => err) t.is(vm.bindings.has('nonzzz'), true) }) test('shadow vm', async (t) => { const vm = createVM() - await vm.run('window.nonzzz = 123', { name: 'nonzzz' }) + await vm.run('window.nonzzz = 123', { name: 'nonzzz' } as ModuleInfo) t.is(vm.bindings.has('nonzzz'), true) }) test('throw error in vm', async (t) => { const vm = createVM() - await vm.run('throw new Error(\'error\')', { name: 'nonzzz' }, (err) => { + await vm.run('throw new Error(\'error\')', { name: 'nonzzz' } as ModuleInfo, (err) => { t.is(err?.message, 'nonzzz') }) }) test('task queue', async (t) => { - const tasks = [() => Promise.resolve(1), () => Promise.resolve(2), () => Promise.reject(new Error('3'))] + const tasks = [() => Promise.resolve(), () => Promise.resolve(), () => Promise.reject(new Error('3'))] const queue = createConcurrentQueue(MAX_CONCURRENT) for (const task of tasks) {