Skip to content

Commit

Permalink
chore: test
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Aug 12, 2024
1 parent a48b1a1 commit 89db8fe
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions __tests__/stream.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Writable } from 'stream'
import { describe, expect, it } from 'vitest'
import { createPack } from '../src'

describe('Stream', () => {
describe('Uniform Standard Type Archive', () => {
describe('Pack', () => {
it('Normal', async () => {
const assets = {
'assets/a.mjs': 'const a = 1;',
'assets/b.mjs': 'import "./c.css"; import { a } from "./a.mjs"; console.log(a);',
'assets/c.css': 'body { background: red; }'
}
const pack = createPack()

let expectByteLen = 0
let actualByteLen = 0

for (const [path, content] of Object.entries(assets)) {
pack.add(new TextEncoder().encode(content), {
filename: path
})
expectByteLen += content.length
expectByteLen += 512 - (content.length % 512)
expectByteLen += 512
}
expectByteLen += 1024
pack.done()
const writer = new Writable({
write(chunk, encoding, callback) {
actualByteLen += chunk.length
callback()
}
})
pack.receiver.pipe(writer)
await new Promise((resolve) => writer.on('finish', resolve))
expect(actualByteLen).toBe(expectByteLen)
})
})
})
})

0 comments on commit 89db8fe

Please sign in to comment.