Skip to content

Commit e4540ce

Browse files
committed
Format code w/ Biome and switch from tsx to tsimp for tests
1 parent be3a3df commit e4540ce

36 files changed

+853
-502
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ node_modules
22

33
.DS_Store
44

5+
/.tsimp
56
/@type
67
/lib
78
/coverage

ava.config.js

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,63 @@
1+
// @ts-check
2+
3+
/**
4+
* @typedef {Object} ParsedVersion
5+
*
6+
* @prop {number} major
7+
* @prop {number?} minor
8+
* @prop {number?} patch
9+
*/
10+
11+
/**
12+
* @return {ParsedVersion}
13+
*/
14+
function parseVersion() {
15+
const parsed = process.version.match(
16+
/^v(?<major>[0-9]+)(?:\.(?<minor>[0-9]+)?)(?:\.(?<patch>[0-9]+))?/
17+
)
18+
19+
if (parsed?.groups?.major == null) {
20+
throw new Error("Can't extract Node.js version form process.version")
21+
}
22+
23+
const major = Number.parseInt(parsed.groups.major, 10)
24+
const [minor, patch] = [parsed.groups.minor, parsed.groups.patch].map(
25+
value => (value ? Number.parseInt(value, 10) : null)
26+
)
27+
28+
return {major, minor, patch}
29+
}
30+
31+
/**
32+
* @returns {boolean}
33+
*/
34+
function isOlderThanTwentyDotSix() {
35+
const {major, minor} = parseVersion()
36+
37+
if (major > 20 || (major === 20 && minor && minor > 6)) {
38+
return false
39+
}
40+
41+
return true
42+
}
43+
44+
/**
45+
* @returns {string[]}
46+
*/
47+
const getTsimpArgs = () =>
48+
isOlderThanTwentyDotSix()
49+
? ["--loader", "tsimp/loader"]
50+
: ["--import", "tsimp"]
51+
152
export default {
53+
timeout: "5m",
254
failFast: true,
3-
workerThreads: false, // Disable to make tsx work
55+
workerThreads: isOlderThanTwentyDotSix() === false,
456
require: "global-jsdom/register",
5-
environmentVariables: {
6-
TS_NODE_PROJECT: "tsconfig.ava.json"
7-
},
857
extensions: {
958
ts: "module",
1059
tsx: "module"
1160
},
12-
files: [
13-
"src/**/*.test.{ts,tsx}"
14-
]
61+
nodeArguments: ["--no-warnings", ...getTsimpArgs()],
62+
files: ["src/**/*.test.{ts,tsx}"]
1563
}

biome.jsonc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
33
"linter": {
44
"rules": {
5-
"recommended": true
5+
"recommended": true,
6+
"complexity": {
7+
"noForEach": "off"
8+
},
9+
"suspicious": {
10+
"noExplicitAny": "off"
11+
}
612
}
713
},
814
"formatter": {
@@ -23,6 +29,6 @@
2329
},
2430
"files": {
2531
"include": ["**/*.ts", "**/*.tsx", "**/*.js"],
26-
"ignore": ["node_modules", ".tsimp", "coverage"]
32+
"ignore": ["node_modules", ".tsimp", "coverage", "lib"]
2733
}
2834
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
}
3535
},
3636
"scripts": {
37-
"test": "cross-env NODE_OPTIONS=\"--no-warnings --import tsx\" ava",
37+
"test": "ava",
3838
"coverage": "c8 pnpm test",
3939
"report": "c8 -r=html pnpm test",
4040
"ci": "c8 pnpm test && c8 report --reporter=json",
@@ -88,6 +88,7 @@
8888
"slate": "0.94.1",
8989
"slate-react": "0.97.1",
9090
"ts-expect": "1.3.0",
91+
"tsimp": "2.0.11",
9192
"tsup": "7.2.0",
9293
"tsx": "^4.7.1",
9394
"typescript": "5.1.6",

0 commit comments

Comments
 (0)