From d99a75680fafddbf94a478212bc4fa4138235b0e Mon Sep 17 00:00:00 2001 From: Ilya Golovin Date: Tue, 27 Jan 2026 02:00:33 +0300 Subject: [PATCH] chore: delete integration tests from the codebase Integration tests are hard to fix and maintain in their current state Refs: * Discussion - https://github.com/zardoy/typescript-vscode-plugins/pull/227#discussion_r2394844458 --- .eslintignore | 1 - CONTRIBUTING.MD | 11 +- .../fixtures/test-project/jsconfig.json | 8 - .../fixtures/test-project/src/completions.ts | 7 - .../fixtures/test-project/src/index.tsx | 23 --- integration/index.ts | 43 ----- integration/prerun.mjs | 10 - integration/runTests.ts | 19 -- integration/suite/outline.test.ts | 176 ------------------ integration/suite/utils.ts | 51 ----- package.json | 6 +- patches/@vscode+test-electron+2.1.5.patch | 35 ---- tsconfig.test.json | 14 -- 13 files changed, 4 insertions(+), 400 deletions(-) delete mode 100644 integration/fixtures/test-project/jsconfig.json delete mode 100644 integration/fixtures/test-project/src/completions.ts delete mode 100644 integration/fixtures/test-project/src/index.tsx delete mode 100644 integration/index.ts delete mode 100644 integration/prerun.mjs delete mode 100644 integration/runTests.ts delete mode 100644 integration/suite/outline.test.ts delete mode 100644 integration/suite/utils.ts delete mode 100644 patches/@vscode+test-electron+2.1.5.patch delete mode 100644 tsconfig.test.json diff --git a/.eslintignore b/.eslintignore index 1361a3dc..346501df 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,4 +3,3 @@ src/configurationType.ts src/configurationTypeCache.jsonc playground.ts test.ts -integration/fixtures diff --git a/CONTRIBUTING.MD b/CONTRIBUTING.MD index 64a57efb..9b1f017c 100644 --- a/CONTRIBUTING.MD +++ b/CONTRIBUTING.MD @@ -31,13 +31,6 @@ To start the VS Code plugin extension locally for developing: #### Unit Tests -> Note: currently project doesn't use integration testing so you can ignore `integration` folder +They are in `typescript/test` and using vitest. Feel free to add new tests here. But note that most of tests are completion tests, but I do hope to add more types tests in the future. -They are in `typescript/test` and using vitest, so they faster than integration. Feel free to add new tests here. But note that most of tests are completion tests, but I do hope to add more types tests in the future. - -To launch them run `pnpm test-plugin`. - -#### Integration Tests - -They are in `integration`. This type of tests launches VSCode. For now I don't recommend either running or adding new tests here, use unit tests. -> Note that while running this script, you must also keep `pnpm start` running in the background. However, changing a file in `src/`, won't relaunch integration tests. If this is your case, you should edit the script. +To launch them run `pnpm test-plugin`. \ No newline at end of file diff --git a/integration/fixtures/test-project/jsconfig.json b/integration/fixtures/test-project/jsconfig.json deleted file mode 100644 index bc0a815b..00000000 --- a/integration/fixtures/test-project/jsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "compilerOptions": { - "jsx": "react-jsx" - }, - "include": [ - "src" - ] -} diff --git a/integration/fixtures/test-project/src/completions.ts b/integration/fixtures/test-project/src/completions.ts deleted file mode 100644 index e662dfe4..00000000 --- a/integration/fixtures/test-project/src/completions.ts +++ /dev/null @@ -1,7 +0,0 @@ -type A = { - (): void - sync: (arg1?: string) => {} -} - -let a: A -a.s \ No newline at end of file diff --git a/integration/fixtures/test-project/src/index.tsx b/integration/fixtures/test-project/src/index.tsx deleted file mode 100644 index 4afb2749..00000000 --- a/integration/fixtures/test-project/src/index.tsx +++ /dev/null @@ -1,23 +0,0 @@ -interface Type { - [p: string]: any -} - -const Component = () => { - return ( -
-
-
- c.value > 0).length} /> - -
-
-
- ) -} diff --git a/integration/index.ts b/integration/index.ts deleted file mode 100644 index 1f2cd137..00000000 --- a/integration/index.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { join } from 'path' -import glob from 'glob' -import Mocha from 'mocha' - -export const run = async () => { - const mocha = new Mocha({ - color: true, - parallel: false, - timeout: process.env.CI ? 5200 : 2000, - }) - const testsRoot = join(__dirname, './suite') - await new Promise(resolve => { - glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { - if (err) throw err - - const preFiles = [] as string[] - const postFiles = ['outline.test.js'] as string[] - - for (const file of preFiles) { - mocha.addFile(join(testsRoot, file)) - } - - for (const file of files.filter(file => !preFiles.includes(file) && !postFiles.includes(file))) { - mocha.addFile(join(testsRoot, file)) - } - - for (const file of postFiles) { - mocha.addFile(join(testsRoot, file)) - } - - mocha.run(failures => { - if (failures > 0) { - console.error(`${failures} tests failed.`) - setImmediate(() => { - process.exit(1) - }) - } else { - resolve() - } - }) - }) - }) -} diff --git a/integration/prerun.mjs b/integration/prerun.mjs deleted file mode 100644 index 22ef17ab..00000000 --- a/integration/prerun.mjs +++ /dev/null @@ -1,10 +0,0 @@ -//@ts-check -import fs from 'fs' - -try { - fs.unlinkSync('.vscode-test/user-data/User/settings.json') -} catch {} - -try { - fs.unlinkSync('out/plugin-config.json') -} catch {} diff --git a/integration/runTests.ts b/integration/runTests.ts deleted file mode 100644 index b68a49da..00000000 --- a/integration/runTests.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { join } from 'path' -import { runTests } from '@vscode/test-electron' - -async function main() { - try { - await runTests({ - version: 'stable', - extensionDevelopmentPath: join(__dirname, '../out'), - extensionTestsPath: join(__dirname, './index'), - launchArgs: [join(__dirname, '../integration/fixtures'), '--disable-extensions'], - }) - } catch (error) { - console.error(error) - console.error('Failed to run tests') - process.exit(1) - } -} - -void main() diff --git a/integration/suite/outline.test.ts b/integration/suite/outline.test.ts deleted file mode 100644 index 56c5e7b4..00000000 --- a/integration/suite/outline.test.ts +++ /dev/null @@ -1,176 +0,0 @@ -import * as vscode from 'vscode' -import delay from 'delay' -import dedent from 'string-dedent' - -import { expect } from 'chai' -// eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error -//@ts-ignore -import type { Configuration } from '../../src/configurationType' -import { fromFixtures, replaceEditorText } from './utils' - -describe('Outline', () => { - const content = dedent/* tsx */ ` - const classes = { - header: '...', - title: '...' - } - function A() { - return - before -
-
- -
- after - - } - ` - - let document: vscode.TextDocument - const editor = () => vscode.window.activeTextEditor! - - const getOutline = async () => vscode.commands.executeCommand('vscode.executeDocumentSymbolProvider', document.uri) as any - - // let editor: vscode.TextEditor - const startPos = new vscode.Position(0, 0) - before(async () => { - const configKey: keyof Configuration = 'patchOutline' - const configValue: Configuration['patchOutline'] = true - await vscode.workspace.getConfiguration('tsEssentialPlugins').update(configKey, configValue, vscode.ConfigurationTarget.Global) - await delay(600) - await vscode.workspace - .openTextDocument({ - content, - language: 'typescriptreact', - }) - .then(async newDocument => { - document = newDocument - /* editor = */ await vscode.window.showTextDocument(document) - }) - }) - - it('Outline untitled works', async () => { - console.time('get outline') - const data = await getOutline() - console.timeEnd('get outline') - expect(simplifyOutline(data)).to.deep.equal([ - { - name: 'A', - children: [ - { - name: 'Notification.test.another#yes', - children: [ - { - name: 'div#ok', - children: [ - { - name: 'div', - }, - { - name: 'span.good', - }, - ], - }, - ], - }, - ], - }, - ]) - await vscode.commands.executeCommand('workbench.action.closeActiveEditor') - }) - - describe('Outline in js project', () => { - it('Initial', async () => { - await delay(500) - await vscode.commands.executeCommand('vscode.open', vscode.Uri.file(fromFixtures('test-project/src/index.tsx'))) - await delay(600) - document = editor().document - const data = await getOutline() - expect(simplifyOutline(data)).to.deep.equal(jsProjectExpectedOutline()) - await vscode.commands.executeCommand('workbench.action.closeActiveEditor') - }) - - it('Reopen', async () => { - await delay(500) - await vscode.commands.executeCommand('vscode.open', vscode.Uri.file(fromFixtures('test-project/src/index.tsx'))) - await delay(600) - document = editor().document - const data = await getOutline() - expect(simplifyOutline(data)).to.deep.equal(jsProjectExpectedOutline()) - }) - - it('Text change', async () => { - const searchText = 'NavBar' - const componentEndPos = document.positionAt(document.getText().indexOf(searchText) + searchText.length) - await replaceEditorText(editor(), new vscode.Range(componentEndPos.translate(0, -1), componentEndPos), '2') - await delay(500) - const data = await getOutline() - expect(simplifyOutline(data)).to.deep.equal(jsProjectExpectedOutline('NavBa2')) - }) - - it('Text change right after TSServer restart', async () => { - void vscode.commands.executeCommand('typescript.restartTsServer') - const searchText = 'NavBa2' - const componentEndPos = document.positionAt(document.getText().indexOf(searchText) + searchText.length) - await editor().edit(builder => { - builder.replace(new vscode.Range(componentEndPos.translate(0, -1), componentEndPos), '3') - }) - await delay(800) - const data = await getOutline() - expect(simplifyOutline(data)).to.deep.equal(jsProjectExpectedOutline('NavBa3')) - }) - - it('Text change with no syntax server', async () => { - await vscode.workspace.getConfiguration('typescript').update('tsserver.useSyntaxServer', 'never', vscode.ConfigurationTarget.Global) - // void vscode.commands.executeCommand('typescript.restartTsServer') - await delay(300) - const searchText = 'NavBa3' - const componentEndPos = document.positionAt(document.getText().indexOf(searchText) + searchText.length) - await editor().edit(builder => { - builder.replace(new vscode.Range(componentEndPos.translate(0, -1), componentEndPos), '4') - }) - await delay(800) - const data = await getOutline() - expect(simplifyOutline(data)).to.deep.equal(jsProjectExpectedOutline('NavBa4')) - }).timeout(8000) - }) -}) - -const jsProjectExpectedOutline = (navbarPosName = 'NavBar') => [ - { - name: 'Component', - children: [ - { - name: 'div.main__wrap', - children: [ - { - name: 'main.container', - children: [ - { - name: 'div.card__box', - children: [ - { - name: navbarPosName, - }, - { - name: 'Counters', - }, - ], - }, - ], - }, - ], - }, - ], - }, -] - -const simplifyOutline = (items: Array) => { - const newItems: Array<{ name: any; children? }> = [] - for (const { children, name } of items) { - if (['classes', 'Type'].includes(name)) continue - newItems.push({ name, ...(children?.length ? { children: simplifyOutline(children as any) } : {}) }) - } - - return newItems -} diff --git a/integration/suite/utils.ts b/integration/suite/utils.ts deleted file mode 100644 index 38d60d6f..00000000 --- a/integration/suite/utils.ts +++ /dev/null @@ -1,51 +0,0 @@ -import delay from 'delay' -import { join } from 'path' -import * as vscode from 'vscode' - -export const fromFixtures = (path: string) => join(__dirname, '../../integration/fixtures', path) - -export const clearEditorText = async (editor: vscode.TextEditor, resetContent = '') => { - await new Promise(resolve => { - const { document } = editor - if (document.getText() === resetContent) { - resolve() - return - } - - const { dispose } = vscode.workspace.onDidChangeTextDocument(({ document }) => { - if (document.uri !== editor.document.uri) return - dispose() - resolve() - }) - void editor.edit(builder => - builder.replace(new vscode.Range(new vscode.Position(0, 0), document.lineAt(document.lineCount - 1).range.end), resetContent), - ) - }) -} - -export const replaceEditorText = async (editor: vscode.TextEditor, range: vscode.Range, text: string) => { - await new Promise(resolve => { - const { document } = editor - if (document.getText(range) === text) { - resolve() - return - } - - // eslint-disable-next-line sonarjs/no-identical-functions - const { dispose } = vscode.workspace.onDidChangeTextDocument(({ document }) => { - if (document.uri !== editor.document.uri) return - dispose() - resolve() - }) - void editor.edit(builder => builder.replace(range, text)) - }) -} - -// allow to use .only -let isFirstTsStart = true -export const prepareTsStart = async () => { - await delay(200) - if (!isFirstTsStart) return - isFirstTsStart = false - await delay(2000) -} diff --git a/package.json b/package.json index 38cf274d..7c794b76 100644 --- a/package.json +++ b/package.json @@ -135,10 +135,8 @@ "build-plugin:npm": "tsc -p typescript/tsconfig.npm.json", "lint": "eslint {src/**,typescript/src/**}", "format": "prettier --write '{src,typescript}/**/*.ts' --ignore-path .gitignore", - "test": "pnpm test-plugin --run && pnpm integration-test", + "test": "pnpm test-plugin --run", "test-plugin": "vitest --globals --dir typescript/test/ --environment ts-plugin", - "integration-test": "node integration/prerun.mjs && tsc -p tsconfig.test.json && node testsOut/runTests.js", - "integration-test:watch": "chokidar \"integration/**\" -c \"pnpm integration-test\" --initial", "postinstall": "patch-package && tsm ./typescript/scripts/patchModules.ts" }, "devDependencies": { @@ -232,4 +230,4 @@ } }, "packageManager": "pnpm@10.12.1+sha512.f0dda8580f0ee9481c5c79a1d927b9164f2c478e90992ad268bbb2465a736984391d6333d2c327913578b2804af33474ca554ba29c04a8b13060a717675ae3ac" -} \ No newline at end of file +} diff --git a/patches/@vscode+test-electron+2.1.5.patch b/patches/@vscode+test-electron+2.1.5.patch deleted file mode 100644 index 6b579062..00000000 --- a/patches/@vscode+test-electron+2.1.5.patch +++ /dev/null @@ -1,35 +0,0 @@ -# generated by patch-package 6.4.10 -# -# command: -# npx patch-package @vscode/test-electron -# -# declared package: -# @vscode/test-electron: ^2.1.5 -# -diff --git a/node_modules/@vscode/test-electron/out/runTest.js b/node_modules/@vscode/test-electron/out/runTest.js -index edf5f22..2206469 100644 ---- a/node_modules/@vscode/test-electron/out/runTest.js -+++ b/node_modules/@vscode/test-electron/out/runTest.js -@@ -62,7 +62,13 @@ async function innerRunTests(executable, args, testRunnerEnv) { - const fullEnv = Object.assign({}, process.env, testRunnerEnv); - const cmd = cp.spawn(executable, args, { env: fullEnv }); - cmd.stdout.on('data', d => process.stdout.write(d)); -- cmd.stderr.on('data', d => process.stderr.write(d)); -+ let debug = '' -+ cmd.stderr.on('data', d => { -+ const str = String(d) -+ if (str.includes('Failed to connect to the bus')) return -+ if (str.match(/(rejected promise)/)) process.stderr.write(d); -+ else debug += `\n${str}` -+ }); - cmd.on('error', function (data) { - console.log('Test error: ' + data.toString()); - }); -@@ -77,6 +83,7 @@ async function innerRunTests(executable, args, testRunnerEnv) { - reject(signal); - } - else if (code !== 0) { -+ console.log('debug', debug) - reject('Failed'); - } - else { diff --git a/tsconfig.test.json b/tsconfig.test.json deleted file mode 100644 index f8a01080..00000000 --- a/tsconfig.test.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "@zardoy/tsconfig/node", - "compilerOptions": { - "outDir": "testsOut", - "rootDir": "integration", - "noEmit": false - }, - "include": [ - "integration" - ], - "exclude": [ - "integration/fixtures" - ] -}