mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Merge pull request #33868 from overleaf/dk-package-loading-tests
[web] Add tests for pyodide worker streams and output pane rendering GitOrigin-RevId: 41ffc25230be23d68d50c61980cfaf1260a0247d
This commit is contained in:
+97
@@ -587,6 +587,103 @@ describe('PyodideWorkerClient', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('output-line forwarding', function () {
|
||||
function setupClientWithOutputTracking() {
|
||||
const outputCalls: Parameters<OutputCallback>[] = []
|
||||
const client = new PyodideWorkerClient({
|
||||
baseAssetPath: BASE_ASSET_PATH,
|
||||
createWorker,
|
||||
onOutput: (...args) => {
|
||||
outputCalls.push(args)
|
||||
},
|
||||
fileUploader: fileUploaderStub,
|
||||
})
|
||||
const worker = WorkerMock.instances[0]
|
||||
worker.emitMessage({ type: 'listening' })
|
||||
return { client, worker, outputCalls }
|
||||
}
|
||||
|
||||
it('forwards stdout output-line events to the output callback', function () {
|
||||
const { worker, outputCalls } = setupClientWithOutputTracking()
|
||||
|
||||
worker.emitMessage({
|
||||
type: 'output-line',
|
||||
stream: 'stdout',
|
||||
line: 'hello!',
|
||||
fileId: 'main.py',
|
||||
executionId: 'exec-stdout',
|
||||
})
|
||||
|
||||
expect(outputCalls).to.deep.equal([
|
||||
['stdout', 'hello!', 'main.py', 'exec-stdout'],
|
||||
])
|
||||
})
|
||||
|
||||
it('forwards stderr output-line events to the output callback', function () {
|
||||
const { worker, outputCalls } = setupClientWithOutputTracking()
|
||||
|
||||
worker.emitMessage({
|
||||
type: 'output-line',
|
||||
stream: 'stderr',
|
||||
line: 'boom',
|
||||
fileId: 'main.py',
|
||||
executionId: 'exec-stderr',
|
||||
})
|
||||
|
||||
expect(outputCalls).to.deep.equal([
|
||||
['stderr', 'boom', 'main.py', 'exec-stderr'],
|
||||
])
|
||||
})
|
||||
|
||||
it('forwards info output-line events to the output callback', function () {
|
||||
const { worker, outputCalls } = setupClientWithOutputTracking()
|
||||
|
||||
worker.emitMessage({
|
||||
type: 'output-line',
|
||||
stream: 'info',
|
||||
line: 'Loading numpy from package index',
|
||||
fileId: 'main.py',
|
||||
executionId: 'exec-info',
|
||||
})
|
||||
|
||||
expect(outputCalls).to.deep.equal([
|
||||
['info', 'Loading numpy from package index', 'main.py', 'exec-info'],
|
||||
])
|
||||
})
|
||||
|
||||
it('preserves stream type when forwarding stdout, stderr, and info in sequence', function () {
|
||||
const { worker, outputCalls } = setupClientWithOutputTracking()
|
||||
|
||||
worker.emitMessage({
|
||||
type: 'output-line',
|
||||
stream: 'info',
|
||||
line: 'Loading package',
|
||||
fileId: 'main.py',
|
||||
executionId: 'exec-mixed',
|
||||
})
|
||||
worker.emitMessage({
|
||||
type: 'output-line',
|
||||
stream: 'stdout',
|
||||
line: 'result',
|
||||
fileId: 'main.py',
|
||||
executionId: 'exec-mixed',
|
||||
})
|
||||
worker.emitMessage({
|
||||
type: 'output-line',
|
||||
stream: 'stderr',
|
||||
line: 'warning',
|
||||
fileId: 'main.py',
|
||||
executionId: 'exec-mixed',
|
||||
})
|
||||
|
||||
expect(outputCalls.map(call => call[0])).to.deep.equal([
|
||||
'info',
|
||||
'stdout',
|
||||
'stderr',
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('reset', function () {
|
||||
it('terminates the current worker and creates a new one', function () {
|
||||
const client = new PyodideWorkerClient({
|
||||
|
||||
Reference in New Issue
Block a user