Skip to content

Commit

Permalink
test: make test happy
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Jul 24, 2023
1 parent 76d24f4 commit 5e71f01
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion __tests__/inject.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { TrackModule } from '../dist'
interface MockIIFEMdoule extends TrackModule{
relativeModule: string
version: string
bindings: Set<string>
}

test('inject', (t) => {
Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions __tests__/vm.spec.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit 5e71f01

Please sign in to comment.