Skip to content

Commit afd0211

Browse files
committed
Switch over to vitest because native ESM memes
1 parent 4399024 commit afd0211

7 files changed

Lines changed: 892 additions & 590 deletions

File tree

package.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,19 @@
4040
"require": "./build/index-cjs.js"
4141
},
4242
"devDependencies": {
43-
"@types/mocha": "^10.0.7",
4443
"@types/node": "^20.14.8",
45-
"c8": "^10.1.2",
46-
"c8-as-nyc": "^1.1.11",
47-
"call-spy": "^3.0.1",
44+
"@vitest/coverage-v8": "^3.2.4",
4845
"esbuild": "^0.25.0",
49-
"esbuild-register": "^3.5.0",
50-
"get-package-type": "^0.1.0",
51-
"mocha": "^10.4.0",
5246
"prettier": "^3.3.2",
53-
"typescript": "^5.5.2"
47+
"typescript": "^5.5.2",
48+
"vitest": "^3.2.4"
5449
},
5550
"scripts": {
5651
"prettier": "prettier --write \"**/*.{ts,md,json,js,cjs}\"",
5752
"build": "tsc && node build.mjs",
5853
"prepack": "yarn build",
59-
"test": "mocha --require esbuild-register --extension js,ts,cjs,mjs tests",
60-
"coverage": "c8 --reporter=lcov --reporter=text-summary --exclude=.yarn yarn test"
54+
"test": "vitest",
55+
"coverage": "vitest --coverage"
6156
},
6257
"prettier": {
6358
"semi": false,

tests/eq.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { test } from "../src"
1818
import assert from "assert"
19-
import { describe } from "mocha"
19+
import { describe } from "vitest"
2020

2121
const data = {
2222
Equality1: [
@@ -119,14 +119,14 @@ describe("$eq", () => {
119119
assert.strictEqual(test(sm, vars), true)
120120
})
121121

122-
context("inequality", () => {
122+
describe("inequality", () => {
123123
it("1 neq 2", () => {
124124
const [sm, vars] = data.Inequality1
125125
assert.strictEqual(test(sm, vars), false)
126126
})
127127
})
128128

129-
context("nested $eq", () => {
129+
describe("nested $eq", () => {
130130
it("can understand nested $eq", () => {
131131
const [sm, vars] = data.NestedEq1
132132
assert.strictEqual(test(sm, vars), true)
@@ -143,7 +143,7 @@ describe("$eq", () => {
143143
assert.strictEqual(test(sm, vars), true)
144144
})
145145

146-
context("$eq with undefined or null variables", () => {
146+
describe("$eq with undefined or null variables", () => {
147147
it("1 (one) undefined variable", () => {
148148
const [sm, vars] = data.UndefinedCheck1
149149
assert.strictEqual(test(sm, vars), false)

tests/or.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import { test } from "../src"
1818
import assert from "assert"
19-
import { describe } from "mocha"
2019

2120
const data = {
2221
Or1: [

tests/timers.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { test, Timer } from "../src"
1818
import assert from "assert"
19-
import callSpy from "call-spy"
19+
import { vi } from "vitest"
2020

2121
const data = {
2222
After1: [
@@ -43,7 +43,7 @@ describe("$after", () => {
4343
it("won't try to evaluate if no timestamp is specified", () => {
4444
const [sm, vars] = data.After1
4545

46-
const [logger, loggerCallDetails] = callSpy((category, message) => {
46+
const logger = vi.fn((category, message) => {
4747
if (category === "validation") {
4848
assert.strictEqual(
4949
message,
@@ -53,7 +53,7 @@ describe("$after", () => {
5353
})
5454

5555
assert.strictEqual(test(sm, vars, { timers: [], logger }), false)
56-
assert.strictEqual(loggerCallDetails.called, true)
56+
assert.strictEqual(logger.mock.calls.length > 1, true)
5757
})
5858

5959
it("supports basic timers", () => {

tsconfig.test.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"compilerOptions": {
44
"noEmit": true,
55
"emitDeclarationOnly": false,
6-
"rootDir": "."
6+
"rootDir": ".",
7+
"types": ["vitest/globals"]
78
},
8-
"include": ["tests", "tests/handleEvent.data.json", "src"]
9+
"include": ["tests", "tests/handleEvent.data.json", "src", "vite.config.ts"]
910
}

vite.config.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2025 The Peacock Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { defineConfig } from "vitest/config"
18+
19+
export default defineConfig({
20+
test: {
21+
globals: true,
22+
coverage: {
23+
provider: "v8",
24+
exclude: ["build", "build.mjs", ".yarn", "vite.config.ts"]
25+
}
26+
}
27+
})

0 commit comments

Comments
 (0)