Skip to content

Commit

Permalink
Fixed tests to account for difference in tty vs non-tty
Browse files Browse the repository at this point in the history
  • Loading branch information
sourishkrout committed Feb 12, 2025
1 parent 8948600 commit e829d49
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions tests/extension/runner/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { GrpcRunnerClient } from '../../../src/extension/runner/client'
import GrpcRunner, {
GrpcRunnerProgramSession,
IRunner,
NON_TTY_BUFFER_SPAN_MS,
RunProgramOptions,
} from '../../../src/extension/runner'
import { GrpcRunnerEnvironment } from '../../../src/extension/runner/environment'
Expand Down Expand Up @@ -539,6 +540,7 @@ suite('grpc runner', () => {

test('onDidWrite replaces returns in non-interactive', async () => {
const { duplex, writeListener } = await createNewSession({
tty: false,
convertEol: true,
})

Expand All @@ -548,27 +550,33 @@ suite('grpc runner', () => {
mimeType: 'text/plain',
})

await waitForBufferTimespan()
expect(writeListener).toBeCalledTimes(1)
expect(writeListener).toBeCalledWith('test\r\n')
expect(writeListener).toBeCalledWith('\rtest\r\r\n')
})

test('onDidWrite replaces returns in complex string in non-interactive', async () => {
const { duplex, writeListener } = await createNewSession({
tty: false,
convertEol: true,
})

duplex._onMessage.fire({
stdoutData: Buffer.from('SERVICE_FOO_TOKEN: foobar\nSERVICE_BAR_TOKEN: barfoo'),
stdoutData: Buffer.from('SERVICE_FOO_TOKEN: foobar\r\nSERVICE_BAR_TOKEN: barfoo'),
stderrData: Buffer.from(''),
mimeType: 'text/plain',
})

await waitForBufferTimespan()
expect(writeListener).toBeCalledTimes(1)
expect(writeListener).toBeCalledWith('SERVICE_FOO_TOKEN: foobar\r\nSERVICE_BAR_TOKEN: barfoo')
expect(writeListener).toBeCalledWith(
'\rSERVICE_FOO_TOKEN: foobar\r\r\r\nSERVICE_BAR_TOKEN: barfoo',
)
})

test('onDidWrite replaces returns in non-interactive in stderr', async () => {
const { duplex, errListener } = await createNewSession({
tty: false,
convertEol: true,
})

Expand Down Expand Up @@ -784,6 +792,10 @@ suite('RunmeCodeLensProvider', () => {
})
})

function waitForBufferTimespan() {
return new Promise((resolve) => setTimeout(resolve, 2 * NON_TTY_BUFFER_SPAN_MS))
}

function getMockedDuplex(session: GrpcRunnerProgramSession): MockedDuplexClientStream {
return session['session'] as unknown as MockedDuplexClientStream
}
Expand Down Expand Up @@ -820,6 +832,7 @@ async function createNewSession(
runner ??= generatedRunner
const session = (await runner.createProgramSession({
programName: 'sh',
tty: true,
...options,
})) as GrpcRunnerProgramSession

Expand Down

0 comments on commit e829d49

Please sign in to comment.