diff --git a/package.json b/package.json index 335d96a2..cfa99e25 100644 --- a/package.json +++ b/package.json @@ -17,11 +17,11 @@ "url": "https://github.com/NomicFoundation/hardhat-vscode/issues" }, "scripts": { - "build": "tsc -b ./client/tsconfig.json && tsc -b ./server/tsconfig.build.json && tsc -b ./coc/tsconfig.json && tsc -b", + "build": "tsc -b ./client/tsconfig.json && tsc -b ./server/tsconfig.build.json && tsc -b ./coc/tsconfig.json", "watch": "concurrently -n client,server \"tsc -b -w ./client/tsconfig.json\" \"tsc -b -w ./server/tsconfig.build.json\"", "test:unit": "npm -w server run test", "test:protocol": "npm -w test/protocol run test", - "test:e2e": "npm run build && node ./out/test/runTests.js", + "test:e2e": "npm -w test/e2e run test", "test": "npm run test:unit && npm run test:protocol && npm run test:e2e", "test:coverage": "npm -w server run test:coverage", "test:codecov": "npm -w server run test:codecov", diff --git a/test/e2e/.eslintrc.js b/test/e2e/.eslintrc.js new file mode 100644 index 00000000..e2060254 --- /dev/null +++ b/test/e2e/.eslintrc.js @@ -0,0 +1,21 @@ +/** @type {import('eslint').Linter.Config} */ +module.exports = { + root: true, + extends: [`../../.eslintrc.js`], + parserOptions: { + project: `${__dirname}/tsconfig.json`, + sourceType: "module", + }, + overrides: [ + { + files: ["**/*.ts"], + rules: { + "@typescript-eslint/no-floating-promises": "error", + "@typescript-eslint/no-unused-vars": "warn", + "@typescript-eslint/no-empty-function": "warn", + "@typescript-eslint/no-non-null-assertion": "off", + "no-empty": "warn", + }, + }, + ], +}; diff --git a/test/e2e/.gitignore b/test/e2e/.gitignore new file mode 100644 index 00000000..1fcb1529 --- /dev/null +++ b/test/e2e/.gitignore @@ -0,0 +1 @@ +out diff --git a/test/e2e/client.ts b/test/e2e/client.ts deleted file mode 100644 index ec07d028..00000000 --- a/test/e2e/client.ts +++ /dev/null @@ -1,111 +0,0 @@ -"use strict"; - -import * as path from "path"; -import * as vscode from "vscode"; -import * as lsclient from "vscode-languageclient/node"; - -import { sleep } from "./helpers/sleep"; -import { Client as IClient } from "./common/types"; - -let client: Client | null = null; - -export async function getClient(): Promise { - if (client) { - return client; - } - - client = new Client(); - - try { - await client.activate(); - } catch (err) { - // eslint-disable-next-line no-console - console.error(err); - process.exit(1); - } - - return client; -} - -class Client implements IClient { - public client: lsclient.LanguageClient; - public tokenSource: vscode.CancellationTokenSource = - new vscode.CancellationTokenSource(); - - public document: vscode.TextDocument | null = null; - public docUri: vscode.Uri | null = null; - - constructor() { - const serverModule = path.join( - __dirname, - "..", - "..", - "..", - "server", - "out", - "index.js" - ); - - const serverOptions: lsclient.ServerOptions = { - run: { module: serverModule, transport: lsclient.TransportKind.ipc }, - debug: { - module: serverModule, - transport: lsclient.TransportKind.ipc, - options: { execArgv: ["--nolazy", "--inspect=6014"] }, - }, - }; - - const clientOptions: lsclient.LanguageClientOptions = { - documentSelector: [{ scheme: "file", language: "solidity" }], - synchronize: { - fileEvents: vscode.workspace.createFileSystemWatcher("**/.sol"), - }, - initializationOptions: { - extensionName: "nomicfoundation.hardhat-solidity", - extensionVersion: "0.0.0", - env: "development", - telemetryEnabled: false, - machineId: "fake-interagtion-machine-id", - }, - }; - - this.client = new lsclient.LanguageClient( - "testSolidityLanguageServer", - "Test Solidity Language Server", - serverOptions, - clientOptions - ); - } - - /** - * Activates the extension - */ - public async activate(): Promise { - // The extensionId is `publisher.name` from package.json - const ext = vscode.extensions.getExtension( - "nomicfoundation.hardhat-solidity" - ); - - if (!ext) { - throw new Error("Extension not found"); - } - - await ext.activate(); - - this.client.start(); - - await this.client.onReady(); - - // while (ext.exports.isReady() !== true) { - // await sleep(100); - // } - - await sleep(10000); - } - - public async changeDocument(docUri: vscode.Uri) { - this.docUri = docUri; - - this.document = await vscode.workspace.openTextDocument(this.docUri); - } -} diff --git a/test/e2e/package.json b/test/e2e/package.json index dfba3368..aeab69e0 100644 --- a/test/e2e/package.json +++ b/test/e2e/package.json @@ -3,6 +3,9 @@ "version": "1.0.0", "private": true, "scripts": { - "postinstall": "cd ./projects/main && npm install" + "postinstall": "cd ./projects/main && npm install", + "pretest": "tsc -b ./tsconfig.json", + "test": "node ./out/runTests.js", + "clean": "rimraf out .nyc_output coverage *.tsbuildinfo" } } diff --git a/test/e2e/common/assertLspCommand.ts b/test/e2e/src/common/assertLspCommand.ts similarity index 100% rename from test/e2e/common/assertLspCommand.ts rename to test/e2e/src/common/assertLspCommand.ts diff --git a/test/e2e/common/types.ts b/test/e2e/src/common/types.ts similarity index 100% rename from test/e2e/common/types.ts rename to test/e2e/src/common/types.ts diff --git a/test/e2e/helpers/assertions.ts b/test/e2e/src/helpers/assertions.ts similarity index 100% rename from test/e2e/helpers/assertions.ts rename to test/e2e/src/helpers/assertions.ts diff --git a/test/e2e/helpers/commands.ts b/test/e2e/src/helpers/commands.ts similarity index 100% rename from test/e2e/helpers/commands.ts rename to test/e2e/src/helpers/commands.ts diff --git a/test/e2e/helpers/editor.ts b/test/e2e/src/helpers/editor.ts similarity index 100% rename from test/e2e/helpers/editor.ts rename to test/e2e/src/helpers/editor.ts diff --git a/test/e2e/helpers/getTestContract.ts b/test/e2e/src/helpers/getTestContract.ts similarity index 100% rename from test/e2e/helpers/getTestContract.ts rename to test/e2e/src/helpers/getTestContract.ts diff --git a/test/e2e/helpers/joinLines.ts b/test/e2e/src/helpers/joinLines.ts similarity index 100% rename from test/e2e/helpers/joinLines.ts rename to test/e2e/src/helpers/joinLines.ts diff --git a/test/e2e/helpers/sleep.ts b/test/e2e/src/helpers/sleep.ts similarity index 100% rename from test/e2e/helpers/sleep.ts rename to test/e2e/src/helpers/sleep.ts diff --git a/test/e2e/helpers/workspace.ts b/test/e2e/src/helpers/workspace.ts similarity index 100% rename from test/e2e/helpers/workspace.ts rename to test/e2e/src/helpers/workspace.ts diff --git a/test/e2e/index.ts b/test/e2e/src/index.ts similarity index 100% rename from test/e2e/index.ts rename to test/e2e/src/index.ts diff --git a/test/runTests.ts b/test/e2e/src/runTests.ts similarity index 75% rename from test/runTests.ts rename to test/e2e/src/runTests.ts index 94a2fdfc..c8d7f0e2 100644 --- a/test/runTests.ts +++ b/test/e2e/src/runTests.ts @@ -1,7 +1,7 @@ import * as path from "path"; import { runTests } from "@vscode/test-electron"; -(async () => { +const main = async () => { try { // The folder containing the Extension Manifest package.json // Passed to `--extensionDevelopmentPath` @@ -9,14 +9,15 @@ import { runTests } from "@vscode/test-electron"; __dirname, "..", "..", + "..", "client" ); // The path to test runner // Passed to --extensionTestsPath - const extensionTestsPath = path.resolve(__dirname, "e2e", "index"); + const extensionTestsPath = path.resolve(__dirname, "index"); - const folder = path.resolve(__dirname, "..", "..", "test", "e2e"); + const folder = path.resolve(__dirname, "..", "..", "e2e"); // Download VS Code, unzip it and run the e2e test await runTests({ @@ -39,4 +40,10 @@ import { runTests } from "@vscode/test-electron"; console.error("Failed to run tests, err:", err); process.exitCode = 1; } -})(); +}; + +main().catch((err) => { + // eslint-disable-next-line no-console + console.error("Failed to run tests, err:", err); + process.exitCode = 1; +}); diff --git a/test/e2e/tests/commands/clean.test.ts b/test/e2e/src/tests/commands/clean.test.ts similarity index 90% rename from test/e2e/tests/commands/clean.test.ts rename to test/e2e/src/tests/commands/clean.test.ts index 62835c4f..007e747a 100644 --- a/test/e2e/tests/commands/clean.test.ts +++ b/test/e2e/src/tests/commands/clean.test.ts @@ -12,9 +12,11 @@ suite("task - clean", function () { // Create an artifacts folder to be cleaned up const artifactsPath = path.join(getRootPath(), "projects/main/artifacts"); + if (!existsSync(artifactsPath)) { mkdirSync(artifactsPath); } + assert.ok(existsSync(artifactsPath)); // Run clean task @@ -22,12 +24,16 @@ suite("task - clean", function () { type: "hardhat", task: "clean", }); + await waitForUI(); // Wait for the task to finish await new Promise((resolve) => vscode.tasks.onDidEndTask(resolve)); // Assert the artifacts were removed - assert.ok(!existsSync(artifactsPath)); + assert.ok( + !existsSync(artifactsPath), + `Artifacts folder was not removed: ${artifactsPath}` + ); }); }); diff --git a/test/e2e/tests/commands/flatten.test.ts b/test/e2e/src/tests/commands/flatten.test.ts similarity index 100% rename from test/e2e/tests/commands/flatten.test.ts rename to test/e2e/src/tests/commands/flatten.test.ts diff --git a/test/e2e/tests/language-configuration/onEnterRules.test.ts b/test/e2e/src/tests/language-configuration/onEnterRules.test.ts similarity index 100% rename from test/e2e/tests/language-configuration/onEnterRules.test.ts rename to test/e2e/src/tests/language-configuration/onEnterRules.test.ts diff --git a/test/e2e/tsconfig.json b/test/e2e/tsconfig.json new file mode 100644 index 00000000..aba753db --- /dev/null +++ b/test/e2e/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + "module": "commonjs" /* Specify what module code is generated. */, + "resolveJsonModule": true /* Enable importing .json files. */, + "outDir": "./out" /* Specify an output folder for all emitted files. */, + "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, + "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, + "strict": true /* Enable all strict type-checking options. */, + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + }, + "include": ["src"] +}