Skip to content

Commit

Permalink
feat: support ts and update deps (#85)
Browse files Browse the repository at this point in the history
* feat: support ts and update deps

* chore: revert yarn.lock

* feat: add unit tests

* fix: ci failed

* fix: ci

* chore: ignore compile ts/tsx file in fixtures

* chore: make file name more consistent

* chore: move @types package to devDependencies
  • Loading branch information
iChenLei committed Apr 21, 2023
1 parent 4fc1c2a commit 32aae48
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 122 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
name: VSCode Test

# Triggers the workflow on push or pull request events
on: [push, pull_request]
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

jobs:
VSCode-Test:
name: 'CI on ${{matrix.os}} with node14'
name: 'CI on ${{matrix.os}} with nodejs'
strategy:
matrix:
os: [macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 2
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'yarn'
- run: yarn install
- run: yarn test

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"activationEvents": [
"onLanguage:typescriptreact",
"onLanguage:javascriptreact",
"onLanguage:javascript"
"onLanguage:javascript",
"onLanguage:typescript"
],
"contributes": {
"configuration": {
Expand Down Expand Up @@ -52,13 +53,14 @@
"prepare": "husky install"
},
"devDependencies": {
"@types/fs-extra": "^9.0.11",
"@types/glob": "^7.1.3",
"@types/mocha": "^8.2.2",
"@types/node": "14.x",
"@types/vscode": "^1.56.0",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"@vscode/test-electron": "^1.6.1",
"@vscode/test-electron": "^2.3.0",
"eslint": "^7.27.0",
"glob": "^7.1.7",
"husky": ">=6",
Expand All @@ -68,7 +70,6 @@
"typescript": "^4.3.2"
},
"dependencies": {
"@types/fs-extra": "^9.0.11",
"fs-extra": "^10.0.0",
"json5": "^2.2.0",
"lodash": "^4.17.4"
Expand Down
7 changes: 5 additions & 2 deletions src/test/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import * as path from "path";
export const ROOT_PATH = path.join(__dirname, "..", "..");
export const FIXTURES_PATH = path.join(ROOT_PATH, "src", "test", "fixtures");

export const SAMPLE_JS_FILE = path.join(FIXTURES_PATH, "sample.jsx");
export const STYLUS_JS_FILE = path.join(FIXTURES_PATH, "stylus.jsx");
export const SAMPLE_JSX_FILE = path.join(FIXTURES_PATH, "sample.jsx");
export const SAMPLE_JS_FILE = path.join(FIXTURES_PATH, "sample.js");
export const SAMPLE_TSX_FILE = path.join(FIXTURES_PATH, "sample.tsx");
export const SAMPLE_TS_FILE = path.join(FIXTURES_PATH, "sample.ts");
export const STYLUS_JSX_FILE = path.join(FIXTURES_PATH, "stylus.jsx");
export const JUMP_PRECISE_DEF_FILE = path.join(FIXTURES_PATH, "jumpDef.jsx");
export const SPREAD_SYNTAX_FILE = path.join(FIXTURES_PATH, "spread-syntax", "index.js");
5 changes: 5 additions & 0 deletions src/test/fixtures/sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import styles from './sample.css'

const myTheme = {
backgroundTheme: styles.container
}
9 changes: 9 additions & 0 deletions src/test/fixtures/sample.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import styles from './sample.css'

interface ITheme {
backgroundTheme: string;
}

const myTheme: ITheme = {
backgroundTheme: styles.container
}
9 changes: 9 additions & 0 deletions src/test/fixtures/sample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import styles from './sample.css'

interface ITheme {
backgroundTheme: string;
}

const myTheme: ITheme = {
backgroundTheme: styles.container
}
37 changes: 34 additions & 3 deletions src/test/suite/CompletionProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import * as vscode from "vscode";

import { CSSModuleCompletionProvider } from "../../CompletionProvider";
import { CamelCaseValues } from "../../options";
import { SAMPLE_JS_FILE, STYLUS_JS_FILE } from "../constant";
import { SAMPLE_JSX_FILE, SAMPLE_JS_FILE, SAMPLE_TSX_FILE, SAMPLE_TS_FILE, STYLUS_JSX_FILE } from "../constant";
import { readOptions } from "../utils";

const uri = vscode.Uri.file(SAMPLE_JS_FILE);
const uri2 = vscode.Uri.file(STYLUS_JS_FILE);
const uri = vscode.Uri.file(SAMPLE_JSX_FILE);
const uri2 = vscode.Uri.file(STYLUS_JSX_FILE);
const uri3 = vscode.Uri.file(SAMPLE_JS_FILE);
const uri4 = vscode.Uri.file(SAMPLE_TSX_FILE);
const uri5 = vscode.Uri.file(SAMPLE_TS_FILE);

function testCompletion(position: vscode.Position, itemCount: number, fixtureFile?: vscode.Uri) {
return vscode.workspace.openTextDocument(fixtureFile || uri).then((text) => {
Expand Down Expand Up @@ -131,3 +134,31 @@ test("test camelCase:dashes style completion", () => {
assert.ok(false, `error in OpenTextDocument ${err}`);
});
});

test("support jsx", () => {
const position = new vscode.Position(3, 20);
return Promise.resolve(testCompletion(position, 5, uri)).catch((err) => {
assert.ok(false, `error in OpenTextDocument ${err}`);
});
});

test("support js", () => {
const position = new vscode.Position(3, 28);
return Promise.resolve(testCompletion(position, 5, uri3)).catch((err) => {
assert.ok(false, `error in OpenTextDocument ${err}`);
});
});

test("support tsx", () => {
const position = new vscode.Position(7, 28);
return Promise.resolve(testCompletion(position, 5, uri4)).catch((err) => {
assert.ok(false, `error in OpenTextDocument ${err}`);
});
});

test("support ts", () => {
const position = new vscode.Position(7, 28);
return Promise.resolve(testCompletion(position, 5, uri5)).catch((err) => {
assert.ok(false, `error in OpenTextDocument ${err}`);
});
});
8 changes: 4 additions & 4 deletions src/test/suite/DefinitionProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { CSSModuleDefinitionProvider } from "../../DefinitionProvider";
import { CamelCaseValues } from "../../options";
import {
JUMP_PRECISE_DEF_FILE,
SAMPLE_JS_FILE,
SAMPLE_JSX_FILE,
SPREAD_SYNTAX_FILE,
STYLUS_JS_FILE,
STYLUS_JSX_FILE,
} from "../constant";
import { readOptions } from "../utils";

const uri = vscode.Uri.file(SAMPLE_JS_FILE);
const uri = vscode.Uri.file(SAMPLE_JSX_FILE);
const uri2 = vscode.Uri.file(JUMP_PRECISE_DEF_FILE);
const uri3 = vscode.Uri.file(STYLUS_JS_FILE);
const uri3 = vscode.Uri.file(STYLUS_JSX_FILE);

function getDefinitionLineAndChar(
position: vscode.Position,
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"exclude": [
"node_modules",
".vscode-test",
"out"
"out",
"src/test/fixtures" // #85
]
}

0 comments on commit 32aae48

Please sign in to comment.