diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..619431a --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,27 @@ +name: Tests + +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: ~ + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js and Bun + uses: oven-sh/setup-bun@v2 + + - name: Install dependencies + run: bun install + + - name: Run tests + run: bun run test diff --git a/.gitignore b/.gitignore index 42d43cc..5c8c55e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.idea /node_modules /build +/coverage diff --git a/README.md b/README.md index f322d1b..0949753 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Template Node [![Build Workflow](https://github.com/jdevelop-io/template-node/actions/workflows/build.yml/badge.svg)](https://github.com/jdevelop-io/template-node/actions/workflows/build.yml) +[![Tests Workflow](https://github.com/jdevelop-io/template-node/actions/workflows/tests.yml/badge.svg)](https://github.com/jdevelop-io/template-node/actions/workflows/tests.yml) [![License](https://img.shields.io/github/license/jdevelop-io/template-node)](/LICENSE) [![WakaTime](https://wakatime.com/badge/user/b5dd94a4-c0ea-4c12-9cb2-41f984e74fdc/project/e774c158-4cbd-4a4e-a265-1c08e6e84c3d.svg)](https://wakatime.com/badge/user/b5dd94a4-c0ea-4c12-9cb2-41f984e74fdc/project/e774c158-4cbd-4a4e-a265-1c08e6e84c3d) diff --git a/bun.lockb b/bun.lockb index b22a0a9..39da5ae 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/jest.config.ts b/jest.config.ts new file mode 100644 index 0000000..f95b01e --- /dev/null +++ b/jest.config.ts @@ -0,0 +1,54 @@ +/** + * For a detailed explanation regarding each configuration property, visit: + * https://jestjs.io/docs/configuration + */ + +import type { Config } from 'jest' + +const config: Config = { + preset: 'ts-jest', + + // Automatically clear mock calls, instances, contexts and results before every test + clearMocks: true, + + // Indicates whether the coverage information should be collected while executing the test + collectCoverage: false, + + // The directory where Jest should output its coverage files + coverageDirectory: 'coverage', + + // An array of glob patterns indicating a set of files for which coverage information should be collected + collectCoverageFrom: ['**/*.ts', '!jest.config.ts'], + + // An array of regexp pattern strings used to skip coverage collection + coveragePathIgnorePatterns: ['/node_modules/', '/coverage/', '/dist/'], + + // Indicates which provider should be used to instrument code for coverage + coverageProvider: 'babel', + + // A list of reporter names that Jest uses when writing coverage reports + coverageReporters: ['json', 'text', 'lcov', 'clover'], + + // An object that configures minimum threshold enforcement for coverage results + coverageThreshold: { + global: { + branches: 100, + functions: 100, + lines: 100, + statements: 100, + }, + }, + + // Make calling deprecated APIs throw helpful error messages + errorOnDeprecated: true, + + // An array of directory names to be searched recursively up from the requiring module's location + moduleDirectories: ['node_modules'], + + // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module + moduleNameMapper: { + '^@/(.*)$': '/src/$1', + }, +} + +export default config diff --git a/package.json b/package.json index c07a99a..9b89991 100644 --- a/package.json +++ b/package.json @@ -15,11 +15,19 @@ "main": "src/add.ts", "scripts": { "prebuild": "rimraf build", - "build": "bun build src/add.ts --outdir ./build" + "build": "bun build src/add.ts --outdir ./build", + "test": "jest", + "test:watch": "jest --watch", + "test:coverage": "jest --coverage", + "test:coverage:watch": "jest --coverage --watch" }, "devDependencies": { "@types/bun": "^1.1.6", + "@types/jest": "^29.5.12", + "jest": "^29.7.0", "rimraf": "^6.0.1", + "ts-jest": "^29.2.4", + "ts-node": "^10.9.2", "typescript": "^5.5.4" } } diff --git a/src/add.test.ts b/src/add.test.ts new file mode 100644 index 0000000..e298e31 --- /dev/null +++ b/src/add.test.ts @@ -0,0 +1,7 @@ +import { add } from '@/add.ts' + +describe('add', () => { + it('should add two numbers', () => { + expect(add(1, 2)).toBe(3) + }) +}) diff --git a/tsconfig.json b/tsconfig.json index 4d4bc96..2e0b2e9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,7 +14,7 @@ "moduleDetection": "force", "moduleResolution": "bundler", "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, + "esModuleInterop": true, "noEmit": true, "strict": true, "skipLibCheck": true,