Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use async/await for terminal integration tests #115944

Merged
merged 1 commit into from Feb 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
259 changes: 138 additions & 121 deletions extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts
Expand Up @@ -3,8 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { window, Pseudoterminal, EventEmitter, TerminalDimensions, workspace, ConfigurationTarget, Disposable, UIKind, env, EnvironmentVariableMutatorType, EnvironmentVariableMutator, extensions, ExtensionContext, TerminalOptions, ExtensionTerminalOptions } from 'vscode';
import { doesNotThrow, equal, ok, deepEqual, throws } from 'assert';
import { window, Pseudoterminal, EventEmitter, TerminalDimensions, workspace, ConfigurationTarget, Disposable, UIKind, env, EnvironmentVariableMutatorType, EnvironmentVariableMutator, extensions, ExtensionContext, TerminalOptions, ExtensionTerminalOptions, Terminal } from 'vscode';
import { doesNotThrow, equal, deepEqual, throws } from 'assert';
import { assertNoRpc } from '../utils';

// Disable terminal tests:
Expand Down Expand Up @@ -36,19 +36,25 @@ import { assertNoRpc } from '../utils';
disposables.length = 0;
});

test('sendText immediately after createTerminal should not throw', (done) => {
disposables.push(window.onDidOpenTerminal(term => {
try {
equal(terminal, term);
} catch (e) {
done(e);
return;
}
terminal.dispose();
disposables.push(window.onDidCloseTerminal(() => done()));
}));
test('sendText immediately after createTerminal should not throw', async () => {
const terminal = window.createTerminal();
const result = await new Promise<Terminal>(r => {
disposables.push(window.onDidOpenTerminal(t => {
if (t === terminal) {
r(t);
}
}));
});
equal(result, terminal);
doesNotThrow(terminal.sendText.bind(terminal, 'echo "foo"'));
await new Promise<void>(r => {
disposables.push(window.onDidCloseTerminal(t => {
if (t === terminal) {
r();
}
}));
terminal.dispose();
});
});

(process.platform === 'linux' ? test.skip : test)('echo works in the default shell', (done) => {
Expand Down Expand Up @@ -96,124 +102,133 @@ import { assertNoRpc } from '../utils';
});
});

