Skip to content

Commit

Permalink
fix: use vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
ruicsh committed Mar 27, 2023
1 parent 465d58f commit caa9d40
Show file tree
Hide file tree
Showing 12 changed files with 976 additions and 1,893 deletions.
15 changes: 4 additions & 11 deletions .eslintrc → .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,22 @@
"airbnb-typescript/base",
"prettier",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript",
"plugin:jest/all"
"plugin:import/typescript"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"jest"
"@typescript-eslint"
],
"parserOptions": {
"ecmaVersion": 9,
"project": "./tsconfig.json"
},
"env": {
"node": true,
"jest": true
"node": true
},
"rules": {
"@typescript-eslint/comma-dangle": "off",
"import/prefer-default-export": "off",
"jest/no-conditional-in-test": "off",
"jest/no-hooks": "off",
"jest/no-identical-title": "off",
"jest/prefer-expect-assertions": "off"
"import/prefer-default-export": "off"
},
"overrides": [
{
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x, 19.x]
node-version: [14.x, 16.x, 18.x]
steps:
- uses: actions/checkout@main
with:
fetch-depth: "0"
- uses: actions/setup-node@main
with:
node-version: 19
node-version: 18
- uses: actions/cache@main
with:
path: node_modules
Expand All @@ -37,7 +37,7 @@ jobs:
fetch-depth: "0"
- uses: actions/setup-node@main
with:
node-version: 19
node-version: 18
- uses: actions/cache@main
with:
path: node_modules
Expand All @@ -59,7 +59,7 @@ jobs:
fetch-depth: "0"
- uses: actions/setup-node@main
with:
node-version: 19
node-version: 18
registry-url: https://registry.npmjs.org/
- run: |
yarn install --frozen-lockfile
Expand Down
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.15.0
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

7 changes: 0 additions & 7 deletions jest.config.json

This file was deleted.

50 changes: 24 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,49 @@
"Intl.NumberFormat"
],
"types": "dist/index.d.ts",
"module": "./dist/index.esm.js",
"main": "./dist/index.cjs.js",
"module": "./dist/index.mjs",
"main": "./dist/index.cjs",
"exports": {
".": [
{
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js",
"default": "./dist/index.esm.js"
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"default": "./dist/index.mjs"
},
"./dist/index.esm.js"
"./dist/index.mjs"
]
},
"files": [
"dist/index.esm.js",
"dist/index.cjs.js",
"dist/index.mjs",
"dist/index.cjs",
"dist/index.d.ts",
"dist/numberfmt.d.ts"
],
"devDependencies": {
"@types/jest": "29.2.5",
"@types/node": "18.11.18",
"@typescript-eslint/eslint-plugin": "5.48.0",
"@typescript-eslint/parser": "5.48.0",
"esbuild": "0.16.15",
"eslint": "8.31.0",
"@types/node": "18.15.10",
"@typescript-eslint/eslint-plugin": "5.56.0",
"@typescript-eslint/parser": "5.56.0",
"@vitest/coverage-c8": "0.29.7",
"esbuild": "0.17.14",
"eslint": "8.36.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-airbnb-typescript": "17.0.0",
"eslint-config-prettier": "8.6.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jest": "27.2.1",
"jest": "29.3.1",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-import": "2.27.5",
"nyc": "15.1.0",
"prettier": "2.8.2",
"ts-jest": "29.0.3",
"tsx": "3.12.1",
"typescript": "4.9.4",
"zx": "7.1.1"
"prettier": "2.8.7",
"tsx": "3.12.6",
"typescript": "5.0.2",
"vitest": "0.29.7",
"zx": "7.2.1"
},
"scripts": {
"build": "tsx sh/build.ts",
"coverage": "tsx sh/coverage.ts",
"format": "prettier --write src sh",
"lint:ts": "tsc --noEmit",
"lint": "eslint src --ext ts",
"test:ci": "LANG=en-GB jest --ci",
"test": "LANG=en-GB jest --watch"
"lint": "eslint src",
"test:ci": "LANG=en-GB vitest run",
"test": "LANG=en-GB vitest --watch"
}
}
15 changes: 4 additions & 11 deletions sh/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@ async function main() {
await $`rm -rf dist`;
await $`tsc --build tsconfig.build.json`;

const modes = ["cjs", "esm"];
for await (const mode of modes) {
const flags = [
"src/index.ts",
"--bundle",
`--format=${mode}`,
"--minify",
`--outfile=dist/index.${mode}.js`,
];
await $`esbuild ${flags}`;
}
const flags = ["--bundle", "--platform=node", "--minify"];

await $`esbuild src/cjs/index.cjs --outfile=dist/index.cjs ${flags}`;
await $`esbuild src/index.ts --format=esm --outfile=dist/index.mjs ${flags}`;

await $`rm dist/index.js`;
await $`rm -rf dist/formats dist/helpers dist/options`;
Expand Down
4 changes: 2 additions & 2 deletions sh/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ async function main() {
await $`rm -rf coverage/`;
await $`rm -rf .nyc_output/`;

await $`NODE_ENV=test LOG_LEVEL=silent nyc yarn test:ci \
--coverage true --coverageReporters lcov`;
const flags = ["--coverage true"].flatMap((f) => f.split(" "));
await $`NODE_ENV=test LOG_LEVEL=silent nyc yarn test:ci ${flags}`;
}

main();
3 changes: 3 additions & 0 deletions src/cjs/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import numberfmt from "../index";

module.exports = numberfmt;
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"baseUrl": "./",
"declaration": true,
"esModuleInterop": true,
"lib": [],
"lib": ["DOM"],
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./dist",
"removeComments": true,
"strict": true,
"target": "es6"
"target": "es6",
"types": ["vitest/globals"]
},
"include": ["src/**/*"],
"exclude": ["node_modules/**/*"]
Expand Down
16 changes: 16 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from "vitest/config";
import path from "node:path";

export default defineConfig({
test: {
globals: true,
coverage: {
reporter: ["lcov"],
},
},
resolve: {
alias: {
src: path.resolve(__dirname, "./src/"),
},
},
});
Loading

0 comments on commit caa9d40

Please sign in to comment.