Skip to content

Commit

Permalink
feat: add vitest and setup codecov in the ci
Browse files Browse the repository at this point in the history
  • Loading branch information
rsaz committed Apr 27, 2024
1 parent 58dbb52 commit 14fd527
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 40 deletions.
52 changes: 26 additions & 26 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
/* eslint-env node */
module.exports = {
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"eslint-config-prettier",
"prettier"
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["./tsconfig.cjs.json"]
},
plugins: ["@typescript-eslint"],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ["dist", "node_modules", ".eslintrc.cjs"],
rules: {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": ["error", { default: "generic" }],
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-types": "error",
"@typescript-eslint/class-literal-property-style": "error",
"@typescript-eslint/explicit-function-return-type": "error",
},
}
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"eslint-config-prettier",
"prettier",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["./tsconfig.cjs.json", "./tsconfig.json"],
},
plugins: ["@typescript-eslint"],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ["dist", "node_modules", ".eslintrc.cjs", "**/__tests__/*.spec.ts"],
rules: {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": ["error", { default: "generic" }],
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-types": "error",
"@typescript-eslint/class-literal-property-style": "error",
"@typescript-eslint/explicit-function-return-type": "error",
},
};
32 changes: 21 additions & 11 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
name: Build
name: Build and Test

on:
push:
branches:
- main
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]
pull_request_target:
types: [opened, synchronize, reopened]
Expand All @@ -29,13 +28,24 @@ jobs:
- name: Build
run: npm run build

#- name: Unit Tests
# working-directory: .
# run: npm test
# env:
# CI: true
- name: Unit Tests
working-directory: ./src
run: npm run test
env:
CI: true

#- name: Set up .npmrc
# run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc
#- name: Install dependencies
# run: npm ci
- name: Run Code Coverage
working-directory: packages/core
run: npm run coverage

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
working-directory: ./src
token: ${{ secrets.CODECOV_TOKEN }}

- name: Set up .npmrc
run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.NPM_TOKEN }}" >> .npmrc

- name: Install dependencies
run: npm ci
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
"build:cjs": "tsc -p tsconfig.cjs.json",
"release": "release-it",
"prepublish": "npm run build && npm pack",
"test": "jest",
"publish": "npm publish --tag latest",
"test": "vitest run --reporter default",
"test:watch": "vitest run --watch",
"coverage": "vitest run --coverage",
"format": "prettier --write \"src/**/*.ts\" --cache",
"lint": "eslint \"src/**/*.ts\"",
"lint:fix": "eslint \"src/**/*.ts\" --fix"
Expand Down
7 changes: 7 additions & 0 deletions src/adapter-express/__tests__/application-express.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { describe, expect, it } from "vitest";

describe("application-express", () => {
it("should have tests", () => {
expect(true).toBe(true);
});
});
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"types": ["node", "reflect-metadata"]
"types": ["node", "reflect-metadata", "vitest/globals"]
},
"include": ["./src/**/*.ts"],
"exclude": ["node_modules"]
"exclude": ["node_modules", "**/__tests__/*.spec.ts", "scripts/**/*"]
}
41 changes: 41 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { defineConfig } from "vitest/config";
import { codecovVitePlugin } from "@codecov/vite-plugin";
import tsconfigPaths from "vite-tsconfig-paths";

/**
* @see {@link https://vitejs.dev/config/}
* @see {@link https://vitest.dev/config/}
*/
export default defineConfig({
plugins: [
tsconfigPaths(),
codecovVitePlugin({
enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined,
bundleName: "expresso-ts-adapter-express-coverage",
uploadToken: process.env.CODECOV_TOKEN,
}),
],
test: {
globals: true,
environment: "node",
setupFiles: ["reflect-metadata"],
exclude: ["**/node_modules/**", "**/test/**", "**/lib/**"],
coverage: {
all: true,
include: ["**/src/**"],
exclude: ["**/node_modules/**", "**/lib/**", "**/test/**", "**/index.ts/**"],
thresholds: {
global: {
statements: 85,
branches: 85,
functions: 85,
lines: 85,
},
},
reporter: ["text", "html", "json"],
provider: "v8",
},
// ref: https://vitest.dev/config/#testtimeout
testTimeout: 10000,
},
});

0 comments on commit 14fd527

Please sign in to comment.