Skip to content

Commit

Permalink
Format code w/ Biome and switch from tsx to tsimp for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
octet-stream committed Jul 25, 2024
1 parent be3a3df commit e4540ce
Show file tree
Hide file tree
Showing 36 changed files with 853 additions and 502 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules

.DS_Store

/.tsimp
/@type
/lib
/coverage
Expand Down
62 changes: 55 additions & 7 deletions ava.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,63 @@
// @ts-check

/**
* @typedef {Object} ParsedVersion
*
* @prop {number} major
* @prop {number?} minor
* @prop {number?} patch
*/

/**
* @return {ParsedVersion}
*/
function parseVersion() {
const parsed = process.version.match(
/^v(?<major>[0-9]+)(?:\.(?<minor>[0-9]+)?)(?:\.(?<patch>[0-9]+))?/
)

if (parsed?.groups?.major == null) {
throw new Error("Can't extract Node.js version form process.version")
}

const major = Number.parseInt(parsed.groups.major, 10)
const [minor, patch] = [parsed.groups.minor, parsed.groups.patch].map(
value => (value ? Number.parseInt(value, 10) : null)
)

return {major, minor, patch}
}

/**
* @returns {boolean}
*/
function isOlderThanTwentyDotSix() {
const {major, minor} = parseVersion()

if (major > 20 || (major === 20 && minor && minor > 6)) {
return false
}

return true
}

/**
* @returns {string[]}
*/
const getTsimpArgs = () =>
isOlderThanTwentyDotSix()
? ["--loader", "tsimp/loader"]
: ["--import", "tsimp"]

export default {
timeout: "5m",
failFast: true,
workerThreads: false, // Disable to make tsx work
workerThreads: isOlderThanTwentyDotSix() === false,
require: "global-jsdom/register",
environmentVariables: {
TS_NODE_PROJECT: "tsconfig.ava.json"
},
extensions: {
ts: "module",
tsx: "module"
},
files: [
"src/**/*.test.{ts,tsx}"
]
nodeArguments: ["--no-warnings", ...getTsimpArgs()],
files: ["src/**/*.test.{ts,tsx}"]
}
10 changes: 8 additions & 2 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"linter": {
"rules": {
"recommended": true
"recommended": true,
"complexity": {
"noForEach": "off"
},
"suspicious": {
"noExplicitAny": "off"
}
}
},
"formatter": {
Expand All @@ -23,6 +29,6 @@
},
"files": {
"include": ["**/*.ts", "**/*.tsx", "**/*.js"],
"ignore": ["node_modules", ".tsimp", "coverage"]
"ignore": ["node_modules", ".tsimp", "coverage", "lib"]
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
},
"scripts": {
"test": "cross-env NODE_OPTIONS=\"--no-warnings --import tsx\" ava",
"test": "ava",
"coverage": "c8 pnpm test",
"report": "c8 -r=html pnpm test",
"ci": "c8 pnpm test && c8 report --reporter=json",
Expand Down Expand Up @@ -88,6 +88,7 @@
"slate": "0.94.1",
"slate-react": "0.97.1",
"ts-expect": "1.3.0",
"tsimp": "2.0.11",
"tsup": "7.2.0",
"tsx": "^4.7.1",
"typescript": "5.1.6",
Expand Down
Loading

0 comments on commit e4540ce

Please sign in to comment.