|
| 1 | +import * as vscode from 'vscode'; |
| 2 | +import * as path from 'path'; |
| 3 | +import * as fs from 'fs-extra'; |
| 4 | +import { assert } from 'chai'; |
| 5 | +import { EXTENSION_ROOT_DIR_FOR_TESTS, IS_SMOKE_TEST } from '../constants'; |
| 6 | +import { closeActiveWindows, initialize, initializeTest } from '../initialize'; |
| 7 | +import { openFile, waitForCondition } from '../common'; |
| 8 | + |
| 9 | +suite('Smoke Test: Run Smart Selection and Advance Cursor', () => { |
| 10 | + suiteSetup(async function () { |
| 11 | + if (!IS_SMOKE_TEST) { |
| 12 | + return this.skip(); |
| 13 | + } |
| 14 | + await initialize(); |
| 15 | + return undefined; |
| 16 | + }); |
| 17 | + |
| 18 | + setup(initializeTest); |
| 19 | + suiteTeardown(closeActiveWindows); |
| 20 | + teardown(closeActiveWindows); |
| 21 | + |
| 22 | + test('Smart Send', async () => { |
| 23 | + const file = path.join( |
| 24 | + EXTENSION_ROOT_DIR_FOR_TESTS, |
| 25 | + 'src', |
| 26 | + 'testMultiRootWkspc', |
| 27 | + 'smokeTests', |
| 28 | + 'create_delete_file.py', |
| 29 | + ); |
| 30 | + const outputFile = path.join( |
| 31 | + EXTENSION_ROOT_DIR_FOR_TESTS, |
| 32 | + 'src', |
| 33 | + 'testMultiRootWkspc', |
| 34 | + 'smokeTests', |
| 35 | + 'smart_send_smoke.txt', |
| 36 | + ); |
| 37 | + |
| 38 | + await fs.remove(outputFile); |
| 39 | + |
| 40 | + const textDocument = await openFile(file); |
| 41 | + |
| 42 | + if (vscode.window.activeTextEditor) { |
| 43 | + const myPos = new vscode.Position(0, 0); |
| 44 | + vscode.window.activeTextEditor!.selections = [new vscode.Selection(myPos, myPos)]; |
| 45 | + } |
| 46 | + await vscode.commands |
| 47 | + .executeCommand<void>('python.execSelectionInTerminal', textDocument.uri) |
| 48 | + .then(undefined, (err) => { |
| 49 | + assert.fail(`Something went wrong running the Python file in the terminal: ${err}`); |
| 50 | + }); |
| 51 | + |
| 52 | + const checkIfFileHasBeenCreated = () => fs.pathExists(outputFile); |
| 53 | + await waitForCondition(checkIfFileHasBeenCreated, 10_000, `"${outputFile}" file not created`); |
| 54 | + |
| 55 | + await vscode.commands |
| 56 | + .executeCommand<void>('python.execSelectionInTerminal', textDocument.uri) |
| 57 | + .then(undefined, (err) => { |
| 58 | + assert.fail(`Something went wrong running the Python file in the terminal: ${err}`); |
| 59 | + }); |
| 60 | + await vscode.commands |
| 61 | + .executeCommand<void>('python.execSelectionInTerminal', textDocument.uri) |
| 62 | + .then(undefined, (err) => { |
| 63 | + assert.fail(`Something went wrong running the Python file in the terminal: ${err}`); |
| 64 | + }); |
| 65 | + |
| 66 | + async function wait() { |
| 67 | + return new Promise<void>((resolve) => { |
| 68 | + setTimeout(() => { |
| 69 | + resolve(); |
| 70 | + }, 10000); |
| 71 | + }); |
| 72 | + } |
| 73 | + |
| 74 | + await wait(); |
| 75 | + |
| 76 | + const deletedFile = !(await fs.pathExists(outputFile)); |
| 77 | + if (deletedFile) { |
| 78 | + assert.ok(true, `"${outputFile}" file has been deleted`); |
| 79 | + } else { |
| 80 | + assert.fail(`"${outputFile}" file still exists`); |
| 81 | + } |
| 82 | + }); |
| 83 | +}); |
0 commit comments