Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Not Ready] [typespec-vscode] E2e test for typespec vscode #5457

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ packages/*/etc/
# VS Code test web temp files
.vscode-test-web/

# VS Code test temp files
.vscode-test

# csharp emitter
!packages/http-client-csharp/package-lock.json
packages/http-client-csharp/generator/artifacts/
Expand Down
5 changes: 5 additions & 0 deletions packages/typespec-vscode/.vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from "@vscode/test-cli";

export default defineConfig({
files: ["dist/test/suite/*.test.cjs","dist/test/unit/*.test.cjs"], //
});
7 changes: 4 additions & 3 deletions packages/typespec-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@
"generate-third-party-notices": "typespec-build-tool generate-third-party-notices",
"package-vsix": "vsce package",
"deploy": "vsce publish",
"pretest": "pnpm compile",
"test": "vscode-test",
"open-in-browser": "vscode-test-web --extensionDevelopmentPath=. .",
"test:e2e": "pnpm test:web",
"test:web": "vscode-test-web --extensionDevelopmentPath=. --headless --extensionTestsPath=dist/test/web/suite.js ./test/web/data"
Expand All @@ -175,16 +177,15 @@
"@types/vscode": "~1.94.0",
"@typespec/compiler": "workspace:~",
"@typespec/internal-build-utils": "workspace:~",
"@vitest/coverage-v8": "^2.1.5",
"@vitest/ui": "^2.1.2",
"@vscode/test-web": "^0.0.62",
"@vscode/vsce": "~3.1.1",
"@vscode/test-cli": "^0.0.8",
"@vscode/test-electron": "^2.4.1",
"c8": "^10.1.2",
"mocha": "^10.7.3",
"rimraf": "~6.0.1",
"rollup": "~4.24.0",
"typescript": "~5.6.3",
"vitest": "^2.1.5",
"vscode-languageclient": "~9.0.1"
}
}
22 changes: 22 additions & 0 deletions packages/typespec-vscode/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ export default defineConfig([
},
plugins: [...plugins, ts("dist/test/web")],
},
{
...baseConfig,
input: "test/suite/extension.test.ts",
output: {
file: "dist/test/suite/extension.test.cjs",
format: "commonjs",
sourcemap: true,
inlineDynamicImports: true,
},
plugins: [...plugins, ts("dist/test/suite")],
},
{
...baseConfig,
input: "test/unit/extension.test.ts",
output: {
file: "dist/test/unit/extension.test.cjs",
format: "commonjs",
sourcemap: true,
inlineDynamicImports: true,
},
plugins: [...plugins, ts("dist/test/unit")],
},
]);

function ts(outDir: string) {
Expand Down
15 changes: 15 additions & 0 deletions packages/typespec-vscode/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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';

suite("Extension Test Suite", () => {
vscode.window.showInformationMessage("Start all tests.");

test("Sample test", () => {
assert.strictEqual([1, 2, 3].indexOf(5), -1);
assert.strictEqual([1, 2, 3].indexOf(0), -1);
});
});
15 changes: 4 additions & 11 deletions packages/typespec-vscode/test/unit/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { assert, beforeAll, describe, it } from "vitest";
import { ConsoleLogLogger } from "../../src/log/console-log-listener.js";
import logger from "../../src/log/logger.js";
import assert from "assert";

beforeAll(() => {
// we don't have vscode in test env. Hook console log listener
logger.registerLogListener("test", new ConsoleLogLogger());
});

describe("Hello world test", () => {
it("should pass", () => {
assert(true, "test sample");
suite("Unit test for vs-code", () => {
test("should return -1 when the value is not present", function () {
assert.equal([1, 2, 3].indexOf(4), -1);
});

// Add more unit test when needed
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-vscode/test/web/web.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from "vitest";
import assert from "assert";
import * as vscode from "vscode";

describe("Web Extension", () => {
Expand Down
11 changes: 0 additions & 11 deletions packages/typespec-vscode/vitest.config.ts

This file was deleted.

Loading