Skip to content

Commit

Permalink
Assert that we produce diagnostics in vscode. (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
rictic authored Feb 3, 2022
1 parent ad10d44 commit 9a97f32
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class MyElement extends HTMLElement {}
customElements.define("my-element", MyElement);
5 changes: 5 additions & 0 deletions packages/vscode-lit-plugin/src/test/fixtures/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noEmit": true
}
}
3 changes: 2 additions & 1 deletion packages/vscode-lit-plugin/src/test/scripts/mocha-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import glob from "glob";
export async function run(): Promise<void> {
const mocha = new Mocha({
ui: "tdd",
color: true
color: true,
timeout: 20_000
});

const testsRoot = path.join(__dirname, "..");
Expand Down
30 changes: 30 additions & 0 deletions packages/vscode-lit-plugin/src/test/simple-test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as assert from "assert";
import { after } from "mocha";
import * as path from "path";

// 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 litPlugin from "../extension.js";

suite("Extension Test Suite", () => {
after(() => {
Expand All @@ -15,4 +17,32 @@ suite("Extension Test Suite", () => {
const ourId = "runem.lit-plugin";
assert.ok(extensionIds.includes(ourId), `Expected ${JSON.stringify(extensionIds)} to include '${ourId}'`);
});

test("We produce a diagnostic", async () => {
const config = vscode.workspace.getConfiguration();
config.update("lit-plugin.logging", "verbose", true);
config.update("lit-plugin.rules.no-missing-element-type-definition", "error", true);
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.join(__dirname, "../../src/test/fixtures/missing-elem-type.ts")));
await vscode.window.showTextDocument(doc);

// wait until the TS language server is ready and diagnostics are produced
async function getDiagnostics() {
for (let i = 0; i < 100; i++) {
const diagnostics = vscode.languages.getDiagnostics(doc.uri);
if (diagnostics.length > 0) {
return diagnostics;
}
// Is there a better way to wait for the ts server to be ready?
// Maybe we can listen for the event that displays and hides the "initializing TS/JS language features" message?
await new Promise(resolve => setTimeout(resolve, 100));
}
throw new Error("No diagnostics found");
}

const diagnostics = await getDiagnostics();
assert.deepStrictEqual(
diagnostics.map(d => d.message),
["'my-element' has not been registered on HTMLElementTagNameMap"]
);
});
});
4 changes: 2 additions & 2 deletions packages/vscode-lit-plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"extends": "../../tsconfig.json",
"include": ["./src"],
"exclude": ["node_modules"],
"exclude": ["node_modules", "./src/test/fixtures"],
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"lib": ["es6"],
"lib": ["es2019"],
"sourceMap": true,
"rootDir": "src"
}
Expand Down

0 comments on commit 9a97f32

Please sign in to comment.