Skip to content

Commit ffe6e8a

Browse files
authored
change: migrate from mocha to vitest (#1914)
1 parent 787c45c commit ffe6e8a

8 files changed

Lines changed: 380 additions & 557 deletions

File tree

webui/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ This change log covers only the frontend library (webui) of Open VSX.
44

55
## [next] (unreleased)
66

7+
### Changed
8+
9+
- Migrate unit test framework from mocha to vitest
10+
711
### Dependencies
812

913
- Bump tar from `7.5.11` to `7.5.16` ([#1907](https://github.com/eclipse-openvsx/openvsx/pull/1907))

webui/configs/mocharc.json

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

webui/configs/test.tsconfig.json

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

webui/package.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,13 @@
7777
"@eslint/js": "^9.39.0",
7878
"@playwright/test": "^1.58.0",
7979
"@stylistic/eslint-plugin": "^5.9.0",
80-
"@types/chai": "^4.3.5",
8180
"@types/d3-scale": "^4.0",
8281
"@types/d3-shape": "^3.1",
8382
"@types/dompurify": "^3.0.2",
8483
"@types/express": "^4.17.21",
8584
"@types/lodash": "^4.14.195",
8685
"@types/luxon": "^3.7.1",
8786
"@types/markdown-it": "^14.1.0",
88-
"@types/mocha": "^10.0.0",
8987
"@types/node": "^22.0.0",
9088
"@types/prop-types": "^15.7.0",
9189
"@types/punycode": "^2.1.0",
@@ -97,24 +95,22 @@
9795
"@typescript-eslint/eslint-plugin": "^8.56.0",
9896
"@typescript-eslint/parser": "^8.56.0",
9997
"@vitejs/plugin-react": "^5.1.0",
100-
"chai": "^4.3.0",
10198
"eslint": "^9.39.0",
10299
"eslint-plugin-react": "^7.37.0",
103100
"eslint-plugin-react-refresh": "^0.5.2",
104101
"express": "^4.21.0",
105102
"express-rate-limit": "^7.4.0",
106-
"mocha": "^11.7.0",
107103
"rimraf": "^6.1.0",
108104
"rollup-plugin-visualizer": "^7.0.1",
109-
"ts-mocha": "^11.1.0",
110105
"ts-node": "^10.9.2",
111106
"typescript": "^5.9.0",
112-
"vite": "^7.3.0"
107+
"vite": "^7.3.0",
108+
"vitest": "^3.0.0"
113109
},
114110
"scripts": {
115111
"clean": "rimraf lib && rimraf dist",
116112
"build": "tsc -p ./configs/lib.tsconfig.json && yarn run lint",
117-
"test": "ts-mocha --project ./configs/test.tsconfig.json --config ./configs/mocharc.json",
113+
"test": "vitest run",
118114
"smoke-tests": "playwright install && playwright test --config=./configs/playwright.config.ts",
119115
"lint": "eslint -c eslint.config.mjs src",
120116
"watch": "tsc -w -p ./tsconfig.json --preserveWatchOutput",

webui/test/unit/utils.spec.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
* SPDX-License-Identifier: EPL-2.0
99
********************************************************************************/
1010

11-
import 'mocha';
12-
import { expect } from 'chai';
11+
import { describe, it, expect } from 'vitest';
1312
import { toRelativeTime } from '../../src/utils';
1413

1514
describe('toRelativeTime', () => {
@@ -20,32 +19,32 @@ describe('toRelativeTime', () => {
2019
const msPerYear = msPerDay * 365;
2120
it('should report "now" for seconds', () => {
2221
const now = Date.now();
23-
expect(toRelativeTime(new Date(now - 10000).toString())).to.equal('now');
24-
expect(toRelativeTime(new Date(now).toString())).to.equal('now');
22+
expect(toRelativeTime(new Date(now - 10000).toString())).toBe('now');
23+
expect(toRelativeTime(new Date(now).toString())).toBe('now');
2524
});
2625
it('should correctly report minutes', () => {
2726
const now = Date.now();
28-
expect(toRelativeTime(new Date(now - 10 * msPerMinute).toString())).to.equal('10 minutes ago');
29-
expect(toRelativeTime(new Date(now - msPerMinute).toString())).to.equal('1 minute ago');
27+
expect(toRelativeTime(new Date(now - 10 * msPerMinute).toString())).toBe('10 minutes ago');
28+
expect(toRelativeTime(new Date(now - msPerMinute).toString())).toBe('1 minute ago');
3029
});
3130
it('should correctly report hours', () => {
3231
const now = Date.now();
33-
expect(toRelativeTime(new Date(now - 10 * msPerHour).toString())).to.equal('10 hours ago');
34-
expect(toRelativeTime(new Date(now - msPerHour).toString())).to.equal('1 hour ago');
32+
expect(toRelativeTime(new Date(now - 10 * msPerHour).toString())).toBe('10 hours ago');
33+
expect(toRelativeTime(new Date(now - msPerHour).toString())).toBe('1 hour ago');
3534
});
3635
it('should correctly report days', () => {
3736
const now = Date.now();
38-
expect(toRelativeTime(new Date(now - 10 * msPerDay).toString())).to.equal('10 days ago');
39-
expect(toRelativeTime(new Date(now - msPerDay).toString())).to.equal('1 day ago');
37+
expect(toRelativeTime(new Date(now - 10 * msPerDay).toString())).toBe('10 days ago');
38+
expect(toRelativeTime(new Date(now - msPerDay).toString())).toBe('1 day ago');
4039
});
4140
it('should correctly report months', () => {
4241
const now = Date.now();
43-
expect(toRelativeTime(new Date(now - 10 * msPerMonth).toString())).to.equal('10 months ago');
44-
expect(toRelativeTime(new Date(now - msPerMonth).toString())).to.equal('1 month ago');
42+
expect(toRelativeTime(new Date(now - 10 * msPerMonth).toString())).toBe('10 months ago');
43+
expect(toRelativeTime(new Date(now - msPerMonth).toString())).toBe('1 month ago');
4544
});
4645
it('should correctly report years', () => {
4746
const now = Date.now();
48-
expect(toRelativeTime(new Date(now - 10 * msPerYear).toString())).to.equal('10 years ago');
49-
expect(toRelativeTime(new Date(now - msPerYear).toString())).to.equal('1 year ago');
47+
expect(toRelativeTime(new Date(now - 10 * msPerYear).toString())).toBe('10 years ago');
48+
expect(toRelativeTime(new Date(now - msPerYear).toString())).toBe('1 year ago');
5049
});
5150
});

webui/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"references": [
44
{ "path": "./configs/app.tsconfig.json" },
55
{ "path": "./configs/server.tsconfig.json" },
6-
{ "path": "./configs/node.tsconfig.json" },
7-
{ "path": "./configs/test.tsconfig.json" }
6+
{ "path": "./configs/node.tsconfig.json" }
87
]
98
}

webui/vite.config.mts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// <reference types="vitest/config" />
12
import path from 'node:path';
23
import react from '@vitejs/plugin-react';
34
import { defineConfig, PluginOption } from 'vite';
@@ -20,6 +21,10 @@ export default defineConfig(() => ({
2021
}
2122
},
2223
publicDir: 'static',
24+
test: {
25+
include: ['test/unit/**/*.spec.{ts,tsx}'],
26+
environment: 'node',
27+
},
2328
build: {
2429
target: 'es2020',
2530
minify: true,

0 commit comments

Comments
 (0)