Skip to content
This repository was archived by the owner on Jan 20, 2020. It is now read-only.

Commit 3865bc8

Browse files
author
Luciano Nooijen
committed
Added Typescript support in Jest
1 parent 07904ca commit 3865bc8

File tree

12 files changed

+231
-30
lines changed

12 files changed

+231
-30
lines changed

jest.config.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ module.exports = {
6363
// ],
6464

6565
// An array of file extensions your modules use
66-
// moduleFileExtensions: [
67-
// "js",
68-
// "json",
69-
// "jsx",
70-
// "node"
71-
// ],
72-
66+
moduleFileExtensions: [
67+
"ts",
68+
"tsx",
69+
"js",
70+
"jsx",
71+
"json",
72+
"node"
73+
],
7374
// A map from regular expressions to module names that allow to stub out resources with a single module
7475
// moduleNameMapper: {},
7576

@@ -144,7 +145,7 @@ module.exports = {
144145
// ],
145146

146147
// The regexp pattern Jest uses to detect test files
147-
// testRegex: "",
148+
testRegex: "tests\/(.*).(test|spec).ts?",
148149

149150
// This option allows the use of a custom results processor
150151
// testResultsProcessor: null,
@@ -159,7 +160,9 @@ module.exports = {
159160
// timers: "real",
160161

161162
// A map from regular expressions to paths to transformers
162-
// transform: null,
163+
transform: {
164+
"^.+\\.tsx?$": "ts-jest"
165+
},
163166

164167
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
165168
// transformIgnorePatterns: [

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"node": ">=8.0.0"
2626
},
2727
"scripts": {
28-
"dev": "nodemon server/server.js",
28+
"dev": "ts-node server/server.ts",
2929
"start": "node server/server.js",
3030
"lint": "eslint --ext .jsx,.js,.ts .",
3131
"test": "NODE_ENV=test jest -i",
@@ -44,9 +44,16 @@
4444
"morgan": "^1.9.1",
4545
"pg": "^7.6.0",
4646
"sqreen": "^1.26.2",
47+
"ts-node": "^7.0.1",
48+
"typescript": "^3.1.6",
4749
"yarn": "^1.12.1"
4850
},
4951
"devDependencies": {
52+
"@types/eslint": "^4.16.4",
53+
"@types/express": "^4.16.0",
54+
"@types/jest": "^23.3.9",
55+
"@types/knex": "^0.15.1",
56+
"@types/node": "^10.12.9",
5057
"babel-eslint": "^10.0.1",
5158
"eslint": "^4.19.1",
5259
"eslint-config-airbnb": "^16.1.0",
@@ -64,7 +71,9 @@
6471
"prettierrc": "^0.0.0-5",
6572
"response-time": "^2.3.2",
6673
"sqlite3": "^4.0.3",
67-
"supertest": "^3.3.0"
74+
"supertest": "^3.3.0",
75+
"ts-jest": "^23.10.4",
76+
"typescript-eslint-parser": "^21.0.1"
6877
},
6978
"env": {
7079
"params": {
File renamed without changes.

tests/app.test.js renamed to tests/app.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import useTestDatabase from './config/database-config';
12
const { knex } = require('../helpers');
2-
const { useTestDatabase } = require('./config');
33

44
useTestDatabase();
55

tests/config/database-config.js renamed to tests/config/database-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ const useTestDatabase = () => {
1414
afterAll(() => knex.destroy());
1515
};
1616

17-
module.exports = useTestDatabase;
17+
export default useTestDatabase;

tests/config/index.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/config/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import useTestDatabase from './database-config';
2+
import useEnvVars from './database-config';
3+
4+
export default {
5+
useTestDatabase,
6+
useEnvVars,
7+
};
8+

tests/config/load-env-file.js renamed to tests/config/load-env-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ const useEnvVars = () => {
2929
}));
3030
};
3131

32-
module.exports = useEnvVars;
32+
export default useEnvVars;

tests/database/authors.test.js renamed to tests/database/authors.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { useTestDatabase } = require('../config');
1+
import useTestDatabase from "../config/database-config";
22
const {
33
listAuthors,
44
getAuthor,

tests/database/users.test.js renamed to tests/database/users.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { useTestDatabase } = require('../config');
1+
import useTestDatabase from '../config/database-config';
22
const {
33
listUsers,
44
getUser,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy