From 0075e2252b7ef33ad0f4b8aed7ef5b1695fab3c8 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 14 Feb 2020 07:24:09 -0800 Subject: [PATCH] Create an echo shell integration test Part of #90539 --- .../src/singlefolder-tests/terminal.test.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts index ce5b0f44aa7..9ac88a57e65 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts @@ -33,6 +33,36 @@ suite('window namespace tests', () => { doesNotThrow(terminal.sendText.bind(terminal, 'echo "foo"')); }); + test('echo works in the default shell', (done) => { + disposables.push(window.onDidOpenTerminal(term => { + try { + equal(terminal, term); + } catch (e) { + done(e); + } + let data = ''; + disposables.push(window.onDidWriteTerminalData(e => { + try { + equal(terminal, e.terminal); + } catch (e) { + done(e); + } + data += e.data; + // Pass the test if there is a line that contains only the echo'd output. Note + // that echoing can print "echo ..." twice if the shell has not yet been fully + // initialized. + const lines = data.split('\r').map(d => d.trim()); + if (lines.some(l => l === expected)) { + terminal.dispose(); + disposables.push(window.onDidCloseTerminal(() => done())); + } + })); + })); + const terminal = window.createTerminal(); + const expected = new Date().getTime().toString(); + doesNotThrow(terminal.sendText.bind(terminal, `echo "${expected}"`)); + }); + test('onDidCloseTerminal event fires when terminal is disposed', (done) => { disposables.push(window.onDidOpenTerminal(term => { try {