Configure Jest Testing Framework for Typescript (#2519)

* Set JEST for Typescript testing

* tests
This commit is contained in:
David Bomba 2018-11-26 10:28:22 +11:00 committed by GitHub
parent fa83ce10a3
commit 6a390aedbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 4 deletions

17
jest.config.js vendored Normal file
View File

@ -0,0 +1,17 @@
module.exports = {
"roots": [
"resources/js/src"
],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
}

View File

@ -7,18 +7,21 @@
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"test": "jest"
},
"devDependencies": {
"@coreui/coreui": "^2.0.12",
"@coreui/coreui-plugin-chartjs-custom-tooltips": "1.2.0",
"@coreui/icons": "^0.3.0",
"@types/jest": "^23.3.9",
"axios": "^0.18",
"bootstrap": "^4.0.0",
"chart.js": "^2.7.2",
"cross-env": "^5.1",
"flag-icon-css": "3.2.0",
"font-awesome": "^4.7",
"jest": "^23.6.0",
"jquery": "^3.2",
"laravel-mix": "^2.0",
"lodash": "^4.17.5",
@ -26,9 +29,11 @@
"perfect-scrollbar": "1.4.0",
"popper.js": "^1.12",
"simple-line-icons": "2.4.1",
"ts-jest": "^23.10.5",
"vue": "^2.5.17"
},
"dependencies": {
"@types/node": "^10.12.10",
"hashids": "^1.2.2",
"laravel-echo": "^1.4.0",
"quill": "^1.3.6",

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,3 @@
export function sum(x: number, y: number): number {
return x + y;
}

View File

@ -0,0 +1,13 @@
import { sum } from "./math";
describe("This is a simple test", () => {
test("Check the sum of 0 + 0", () => {
expect(sum(0,0)).toBe(0);
});
});
describe("This is a simple test", () => {
test("Check the sum of 1 + 2", () => {
expect(sum(1, 2)).toBe(3);
});
});

View File

@ -57,6 +57,6 @@
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"include": [
"resources/js/ts/**/*"
"resources/js/src/**/*"
]
}

2
webpack.mix.js vendored
View File

@ -25,7 +25,7 @@ mix.webpackConfig({
}
});
mix.js('resources/js/ts/client/client_edit.ts', 'public/js');
mix.js('resources/js/src/client/client_edit.ts', 'public/js');
mix.js('resources/js/app.js', 'public/js/vendor');