Skip to content

Commit

Permalink
chore(server): introduce Jest (ts-jest)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenberkeley committed Nov 15, 2020
1 parent c0f4044 commit 37b0dfa
Show file tree
Hide file tree
Showing 4 changed files with 2,179 additions and 72 deletions.
21 changes: 21 additions & 0 deletions packages/server/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// This file is generated by `npx ts-jest config:init`, see https://github.com/kulshekhar/ts-jest/blob/102c829/README.md#getting-started
const fs = require('fs')
const path = require('path')
const stripJsonComments = require('strip-json-comments')
const { pathsToModuleNameMapper } = require('ts-jest/utils')

const tsconfig = JSON.parse(
stripJsonComments(
fs.readFileSync(path.join(__dirname, 'tsconfig.json'), 'utf-8'),
),
)

module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
// Doc: https://github.com/kulshekhar/ts-jest/blob/05916b9/docs/user/config/index.md#paths-mapping
moduleNameMapper: pathsToModuleNameMapper(tsconfig.compilerOptions.paths, {
prefix: '<rootDir>/',
}),
}
7 changes: 6 additions & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"lint:eslint": "eslint . --ext .js,.ts --quiet",
"lint:eslint:fix": "yarn run lint:eslint --fix",
"lint:typecheck": "tsc --noEmit",
"format": "prettier --write '**/*.{js,ts,json,md}'"
"format": "prettier --write '**/*.{js,ts,json,md}'",
"test": "jest"
},
"dependencies": {
"@mikro-orm/core": "^4.2.2",
Expand All @@ -27,6 +28,7 @@
"@mikro-orm/migrations": "^4.2.3",
"@types/dotenv-safe": "^8.1.1",
"@types/express": "^4.17.8",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.3",
"@typescript-eslint/eslint-plugin": "^4.5.0",
"@typescript-eslint/parser": "^4.5.0",
Expand All @@ -37,9 +39,12 @@
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-simple-import-sort": "^5.0.3",
"husky": "^4.3.0",
"jest": "^26.6.3",
"lint-staged": "^10.4.2",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.2",
"strip-json-comments": "^3.1.1",
"ts-jest": "^26.4.4",
"ts-node-dev": "^1.0.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.0.3"
Expand Down
4 changes: 2 additions & 2 deletions packages/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@

/* Module Resolution Options */
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
"baseUrl": "src" /* Base directory to resolve non-absolute module names. */,
"baseUrl": "." /* Base directory to resolve non-absolute module names. */,
"paths": {
/* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
"~/*": ["*"]
"~/*": ["./src/*"]
},
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
Expand Down
Loading

0 comments on commit 37b0dfa

Please sign in to comment.