Skip to content

Commit ca934c8

Browse files
committed
add jest
1 parent 4c58a7a commit ca934c8

File tree

3 files changed

+2169
-20
lines changed

3 files changed

+2169
-20
lines changed

package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"scripts": {
1111
"prepublish": "npm run build",
1212
"build": "rm -rf dist && tsc",
13-
"test": "npm run lint",
13+
"pretest": "npm run lint",
14+
"test": "jest",
1415
"lint": "tslint -c tslint.json 'src/**/*.ts'"
1516
},
1617
"repository": {
@@ -25,13 +26,27 @@
2526
],
2627
"devDependencies": {
2728
"@types/fs-extra": "2.0.0",
29+
"@types/jest": "^19.2.4",
2830
"@types/lodash": "^4.14.62",
31+
"jest": "^20.0.4",
32+
"ts-jest": "^20.0.6",
2933
"tslint": "^5.1.0"
3034
},
3135
"dependencies": {
3236
"fs-p": "2.0.0",
3337
"globby": "^6.1.0",
3438
"lodash": "^4.17.4",
3539
"typescript": "^2.2.2"
40+
},
41+
"jest": {
42+
"transform": {
43+
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
44+
},
45+
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
46+
"moduleFileExtensions": [
47+
"ts",
48+
"tsx",
49+
"js"
50+
]
3651
}
3752
}

tests/typescript.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import {extractFileNames} from '../src/typescript'
2+
import {ServerlessFunction} from '../src/types'
3+
4+
const functions: { [key: string]: ServerlessFunction } = {
5+
hello: {
6+
handler: 'my-folder/hello.handler',
7+
package: {
8+
include: [],
9+
exclude: []
10+
}
11+
},
12+
world: {
13+
handler: 'my-folder/my-subfolder/world.handler',
14+
package: {
15+
include: [],
16+
exclude: []
17+
}
18+
},
19+
create: {
20+
handler: 'create.create',
21+
package: {
22+
include: [],
23+
exclude: []
24+
}
25+
},
26+
}
27+
28+
describe('extractFileName', () => {
29+
it('get function filenames from serverless service', () => {
30+
expect(
31+
extractFileNames(functions),
32+
).toEqual(
33+
[
34+
'my-folder/hello.ts',
35+
'my-folder/my-subfolder/world.ts',
36+
'create.ts',
37+
],
38+
)
39+
})
40+
})
41+

0 commit comments

Comments
 (0)