Skip to content

Commit

Permalink
Enable experiments for all tests (#22194)
Browse files Browse the repository at this point in the history
Closes: #22193

Enables to opt into experiments for tests such as single workspace,
multi workspace, debugger, venv, etc.
  • Loading branch information
anthonykim1 authored Oct 17, 2023
1 parent ed155af commit 1310bd6
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/test/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export async function initializePython() {

export async function initialize(): Promise<IExtensionTestApi> {
await initializePython();

const pythonConfig = vscode.workspace.getConfiguration('python');
await pythonConfig.update('experiments.optInto', ['All'], vscode.ConfigurationTarget.Global);
await pythonConfig.update('experiments.optOutFrom', [], vscode.ConfigurationTarget.Global);
const api = await activateExtension();
if (!IS_SMOKE_TEST) {
// When running smoke tests, we won't have access to these.
Expand Down
83 changes: 83 additions & 0 deletions src/test/smoke/smartSend.smoke.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs-extra';
import { assert } from 'chai';
import { EXTENSION_ROOT_DIR_FOR_TESTS, IS_SMOKE_TEST } from '../constants';
import { closeActiveWindows, initialize, initializeTest } from '../initialize';
import { openFile, waitForCondition } from '../common';

suite('Smoke Test: Run Smart Selection and Advance Cursor', () => {
suiteSetup(async function () {
if (!IS_SMOKE_TEST) {
return this.skip();
}
await initialize();
return undefined;
});

setup(initializeTest);
suiteTeardown(closeActiveWindows);
teardown(closeActiveWindows);

test('Smart Send', async () => {
const file = path.join(
EXTENSION_ROOT_DIR_FOR_TESTS,
'src',
'testMultiRootWkspc',
'smokeTests',
'create_delete_file.py',
);
const outputFile = path.join(
EXTENSION_ROOT_DIR_FOR_TESTS,
'src',
'testMultiRootWkspc',
'smokeTests',
'smart_send_smoke.txt',
);

await fs.remove(outputFile);

const textDocument = await openFile(file);

if (vscode.window.activeTextEditor) {
const myPos = new vscode.Position(0, 0);
vscode.window.activeTextEditor!.selections = [new vscode.Selection(myPos, myPos)];
}
await vscode.commands
.executeCommand<void>('python.execSelectionInTerminal', textDocument.uri)
.then(undefined, (err) => {
assert.fail(`Something went wrong running the Python file in the terminal: ${err}`);
});

const checkIfFileHasBeenCreated = () => fs.pathExists(outputFile);
await waitForCondition(checkIfFileHasBeenCreated, 10_000, `"${outputFile}" file not created`);

await vscode.commands
.executeCommand<void>('python.execSelectionInTerminal', textDocument.uri)
.then(undefined, (err) => {
assert.fail(`Something went wrong running the Python file in the terminal: ${err}`);
});
await vscode.commands
.executeCommand<void>('python.execSelectionInTerminal', textDocument.uri)
.then(undefined, (err) => {
assert.fail(`Something went wrong running the Python file in the terminal: ${err}`);
});

async function wait() {
return new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 10000);
});
}

await wait();

const deletedFile = !(await fs.pathExists(outputFile));
if (deletedFile) {
assert.ok(true, `"${outputFile}" file has been deleted`);
} else {
assert.fail(`"${outputFile}" file still exists`);
}
});
});

0 comments on commit 1310bd6

Please sign in to comment.