From 693d515fb27e3a6721f21c662af64e669700c885 Mon Sep 17 00:00:00 2001 From: kanno <812137533@qq.com> Date: Mon, 24 Jul 2023 12:20:46 +0800 Subject: [PATCH] test: make test happy --- __tests__/inject.spec.ts | 6 ++++-- __tests__/vm.spec.ts | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) 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) {