diff --git a/server/jest.config.js b/server/jest.config.js new file mode 100644 index 0000000..4f0f1e2 --- /dev/null +++ b/server/jest.config.js @@ -0,0 +1,21 @@ +module.exports = { + "verbose": true, + "globals": { + "ts-jest": { + "useBabelrc": true, + "tsConfigFile": "tsconfig.jest.json" + } + }, + "transform": { + "\\.ts": "ts-jest" + }, + "testRegex": "(\\.|/)([jt]est)\\.[jt]s$", + "moduleFileExtensions": [ + "ts", + "js", + "json" + ], + "setupFiles": [ + "/spec/setup_tests.ts" + ] +}; diff --git a/server/package.json b/server/package.json index fae059a..4b2b60c 100644 --- a/server/package.json +++ b/server/package.json @@ -6,7 +6,8 @@ "start": "node dist/server.js", "dev": "NODE_ENV=development node build/dev-server.js", "build-prod": "npm rebuild zeromq && webpack --config build/webpack.prod.conf.js", - "build": "npm run build-prod && webpack --config build/webpack.614.prod.conf.js" + "build": "npm run build-prod && webpack --config build/webpack.614.prod.conf.js", + "test": "jest --config jest.config.js" }, "repository": { "type": "git", @@ -21,6 +22,7 @@ "dependencies": {}, "devDependencies": { "@types/es6-promisify": "^6.0.0", + "@types/jest": "^23.1.1", "@types/koa": "^2.0.45", "@types/koa-bodyparser": "^4.2.0", "@types/koa-router": "^7.0.28", @@ -28,6 +30,7 @@ "@types/nedb": "^1.8.0", "axios": "^0.18.0", "babel-core": "^6.26.3", + "babel-jest": "^23.4.2", "babel-loader": "^7.1.4", "babel-polyfill": "^6.26.0", "babel-preset-env": "^1.7.0", @@ -35,6 +38,7 @@ "es6-promise": "^4.2.4", "event-stream": "^3.3.4", "file-loader": "^1.1.11", + "jest": "^23.1.1", "koa": "^2.5.1", "koa-bodyparser": "^4.2.1", "koa-router": "^7.4.0", @@ -43,6 +47,7 @@ "node-loader": "^0.6.0", "nodemon": "^1.17.5", "ts-loader": "^4.4.1", + "ts-jest": "^23.1.1", "typescript": "^2.8.3", "webpack": "^4.12.0", "webpack-cli": "^3.0.8", diff --git a/server/spec/basic.jest.ts b/server/spec/basic.jest.ts new file mode 100644 index 0000000..1934d5c --- /dev/null +++ b/server/spec/basic.jest.ts @@ -0,0 +1,7 @@ +describe("Basic test", function() { + let text = "I am a basic test"; + + it("should work", function() { + expect(text).toBe("I am a basic test"); + }) +}) diff --git a/server/spec/config.jest.ts b/server/spec/config.jest.ts new file mode 100644 index 0000000..f68728b --- /dev/null +++ b/server/spec/config.jest.ts @@ -0,0 +1,8 @@ +import { HASTIC_PORT } from '../src/config'; + +describe("When importing from .ts files", function() { + + it("should work", function() { + expect(HASTIC_PORT).toBe(8000) + }) +}) diff --git a/server/spec/setup_tests.ts b/server/spec/setup_tests.ts new file mode 100644 index 0000000..89d2823 --- /dev/null +++ b/server/spec/setup_tests.ts @@ -0,0 +1,2 @@ +console.log = jest.fn(); +console.error = jest.fn(); diff --git a/server/tsconfig.jest.json b/server/tsconfig.jest.json new file mode 100644 index 0000000..1c66acf --- /dev/null +++ b/server/tsconfig.jest.json @@ -0,0 +1,3 @@ +{ + "extends": "./tsconfig" +}