Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(jest): add jest #2

Merged
merged 11 commits into from
Aug 8, 2024
27 changes: 27 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea
/node_modules
/build
/coverage
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
Binary file modified bun.lockb
Binary file not shown.
54 changes: 54 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -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: {
'^@/(.*)$': '<rootDir>/src/$1',
},
}

export default config
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
7 changes: 7 additions & 0 deletions src/add.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { add } from '@/add.ts'

describe('add', () => {
it('should add two numbers', () => {
expect(add(1, 2)).toBe(3)
})
})
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"moduleDetection": "force",
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"esModuleInterop": true,
"noEmit": true,
"strict": true,
"skipLibCheck": true,
Expand Down