From f40c732956a896a2543267ea1885985d3a9f9fdf Mon Sep 17 00:00:00 2001 From: Test User Date: Wed, 9 Jul 2025 22:11:43 +0300 Subject: [PATCH] cleanup --- .eslintrc.json | 25 ----------- .npmrc | 1 - .vscode/extensions.json | 7 --- .vscode/launch.json | 38 ++++++++--------- eslint.config.js | 41 ++++++++++++++++++ package.json | 3 +- test/runTest.js | 16 ------- test/suite/extension.test.js | 82 ------------------------------------ test/suite/index.js | 36 ---------------- 9 files changed, 60 insertions(+), 189 deletions(-) delete mode 100644 .eslintrc.json delete mode 100644 .npmrc delete mode 100644 .vscode/extensions.json create mode 100644 eslint.config.js delete mode 100644 test/runTest.js delete mode 100644 test/suite/extension.test.js delete mode 100644 test/suite/index.js diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index d25565b..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "env": { - "browser": false, - "commonjs": true, - "es6": true, - "node": true, - "mocha": true - }, - "parserOptions": { - "ecmaVersion": 2018, - "ecmaFeatures": { - "jsx": true - }, - "sourceType": "module" - }, - "rules": { - "no-const-assign": "warn", - "no-this-before-super": "warn", - "no-undef": "warn", - "no-unreachable": "warn", - "no-unused-vars": "warn", - "constructor-super": "warn", - "valid-typeof": "warn" - } -} diff --git a/.npmrc b/.npmrc deleted file mode 100644 index 37d1b60..0000000 --- a/.npmrc +++ /dev/null @@ -1 +0,0 @@ -enable-pre-post-scripts = true \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 0915202..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the extensions.json format - "recommendations": [ - "dbaeumer.vscode-eslint" - ] -} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index c774552..803148b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,24 +3,22 @@ // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 { - "version": "0.2.0", - "configurations": [ - { - "name": "Run Extension", - "type": "extensionHost", - "request": "launch", - "args": [ - "--extensionDevelopmentPath=${workspaceFolder}" - ] - }, - { - "name": "Extension Tests", - "type": "extensionHost", - "request": "launch", - "args": [ - "--extensionDevelopmentPath=${workspaceFolder}", - "--extensionTestsPath=${workspaceFolder}/test/suite/index" - ] - } - ] + "version": "0.2.0", + "configurations": [ + { + "name": "Run Extension", + "type": "extensionHost", + "request": "launch", + "args": ["--extensionDevelopmentPath=${workspaceFolder}"] + }, + { + "name": "Extension Tests", + "type": "extensionHost", + "request": "launch", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}", + "--extensionTestsPath=${workspaceFolder}/test/suite/index" + ] + } + ] } diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..f8a0ede --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,41 @@ +import globals from "globals"; + +/** + * ESLint 9+ Flat Config + * - Node.js globals for all code + * - Mocha globals only for test files + * - Modern parser options and rule mapping + * + * Install: npm install --save-dev globals + */ + +export default [ + { + files: ["**/*.{js,jsx,ts,tsx}"], + languageOptions: { + ecmaVersion: 2022, + sourceType: "module", + globals: { + ...globals.node, + }, + }, + rules: { + "no-const-assign": "warn", + "no-this-before-super": "warn", + "no-undef": "warn", + "no-unreachable": "warn", + "no-unused-vars": "warn", + "constructor-super": "warn", + "valid-typeof": "warn", + }, + }, + { + // Mocha globals only inside tests + files: ["test/**/*", "tests/**/*", "**/*.test.js"], + languageOptions: { + globals: { + ...globals.mocha, + }, + }, + }, +]; diff --git a/package.json b/package.json index a29bc87..494fb57 100644 --- a/package.json +++ b/package.json @@ -37,8 +37,7 @@ "scripts": { "lint": "eslint .", "pretest": "pnpm run lint", - "prettier": "prettier -w src", - "test": "node ./test/runTest.js" + "prettier": "prettier -w src" }, "devDependencies": { "@types/mocha": "^10.0.6", diff --git a/test/runTest.js b/test/runTest.js deleted file mode 100644 index c1412d2..0000000 --- a/test/runTest.js +++ /dev/null @@ -1,16 +0,0 @@ -const path = require("path"); -const { runTests } = require("@vscode/test-electron"); - -async function main() { - try { - const extensionDevelopmentPath = path.resolve(__dirname, "../"); - const extensionTestsPath = path.resolve(__dirname, "./suite/index"); // Make sure this is correct - - await runTests({ extensionDevelopmentPath, extensionTestsPath }); - } catch (err) { - console.error("Failed to run tests", err); - process.exit(1); - } -} - -main(); diff --git a/test/suite/extension.test.js b/test/suite/extension.test.js deleted file mode 100644 index d2ba934..0000000 --- a/test/suite/extension.test.js +++ /dev/null @@ -1,82 +0,0 @@ -const assert = require("assert"); -const sinon = require("sinon"); -const vscode = require("vscode"); -const child_process = require("child_process"); -const fs = require("fs"); -const extension = require("../../extension"); -const { executeCommand } = require("../../src/helpers"); - -describe("Git Search Extension Tests", () => { - beforeEach(() => { - sinon.stub(child_process, "exec"); - sinon.stub(fs, "readFileSync"); - sinon.stub(vscode.window, "createWebviewPanel"); - }); - - afterEach(() => { - sinon.restore(); - }); - - it("should handle search command correctly", async () => { - const mockPanel = { webview: { postMessage: sinon.spy() } }; - extension.handleWebviewMessage( - { command: "search", text: "test query" }, - mockPanel - ); - assert.ok( - mockPanel.webview.postMessage.calledWith({ - command: "showResults", - text: "Loading", - }) - ); - }); - - it("should handle load more command correctly", async () => { - const mockPanel = { webview: { postMessage: sinon.spy() } }; - extension.handleWebviewMessage({ command: "loadMore" }, mockPanel); - assert.ok(mockPanel.webview.postMessage.called); - }); - - it("should handle reset command correctly", () => { - const mockPanel = { webview: { postMessage: sinon.spy() } }; - extension.handleWebviewMessage({ command: "reset" }, mockPanel); - assert.ok( - mockPanel.webview.postMessage.calledWith({ command: "reset", text: "" }) - ); - }); - - it("should execute Git search and update panel", async () => { - const mockPanel = { webview: { postMessage: sinon.spy() } }; - child_process.exec.callsArgWith( - 2, - null, - "commitHash|authorName|commitDate\n" - ); - await extension.executeGitSearch("test query", mockPanel); - assert.ok(mockPanel.webview.postMessage.called); - }); - - xit("should execute command and return result", async () => { - child_process.exec.callsArgWith(2, null, "output", ""); - const result = await executeCommand("git status", "."); - assert.equal(result, "output"); - }); - - xit("should get repository URL", async () => { - child_process.exec.callsArgWith( - 2, - null, - "git@github.com:user/repo.git", - "" - ); - const url = await extension.getRepoUrl("."); - assert.equal(url, "https://github.com/user/repo"); - }); - - it("should load HTML content for Webview", () => { - const htmlString = "Mock Content"; - fs.readFileSync.returns(htmlString); - const content = extension.getWebviewContent(); - assert.ok(content.includes(htmlString)); - }); -}); diff --git a/test/suite/index.js b/test/suite/index.js deleted file mode 100644 index ac9f747..0000000 --- a/test/suite/index.js +++ /dev/null @@ -1,36 +0,0 @@ -const path = require("path"); -const Mocha = require("mocha"); -const { globSync } = require("glob"); - -async function run() { - // Create the mocha test - const mocha = new Mocha({ - ui: "bdd", - color: true, - }); - - const testsRoot = path.resolve(__dirname, ".."); - const files = globSync("**/**.test.js", { cwd: testsRoot }); - - // Add files to the test suite - files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f))); - - try { - return await new Promise((c, e) => { - // Run the mocha test - mocha.run((failures) => { - if (failures > 0) { - e(new Error(`${failures} tests failed.`)); - } else { - c(); - } - }); - }); - } catch (err) { - console.error(err); - } -} - -module.exports = { - run, -};