Skip to content

Commit 04abbbf

Browse files
chore(ci): switch to vitest for testing (typescript-language-server#835)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 223a497 commit 04abbbf

15 files changed

+639
-2679
lines changed

.eslintrc.cjs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,17 @@ module.exports = {
124124
},
125125
},
126126
{
127-
files: ['**/*.spec.*'],
127+
files: ['**/*.test.*'],
128128
extends: [
129-
'plugin:jest/recommended',
130-
'plugin:jest/style',
129+
'plugin:vitest/all',
131130
],
132-
rules: {},
131+
rules: {
132+
'vitest/max-expects': 'off',
133+
'vitest/no-conditional-in-test': 'off',
134+
'vitest/no-conditional-tests': 'off',
135+
'vitest/no-hooks': 'off',
136+
'vitest/require-top-level-describe': 'off',
137+
},
133138
},
134139
],
135140
};
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: PR Conventional Commit Validation
1+
name: Conventional Commit Validation
22

33
on:
44
pull_request:
@@ -8,7 +8,7 @@ jobs:
88
validate-pr-title:
99
runs-on: ubuntu-latest
1010
steps:
11-
- name: PR Conventional Commit Validation
11+
- name: Conventional Commit Validation
1212
uses: ytanikin/[email protected]
1313
with:
1414
task_types: '["feat","fix","docs","test","ci","refactor","perf","chore","revert"]'

