diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-05-23 23:45:12 -0400 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-05-23 23:45:12 -0400 |
commit | f53768612b1e2268697b5444e502032ef9f3fb3c (patch) | |
tree | 4ed49b73e6bd3c2f8fceffa9643973033f87af95 /extension/src/test | |
download | sncontinue-f53768612b1e2268697b5444e502032ef9f3fb3c.tar.gz sncontinue-f53768612b1e2268697b5444e502032ef9f3fb3c.tar.bz2 sncontinue-f53768612b1e2268697b5444e502032ef9f3fb3c.zip |
copying from old repo
Diffstat (limited to 'extension/src/test')
-rw-r--r-- | extension/src/test/runTest.ts | 23 | ||||
-rw-r--r-- | extension/src/test/suite/extension.test.ts | 16 | ||||
-rw-r--r-- | extension/src/test/suite/index.ts | 38 | ||||
-rw-r--r-- | extension/src/test/suite/terminalEmulator.test.ts | 28 | ||||
-rw-r--r-- | extension/src/test/suite/util.test.ts | 18 |
5 files changed, 123 insertions, 0 deletions
diff --git a/extension/src/test/runTest.ts b/extension/src/test/runTest.ts new file mode 100644 index 00000000..27b3ceb2 --- /dev/null +++ b/extension/src/test/runTest.ts @@ -0,0 +1,23 @@ +import * as path from 'path'; + +import { runTests } from '@vscode/test-electron'; + +async function main() { + try { + // The folder containing the Extension Manifest package.json + // Passed to `--extensionDevelopmentPath` + const extensionDevelopmentPath = path.resolve(__dirname, '../../'); + + // The path to test runner + // Passed to --extensionTestsPath + const extensionTestsPath = path.resolve(__dirname, './suite/index'); + + // Download VS Code, unzip it and run the integration test + await runTests({ extensionDevelopmentPath, extensionTestsPath }); + } catch (err) { + console.error('Failed to run tests'); + process.exit(1); + } +} + +main(); diff --git a/extension/src/test/suite/extension.test.ts b/extension/src/test/suite/extension.test.ts new file mode 100644 index 00000000..890820b2 --- /dev/null +++ b/extension/src/test/suite/extension.test.ts @@ -0,0 +1,16 @@ +import { test, describe } from "mocha"; +import * as assert from "assert"; + +// You can import and use all API from the 'vscode' module +// as well as import your extension to test it +import * as vscode from "vscode"; +// import * as myExtension from '../../extension'; + +describe("Extension Test Suite", () => { + vscode.window.showInformationMessage("Start all tests."); + + test("Sample test", () => { + assert.strictEqual(-1, [1, 2, 3].indexOf(5)); + assert.strictEqual(-1, [1, 2, 3].indexOf(0)); + }); +}); diff --git a/extension/src/test/suite/index.ts b/extension/src/test/suite/index.ts new file mode 100644 index 00000000..772a0152 --- /dev/null +++ b/extension/src/test/suite/index.ts @@ -0,0 +1,38 @@ +import * as path from "path"; +import * as Mocha from "mocha"; +import * as glob from "glob"; + +export function run(): Promise<void> { + // Create the mocha test + const mocha = new Mocha({ + ui: "tdd", + color: true, + }); + + const testsRoot = path.resolve(__dirname, ".."); + + return new Promise((c, e) => { + glob("**/**.test.js", { cwd: testsRoot }, (err, files) => { + if (err) { + return e(err); + } + + // Add files to the test suite + files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f))); + + try { + // Run the mocha test + mocha.run((failures: any) => { + if (failures > 0) { + e(new Error(`${failures} tests failed.`)); + } else { + c(); + } + }); + } catch (err) { + console.error(err); + e(err); + } + }); + }); +} diff --git a/extension/src/test/suite/terminalEmulator.test.ts b/extension/src/test/suite/terminalEmulator.test.ts new file mode 100644 index 00000000..c4c159a4 --- /dev/null +++ b/extension/src/test/suite/terminalEmulator.test.ts @@ -0,0 +1,28 @@ +import { test, describe } from "mocha"; +import * as assert from "assert"; +import { PythonTracebackSnooper } from "../../terminal/snoopers"; + +suite("Snoopers", () => { + suite("PythonTracebackSnooper", () => { + test("should detect traceback given all at once", async () => { + let traceback = `Traceback (most recent call last): + File "/Users/natesesti/Desktop/continue/extension/examples/python/main.py", line 10, in <module> + sum(first, second) + File "/Users/natesesti/Desktop/continue/extension/examples/python/sum.py", line 2, in sum + return a + b + TypeError: unsupported operand type(s) for +: 'int' and 'str'`; + let returnedTraceback = await new Promise((resolve) => { + let callback = (data: string) => { + resolve(data); + }; + let snooper = new PythonTracebackSnooper(callback); + snooper.onData(traceback); + }); + assert( + returnedTraceback === traceback, + "Detected \n" + returnedTraceback + ); + }); + test("should detect traceback given in chunks", () => {}); + }); +}); diff --git a/extension/src/test/suite/util.test.ts b/extension/src/test/suite/util.test.ts new file mode 100644 index 00000000..0ba1473b --- /dev/null +++ b/extension/src/test/suite/util.test.ts @@ -0,0 +1,18 @@ +import { test, describe } from "mocha"; +import * as assert from "assert"; +import { convertSingleToDoubleQuoteJSON } from "../../util/util"; + +describe("utils.ts", () => { + test("convertSingleToDoubleQuoteJson", () => { + let pairs = [ + [`{'a': 'b'}`, `{"a": "b"}`], + [`{'a': "b", "c": 'd'}`, `{"a": "b", "c": "d"}`], + [`{'a': '\\'"'}`, `{"a": "'\\""}`], + ]; + for (let pair of pairs) { + let result = convertSingleToDoubleQuoteJSON(pair[0]); + assert(result === pair[1]); + JSON.parse(result); + } + }); +}); |