test('onDidCloseTerminal event fires when terminal is disposed', (done) => {
disposables.push(window.onDidOpenTerminal(term => {
try {
equal(terminal, term);
} catch (e) {
done(e);
return;
}
terminal.dispose();
disposables.push(window.onDidCloseTerminal(() => done()));
}));
test('onDidCloseTerminal event fires when terminal is disposed', async () => {
const terminal = window.createTerminal();
const result = await new Promise<Terminal>(r => {
disposables.push(window.onDidOpenTerminal(t => {
if (t === terminal) {
r(t);
}
}));
});
equal(result, terminal);
await new Promise<void>(r => {
disposables.push(window.onDidCloseTerminal(t => {
if (t === terminal) {
r();
}
}));
terminal.dispose();
});
});

test('processId immediately after createTerminal should fetch the pid', (done) => {
disposables.push(window.onDidOpenTerminal(term => {
try {
equal(terminal, term);
} catch (e) {
done(e);
return;
}
terminal.processId.then(id => {
try {
ok(id && id > 0);
} catch (e) {
done(e);
return;
}
terminal.dispose();
disposables.push(window.onDidCloseTerminal(() => done()));
});
}));
test('processId immediately after createTerminal should fetch the pid', async () => {
const terminal = window.createTerminal();
const result = await new Promise<Terminal>(r => {
disposables.push(window.onDidOpenTerminal(t => {
if (t === terminal) {
r(t);
}
}));
});
equal(result, terminal);
let pid = await result.processId;
equal(true, pid && pid > 0);
await new Promise<void>(r => {
disposables.push(window.onDidCloseTerminal(t => {
if (t === terminal) {
r();
}
}));
terminal.dispose();
});
});

test('name in constructor should set terminal.name', (done) => {
disposables.push(window.onDidOpenTerminal(term => {
try {
equal(terminal, term);
} catch (e) {
done(e);
return;
}
terminal.dispose();
disposables.push(window.onDidCloseTerminal(() => done()));
}));
test('name in constructor should set terminal.name', async () => {
const terminal = window.createTerminal('a');
try {
equal(terminal.name, 'a');
} catch (e) {
done(e);
return;
}
const result = await new Promise<Terminal>(r => {
disposables.push(window.onDidOpenTerminal(t => {
if (t === terminal) {
r(t);
}
}));
});
equal(result, terminal);
await new Promise<void>(r => {
disposables.push(window.onDidCloseTerminal(t => {
if (t === terminal) {
r();
}
}));
terminal.dispose();
});
});

test('creationOptions should be set and readonly for TerminalOptions terminals', (done) => {
disposables.push(window.onDidOpenTerminal(term => {
try {
equal(terminal, term);
} catch (e) {
done(e);
return;
}
terminal.dispose();
disposables.push(window.onDidCloseTerminal(() => done()));
}));
test('creationOptions should be set and readonly for TerminalOptions terminals', async () => {
const options = {
name: 'foo',
hideFromUser: true
};
const terminal = window.createTerminal(options);
try {
equal(terminal.name, 'foo');
const terminalOptions = terminal.creationOptions as TerminalOptions;
equal(terminalOptions.name, 'foo');
equal(terminalOptions.hideFromUser, true);
throws(() => terminalOptions.name = 'bad', 'creationOptions should be readonly at runtime');
} catch (e) {
done(e);
return;
}
const terminalOptions = terminal.creationOptions as TerminalOptions;
const result = await new Promise<Terminal>(r => {
disposables.push(window.onDidOpenTerminal(t => {
if (t === terminal) {
r(t);
}
}));
});
equal(result, terminal);
await new Promise<void>(r => {
disposables.push(window.onDidCloseTerminal(t => {
if (t === terminal) {
r();
}
}));
terminal.dispose();
});
throws(() => terminalOptions.name = 'bad', 'creationOptions should be readonly at runtime');
});

test('onDidOpenTerminal should fire when a terminal is created', (done) => {
disposables.push(window.onDidOpenTerminal(term => {
try {
equal(term.name, 'b');
} catch (e) {
done(e);
return;
}
disposables.push(window.onDidCloseTerminal(() => done()));
terminal.dispose();
}));
test('onDidOpenTerminal should fire when a terminal is created', async () => {
const terminal = window.createTerminal('b');
const result = await new Promise<Terminal>(r => {
disposables.push(window.onDidOpenTerminal(t => {
if (t === terminal) {
r(t);
}
}));
});
equal(result, terminal);
await new Promise<void>(r => {
disposables.push(window.onDidCloseTerminal(t => {
if (t === terminal) {
r();
}
}));
terminal.dispose();
});
});

test('exitStatus.code should be set to undefined after a terminal is disposed', (done) => {
disposables.push(window.onDidOpenTerminal(term => {
try {
equal(term, terminal);
} catch (e) {
done(e);
return;
}
test('exitStatus.code should be set to undefined after a terminal is disposed', async () => {
const terminal = window.createTerminal();
const result = await new Promise<Terminal>(r => {
disposables.push(window.onDidOpenTerminal(t => {
if (t === terminal) {
r(t);
}
}));
});
equal(result, terminal);
await new Promise<void>(r => {
disposables.push(window.onDidCloseTerminal(t => {
try {
if (t === terminal) {
deepEqual(t.exitStatus, { code: undefined });
} catch (e) {
done(e);
return;
r();
}
done();
}));
terminal.dispose();
}));
const terminal = window.createTerminal();
});
});

// test('onDidChangeActiveTerminal should fire when new terminals are created', (done) => {
Expand Down Expand Up @@ -287,23 +302,25 @@ import { assertNoRpc } from '../utils';
// });

suite('hideFromUser', () => {
test('should be available to terminals API', done => {
test('should be available to terminals API', async () => {
const terminal = window.createTerminal({ name: 'bg', hideFromUser: true });
disposables.push(window.onDidOpenTerminal(t => {
try {
equal(t, terminal);
equal(t.name, 'bg');
ok(window.terminals.indexOf(terminal) !== -1);
} catch (e) {
done(e);
return;
}
disposables.push(window.onDidCloseTerminal(() => {
// reg3.dispose();
done();
const result = await new Promise<Terminal>(r => {
disposables.push(window.onDidOpenTerminal(t => {
if (t === terminal) {
r(t);
}
}));
});
equal(result, terminal);
equal(true, window.terminals.indexOf(terminal) !== -1);
await new Promise<void>(r => {
disposables.push(window.onDidCloseTerminal(t => {
if (t === terminal) {
r();
}
}));
terminal.dispose();
}));
});
});
});

Expand Down