.vscode/launch.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"typescript.tsdk": "node_modules/typescript/lib",
33
"editor.codeActionsOnSave": {
4-
"source.fixAll.eslint": true
4+
"source.fixAll.eslint": "explicit"
55
},
66
}

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Maintained by a [community of contributors](https://github.com/typescript-langua
3131
- [TypeScript Version Notification](#typescript-version-notification)
3232
- [Development](#development)
3333
- [Build](#build)
34+
- [Dev](#dev)
3435
- [Test](#test)
35-
- [Watch](#watch)
3636
- [Publishing](#publishing)
3737

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

279279
```sh
280-
yarn
280+
yarn build
281281
```
282282

283-
### Test
284-
285-
- `yarn test` - run all tests
286-
- `yarn test:watch` - run all tests and enable watch mode for developing
283+
### Dev
287284

288-
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.
289-
290-
### Watch
285+
Build and rebuild on change.
291286

292287
```sh
293-
yarn watch
288+
yarn dev
294289
```
295290

291+
### Test
292+
293+
- `yarn test` - run all tests in watch mode for developing
294+
- `yarn test:commit` - run all tests once
295+
296+
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.
297+
296298
### Publishing
297299

298300
The project uses https://github.com/google-github-actions/release-please-action Github action to automatically release new version on merging a release PR.

jest.config.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

package.json

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
"typescript-language-server": "./lib/cli.mjs"
2020
},
2121
"scripts": {
22+
"dev": "rimraf lib && rollup --config rollup.config.ts --configPlugin typescript --watch",
23+
"build": "rimraf lib && rollup --config rollup.config.ts --configPlugin typescript",
2224
"clean": "rimraf lib *.tsbuildinfo",
23-
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules CONSOLE_LOG_LEVEL=warning jest",
24-
"test:watch": "cross-env NODE_OPTIONS=--experimental-vm-modules CONSOLE_LOG_LEVEL=warning jest --watch",
25+
"test": "cross-env CONSOLE_LOG_LEVEL=warning vitest",
26+
"test:commit": "cross-env CONSOLE_LOG_LEVEL=warning vitest run",
2527
"lint": "eslint --ext \".js,.ts\" src",
2628
"fix": "eslint --ext \".js,.ts\" --fix src",
27-
"build": "concurrently -n compile,lint -c blue,green \"yarn compile\" \"yarn lint\"",
28-
"compile": "rimraf lib && rollup --config rollup.config.ts --configPlugin typescript",
29-
"watch": "rimraf lib && rollup --config rollup.config.ts --configPlugin typescript --watch",
3029
"size": "yarn build && yarn size-limit",
3130
"postversion": "git push --follow-tags",
3231
"prepare": "cd test-data/jsx && yarn"
@@ -36,36 +35,30 @@
3635
],
3736
"husky": {
3837
"hooks": {
39-
"pre-commit": "yarn lint && yarn test && yarn build",
38+
"pre-commit": "concurrently -n build,lint,test \"yarn build\" \"yarn lint\" \"yarn test:commit\"",
4039
"post-merge": "yarn"
4140
}
4241
},
4342
"devDependencies": {
44-
"@babel/core": "^7.23.5",
45-
"@babel/preset-env": "^7.23.5",
4643
"@rollup/plugin-commonjs": "^25.0.7",
4744
"@rollup/plugin-node-resolve": "^15.2.3",
4845
"@rollup/plugin-terser": "^0.4.4",
4946
"@rollup/plugin-typescript": "^11.1.5",
5047
"@size-limit/file": "^11.0.1",
51-
"@types/deepmerge": "^2.2.0",
5248
"@types/fs-extra": "^11.0.4",
53-
"@types/jest": "^29.5.11",
5449
"@types/node": "^18.19.3",
5550
"@types/semver": "^7.5.6",
5651
"@types/which": "^3.0.3",
5752
"@typescript-eslint/eslint-plugin": "^6.13.2",
5853
"@typescript-eslint/parser": "^6.13.2",
59-
"babel-jest": "^29.7.0",
6054
"commander": "^11.1.0",
6155
"concurrently": "^8.2.2",
6256
"cross-env": "^7.0.3",
6357
"deepmerge": "^4.3.1",
6458
"eslint": "^8.55.0",
65-
"eslint-plugin-jest": "^27.6.0",
59+
"eslint-plugin-vitest": "^0.3.13",
6660
"fs-extra": "^11.2.0",
6761
"husky": "4.x",
68-
"jest": "^29.7.0",
6962
"p-debounce": "^4.0.0",
7063
"pkg-up": "^4.0.0",
7164
"rimraf": "^5.0.5",
@@ -74,10 +67,8 @@
7467
"size-limit": "^11.0.1",
7568
"source-map-support": "^0.5.21",
7669
"tempy": "^3.1.0",
77-
"ts-jest": "^29.1.1",
78-
"ts-node": "^10.9.2",
79-
"tslib": "^2.6.2",
8070
"typescript": "^5.3.3",
71+
"vitest": "^1.0.4",
8172
"vscode-jsonrpc": "^8.2.0",
8273
"vscode-languageserver": "^9.0.1",
8374
"vscode-languageserver-protocol": "^3.17.5",

src/features/call-hierarchy.spec.ts renamed to src/features/call-hierarchy.test.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
66
*/
77

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

@@ -47,25 +48,25 @@ function callsToString(item: CallHierarchyItemWithChildren, indentLevel: number,
4748
}
4849
}
4950

50-
beforeAll(async () => {
51-
server = await createServer({
52-
rootUri: uri(),
53-
publishDiagnostics: args => diagnostics.set(args.uri, args),
51+
describe('call hierarchy', () => {
52+
beforeAll(async () => {
53+
server = await createServer({
54+
rootUri: uri(),
55+
publishDiagnostics: args => diagnostics.set(args.uri, args),
56+
});
5457
});
55-
});
5658

57-
beforeEach(() => {
58-
server.closeAllForTesting();
59-
// "closeAllForTesting" triggers final publishDiagnostics with an empty list so clear last.
60-
diagnostics.clear();
61-
});
59+
beforeEach(() => {
60+
server.closeAllForTesting();
61+
// "closeAllForTesting" triggers final publishDiagnostics with an empty list so clear last.
62+
diagnostics.clear();
63+
});
6264

63-
afterAll(() => {
64-
server.closeAllForTesting();
65-
server.shutdown();
66-
});
65+
afterAll(() => {
66+
server.closeAllForTesting();
67+
server.shutdown();
68+
});
6769

68-
describe('call hierarchy', () => {
6970
const oneDoc = documentFromFile({ path: 'call-hierarchy/one.ts' });
7071
const twoDoc = documentFromFile({ path: 'call-hierarchy/two.ts' });
7172
const threeDoc = documentFromFile({ path: 'call-hierarchy/three.ts' });
@@ -90,7 +91,7 @@ describe('call hierarchy', () => {
9091
const incomingCalls = await getIncomingCalls(server, item);
9192
callsToString(incomingCalls, 0, lines);
9293
}
93-
expect(lines.join('\n')).toEqual(`
94+
expect(lines.join('\n')).toStrictEqual(`
9495
-|> tada (symbol: three.ts#2)
9596
-|> callThreeTwice (symbol: two.ts#3)
9697
-|> main (symbol: one.ts#2)
@@ -112,7 +113,7 @@ describe('call hierarchy', () => {
112113
const outgoingCalls = await getOutgoingCalls(server, item);
113114
callsToString(outgoingCalls, 0, lines);
114115
}
115-
expect(lines.join('\n')).toEqual(`
116+
expect(lines.join('\n')).toStrictEqual(`
116117
-|> callThreeTwice (symbol: two.ts#3)
117118
-|> tada (symbol: three.ts#2)
118119
-|> print (symbol: three.ts#6)

src/file-lsp-server.spec.ts renamed to src/file-lsp-server.test.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,28 @@
55
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
66
*/
77

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

1011
let server: TestLspServer;
1112

12-
beforeAll(async () => {
13-
server = await createServer({
14-
rootUri: uri(),
15-
publishDiagnostics: () => { },
13+
describe('documentHighlight', () => {
14+
beforeAll(async () => {
15+
server = await createServer({
16+
rootUri: uri(),
17+
publishDiagnostics: () => { },
18+
});
1619
});
17-
});
1820

19-
beforeEach(() => {
20-
server.closeAllForTesting();
21-
});
21+
beforeEach(() => {
22+
server.closeAllForTesting();
23+
});
2224

23-
afterAll(() => {
24-
server.closeAllForTesting();
25-
server.shutdown();
26-
});
25+
afterAll(() => {
26+
server.closeAllForTesting();
27+
server.shutdown();
28+
});
2729

28-
describe('documentHighlight', () => {
2930
it('simple test', async () => {
3031
const doc = {
3132
uri: uri('module2.ts'),
@@ -43,6 +44,22 @@ describe('documentHighlight', () => {
4344
});
4445

4546
describe('completions', () => {
47+
beforeAll(async () => {
48+
server = await createServer({
49+
rootUri: uri(),
50+
publishDiagnostics: () => { },
51+
});
52+
});
53+
54+
beforeEach(() => {
55+
server.closeAllForTesting();
56+
});
57+
58+
afterAll(() => {
59+
server.closeAllForTesting();
60+
server.shutdown();
61+
});
62+
4663
it('receives completion that auto-imports from another module', async () => {
4764
const doc = {
4865
uri: uri('completion.ts'),

src/lsp-server.spec.ts renamed to src/lsp-server.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
66
*/
77

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

94-
expect(containsInvalidCompletions).toBe(false);
95+
expect(containsInvalidCompletions).toBeFalsy();
9596
});
9697

9798
it('deprecated by JSDoc', async () => {
@@ -277,7 +278,7 @@ describe('completion', () => {
277278
expect(proposals).not.toBeNull();
278279
const completion = proposals!.items.find(completion => completion.label === 'readFile');
279280
expect(completion).toBeDefined();
280-
expect(completion).toEqual(expect.objectContaining({
281+
expect(completion).toStrictEqual(expect.objectContaining({
281282
label: 'readFile',
282283
kind: lsp.CompletionItemKind.Function,
283284
insertTextFormat: lsp.InsertTextFormat.Snippet,
@@ -838,10 +839,10 @@ describe('diagnostics', () => {
838839
expect(fileDiagnostics).toHaveLength(2);
839840
const unusedDiagnostic = fileDiagnostics.find(d => d.code === 6133);
840841
expect(unusedDiagnostic).toBeDefined();
841-
expect(unusedDiagnostic!.tags).toEqual([lsp.DiagnosticTag.Unnecessary]);
842+
expect(unusedDiagnostic!.tags).toStrictEqual([lsp.DiagnosticTag.Unnecessary]);
842843
const deprecatedDiagnostic = fileDiagnostics.find(d => d.code === 6387);
843844
expect(deprecatedDiagnostic).toBeDefined();
844-
expect(deprecatedDiagnostic!.tags).toEqual([lsp.DiagnosticTag.Deprecated]);
845+
expect(deprecatedDiagnostic!.tags).toStrictEqual([lsp.DiagnosticTag.Deprecated]);
845846
});
846847

847848
it('multiple files test', async () => {
@@ -1482,7 +1483,7 @@ describe('code actions', () => {
14821483
},
14831484
}))!;
14841485

1485-
expect(result).toEqual([]);
1486+
expect(result).toStrictEqual([]);
14861487
});
14871488

14881489
it('provides organize imports when there are no errors', async () => {
@@ -2396,7 +2397,7 @@ describe('fileOperations', () => {
23962397
expect(edit.changes).toBeDefined();
23972398
expect(Object.keys(edit.changes!)).toHaveLength(1);
23982399
// module2 imports from renamed file
2399-
expect(edit.changes![uri('module2.ts')]).toEqual([
2400+
expect(edit.changes![uri('module2.ts')]).toStrictEqual([
24002401
{
24012402
range: {
24022403
start:{ line: 0, character: 25 },
@@ -2415,7 +2416,7 @@ describe('fileOperations', () => {
24152416
expect(edit.changes).toBeDefined();
24162417
expect(Object.keys(edit.changes!)).toHaveLength(1);
24172418
// module3 imports from renamed directory
2418-
expect(edit.changes![uri('module3.ts')]).toEqual([
2419+
expect(edit.changes![uri('module3.ts')]).toStrictEqual([
24192420
{
24202421
range: {
24212422
start:{ line: 0, character: 31 },

0 commit comments

Comments
 (0)