Skip to content

chore(ci): switch to vitest for testing #835

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

Merged
merged 5 commits into from
Dec 10, 2023
Merged
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
13 changes: 9 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,17 @@ module.exports = {
},
},
{
files: ['**/*.spec.*'],
files: ['**/*.test.*'],
extends: [
'plugin:jest/recommended',
'plugin:jest/style',
'plugin:vitest/all',
],
rules: {},
rules: {
'vitest/max-expects': 'off',
'vitest/no-conditional-in-test': 'off',
'vitest/no-conditional-tests': 'off',
'vitest/no-hooks': 'off',
'vitest/require-top-level-describe': 'off',
},
},
],
};
4 changes: 2 additions & 2 deletions .github/workflows/semantic-commits.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PR Conventional Commit Validation
name: Conventional Commit Validation

on:
pull_request:
Expand All @@ -8,7 +8,7 @@ jobs:
validate-pr-title:
runs-on: ubuntu-latest
steps:
- name: PR Conventional Commit Validation
- name: Conventional Commit Validation
uses: ytanikin/PRConventionalCommits@1.1.0
with:
task_types: '["feat","fix","docs","test","ci","refactor","perf","chore","revert"]'
16 changes: 0 additions & 16 deletions .vscode/launch.json

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
}
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Maintained by a [community of contributors](https://github.com/typescript-langua
- [TypeScript Version Notification](#typescript-version-notification)
- [Development](#development)
- [Build](#build)
- [Dev](#dev)
- [Test](#test)
- [Watch](#watch)
- [Publishing](#publishing)

<!-- /MarkdownTOC -->
Expand Down Expand Up @@ -277,22 +277,24 @@ The `$/typescriptVersion` notification params include two properties:
### Build

```sh
yarn
yarn build
```

### Test

- `yarn test` - run all tests
- `yarn test:watch` - run all tests and enable watch mode for developing
### Dev

By default only console logs of level `warning` and higher are printed to the console. You can override the `CONSOLE_LOG_LEVEL` level in `package.json` to either `log`, `info`, `warning` or `error` to log other levels.

### Watch
Build and rebuild on change.

```sh
yarn watch
yarn dev
```

### Test

- `yarn test` - run all tests in watch mode for developing
- `yarn test:commit` - run all tests once

By default only console logs of level `warning` and higher are printed to the console. You can override the `CONSOLE_LOG_LEVEL` level in `package.json` to either `log`, `info`, `warning` or `error` to log other levels.

### Publishing

The project uses https://github.com/google-github-actions/release-please-action Github action to automatically release new version on merging a release PR.
Expand Down
24 changes: 0 additions & 24 deletions jest.config.ts

This file was deleted.

23 changes: 7 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
"typescript-language-server": "./lib/cli.mjs"
},
"scripts": {
"dev": "rimraf lib && rollup --config rollup.config.ts --configPlugin typescript --watch",
"build": "rimraf lib && rollup --config rollup.config.ts --configPlugin typescript",
"clean": "rimraf lib *.tsbuildinfo",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules CONSOLE_LOG_LEVEL=warning jest",
"test:watch": "cross-env NODE_OPTIONS=--experimental-vm-modules CONSOLE_LOG_LEVEL=warning jest --watch",
"test": "cross-env CONSOLE_LOG_LEVEL=warning vitest",
"test:commit": "cross-env CONSOLE_LOG_LEVEL=warning vitest run",
"lint": "eslint --ext \".js,.ts\" src",
"fix": "eslint --ext \".js,.ts\" --fix src",
"build": "concurrently -n compile,lint -c blue,green \"yarn compile\" \"yarn lint\"",
"compile": "rimraf lib && rollup --config rollup.config.ts --configPlugin typescript",
"watch": "rimraf lib && rollup --config rollup.config.ts --configPlugin typescript --watch",
"size": "yarn build && yarn size-limit",
"postversion": "git push --follow-tags",
"prepare": "cd test-data/jsx && yarn"
Expand All @@ -36,36 +35,30 @@
],
"husky": {
"hooks": {
"pre-commit": "yarn lint && yarn test && yarn build",
"pre-commit": "concurrently -n build,lint,test \"yarn build\" \"yarn lint\" \"yarn test:commit\"",
"post-merge": "yarn"
}
},
"devDependencies": {
"@babel/core": "^7.23.5",
"@babel/preset-env": "^7.23.5",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.5",
"@size-limit/file": "^11.0.1",
"@types/deepmerge": "^2.2.0",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.11",
"@types/node": "^18.19.3",
"@types/semver": "^7.5.6",
"@types/which": "^3.0.3",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"babel-jest": "^29.7.0",
"commander": "^11.1.0",
"concurrently": "^8.2.2",
"cross-env": "^7.0.3",
"deepmerge": "^4.3.1",
"eslint": "^8.55.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-vitest": "^0.3.13",
"fs-extra": "^11.2.0",
"husky": "4.x",
"jest": "^29.7.0",
"p-debounce": "^4.0.0",
"pkg-up": "^4.0.0",
"rimraf": "^5.0.5",
Expand All @@ -74,10 +67,8 @@
"size-limit": "^11.0.1",
"source-map-support": "^0.5.21",
"tempy": "^3.1.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"vitest": "^1.0.4",
"vscode-jsonrpc": "^8.2.0",
"vscode-languageserver": "^9.0.1",
"vscode-languageserver-protocol": "^3.17.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import { describe, it, expect, beforeAll, beforeEach, afterAll } from 'vitest';
import * as lsp from 'vscode-languageserver';
import { uri, createServer, TestLspServer, positionAfter, documentFromFile, openDocumentAndWaitForDiagnostics } from '../test-utils.js';

Expand Down Expand Up @@ -47,25 +48,25 @@ function callsToString(item: CallHierarchyItemWithChildren, indentLevel: number,
}
}

beforeAll(async () => {
server = await createServer({
rootUri: uri(),
publishDiagnostics: args => diagnostics.set(args.uri, args),
describe('call hierarchy', () => {
beforeAll(async () => {
server = await createServer({
rootUri: uri(),
publishDiagnostics: args => diagnostics.set(args.uri, args),
});
});
});

beforeEach(() => {
server.closeAllForTesting();
// "closeAllForTesting" triggers final publishDiagnostics with an empty list so clear last.
diagnostics.clear();
});
beforeEach(() => {
server.closeAllForTesting();
// "closeAllForTesting" triggers final publishDiagnostics with an empty list so clear last.
diagnostics.clear();
});

afterAll(() => {
server.closeAllForTesting();
server.shutdown();
});
afterAll(() => {
server.closeAllForTesting();
server.shutdown();
});

describe('call hierarchy', () => {
const oneDoc = documentFromFile({ path: 'call-hierarchy/one.ts' });
const twoDoc = documentFromFile({ path: 'call-hierarchy/two.ts' });
const threeDoc = documentFromFile({ path: 'call-hierarchy/three.ts' });
Expand All @@ -90,7 +91,7 @@ describe('call hierarchy', () => {
const incomingCalls = await getIncomingCalls(server, item);
callsToString(incomingCalls, 0, lines);
}
expect(lines.join('\n')).toEqual(`
expect(lines.join('\n')).toStrictEqual(`
-|> tada (symbol: three.ts#2)
-|> callThreeTwice (symbol: two.ts#3)
-|> main (symbol: one.ts#2)
Expand All @@ -112,7 +113,7 @@ describe('call hierarchy', () => {
const outgoingCalls = await getOutgoingCalls(server, item);
callsToString(outgoingCalls, 0, lines);
}
expect(lines.join('\n')).toEqual(`
expect(lines.join('\n')).toStrictEqual(`
-|> callThreeTwice (symbol: two.ts#3)
-|> tada (symbol: three.ts#2)
-|> print (symbol: three.ts#6)
Expand Down
43 changes: 30 additions & 13 deletions src/file-lsp-server.spec.ts → src/file-lsp-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import { describe, it, expect, beforeAll, beforeEach, afterAll } from 'vitest';
import { uri, createServer, lastPosition, filePath, readContents, positionAfter, openDocumentAndWaitForDiagnostics, TestLspServer } from './test-utils.js';

let server: TestLspServer;

beforeAll(async () => {
server = await createServer({
rootUri: uri(),
publishDiagnostics: () => { },
describe('documentHighlight', () => {
beforeAll(async () => {
server = await createServer({
rootUri: uri(),
publishDiagnostics: () => { },
});
});
});

beforeEach(() => {
server.closeAllForTesting();
});
beforeEach(() => {
server.closeAllForTesting();
});

afterAll(() => {
server.closeAllForTesting();
server.shutdown();
});
afterAll(() => {
server.closeAllForTesting();
server.shutdown();
});

describe('documentHighlight', () => {
it('simple test', async () => {
const doc = {
uri: uri('module2.ts'),
Expand All @@ -43,6 +44,22 @@ describe('documentHighlight', () => {
});

describe('completions', () => {
beforeAll(async () => {
server = await createServer({
rootUri: uri(),
publishDiagnostics: () => { },
});
});

beforeEach(() => {
server.closeAllForTesting();
});

afterAll(() => {
server.closeAllForTesting();
server.shutdown();
});

it('receives completion that auto-imports from another module', async () => {
const doc = {
uri: uri('completion.ts'),
Expand Down
15 changes: 8 additions & 7 deletions src/lsp-server.spec.ts → src/lsp-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import { describe, it, expect, beforeAll, beforeEach, afterAll } from 'vitest';
import fs from 'fs-extra';
import * as lsp from 'vscode-languageserver';
import { TextDocument } from 'vscode-languageserver-textdocument';
Expand Down Expand Up @@ -91,7 +92,7 @@ describe('completion', () => {
(current.kind !== lsp.CompletionItemKind.Function && current.kind !== lsp.CompletionItemKind.Method);
}, false);

expect(containsInvalidCompletions).toBe(false);
expect(containsInvalidCompletions).toBeFalsy();
});

it('deprecated by JSDoc', async () => {
Expand Down Expand Up @@ -277,7 +278,7 @@ describe('completion', () => {
expect(proposals).not.toBeNull();
const completion = proposals!.items.find(completion => completion.label === 'readFile');
expect(completion).toBeDefined();
expect(completion).toEqual(expect.objectContaining({
expect(completion).toStrictEqual(expect.objectContaining({
label: 'readFile',
kind: lsp.CompletionItemKind.Function,
insertTextFormat: lsp.InsertTextFormat.Snippet,
Expand Down Expand Up @@ -838,10 +839,10 @@ describe('diagnostics', () => {
expect(fileDiagnostics).toHaveLength(2);
const unusedDiagnostic = fileDiagnostics.find(d => d.code === 6133);
expect(unusedDiagnostic).toBeDefined();
expect(unusedDiagnostic!.tags).toEqual([lsp.DiagnosticTag.Unnecessary]);
expect(unusedDiagnostic!.tags).toStrictEqual([lsp.DiagnosticTag.Unnecessary]);
const deprecatedDiagnostic = fileDiagnostics.find(d => d.code === 6387);
expect(deprecatedDiagnostic).toBeDefined();
expect(deprecatedDiagnostic!.tags).toEqual([lsp.DiagnosticTag.Deprecated]);
expect(deprecatedDiagnostic!.tags).toStrictEqual([lsp.DiagnosticTag.Deprecated]);
});

it('multiple files test', async () => {
Expand Down Expand Up @@ -1482,7 +1483,7 @@ describe('code actions', () => {
},
}))!;

expect(result).toEqual([]);
expect(result).toStrictEqual([]);
});

it('provides organize imports when there are no errors', async () => {
Expand Down Expand Up @@ -2396,7 +2397,7 @@ describe('fileOperations', () => {
expect(edit.changes).toBeDefined();
expect(Object.keys(edit.changes!)).toHaveLength(1);
// module2 imports from renamed file
expect(edit.changes![uri('module2.ts')]).toEqual([
expect(edit.changes![uri('module2.ts')]).toStrictEqual([
{
range: {
start:{ line: 0, character: 25 },
Expand All @@ -2415,7 +2416,7 @@ describe('fileOperations', () => {
expect(edit.changes).toBeDefined();
expect(Object.keys(edit.changes!)).toHaveLength(1);
// module3 imports from renamed directory
expect(edit.changes![uri('module3.ts')]).toEqual([
expect(edit.changes![uri('module3.ts')]).toStrictEqual([
{
range: {
start:{ line: 0, character: 31 },
Expand Down
Loading