29 lines
1.3 KiB
TypeScript
29 lines
1.3 KiB
TypeScript
import { strict as assert } from 'node:assert'
|
|
import { test } from 'node:test'
|
|
import { createRequire } from 'node:module'
|
|
|
|
const { moduleProgress, createModuleProgressParser } = createRequire(import.meta.url)('./moduleProgress.ts') as typeof import('./moduleProgress')
|
|
|
|
test('progress parser handles split lines and ignores normal command output', () => {
|
|
const messages: string[] = []
|
|
const parse = moduleProgress.run((message) => messages.push(message), createModuleProgressParser)
|
|
parse('ordinary output\nLMS_MODULE_PRO')
|
|
parse('GRESS:download\nLMS_MODULE_PROGRESS:load\n')
|
|
assert.deepEqual(messages, ['download', 'load'])
|
|
})
|
|
|
|
test('concurrent operations retain their own progress callbacks', () => {
|
|
const first: string[] = []
|
|
const second: string[] = []
|
|
const a = moduleProgress.run((message) => first.push(message), createModuleProgressParser)
|
|
const b = moduleProgress.run((message) => second.push(message), createModuleProgressParser)
|
|
b('LMS_MODULE_PROGRESS:build\n')
|
|
a('LMS_MODULE_PROGRESS:download\n')
|
|
assert.deepEqual(first, ['download'])
|
|
assert.deepEqual(second, ['build'])
|
|
})
|
|
|
|
test('commands outside a module operation do not report progress', () => {
|
|
assert.doesNotThrow(() => createModuleProgressParser()('LMS_MODULE_PROGRESS:ignored\n'))
|
|
})
|