Skip to content

Commit 1fdea71

Browse files
authored
Merge pull request #717 from huafu/better-coverage
[beta] Improving coverage
2 parents a4acc22 + c2102ea commit 1fdea71

13 files changed

Lines changed: 693 additions & 590 deletions

package-lock.json

Lines changed: 94 additions & 442 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -58,55 +58,54 @@
5858
},
5959
"homepage": "https://kulshekhar.github.io/ts-jest",
6060
"dependencies": {
61-
"bs-logger": "^0.2.5",
62-
"buffer-from": "^1.1.1",
63-
"fast-json-stable-stringify": "^2.0.0",
64-
"json5": "^2.0.1",
65-
"make-error": "^1.3.5",
66-
"mkdirp": "^0.5.1",
67-
"semver": "^5.5.1",
68-
"yargs-parser": "^10.1.0"
61+
"bs-logger": "0.x",
62+
"buffer-from": "1.x",
63+
"fast-json-stable-stringify": "2.x",
64+
"json5": "2.x",
65+
"make-error": "1.x",
66+
"mkdirp": "0.x",
67+
"semver": "5.x",
68+
"yargs-parser": "10.x"
6969
},
7070
"peerDependencies": {
7171
"jest": ">=22 <24"
7272
},
7373
"devDependencies": {
74-
"@commitlint/cli": "^7.1.2",
75-
"@commitlint/config-conventional": "^7.1.2",
76-
"@types/babel__core": "^7.0.1",
77-
"@types/buffer-from": "^1.1.0",
78-
"@types/cross-spawn": "^6.0.0",
79-
"@types/fs-extra": "5.0.4",
80-
"@types/jest": "^23.3.2",
81-
"@types/js-yaml": "^3.11.2",
82-
"@types/json5": "^0.0.30",
83-
"@types/lodash.memoize": "^4.1.4",
84-
"@types/lodash.merge": "^4.6.4",
85-
"@types/lodash.set": "^4.3.4",
86-
"@types/mkdirp": "^0.5.2",
87-
"@types/node": "^10.9.4",
88-
"@types/semver": "^5.5.0",
89-
"@types/yargs": "^11.1.1",
90-
"conventional-changelog-cli": "^2.0.5",
91-
"cross-spawn": "^6.0.5",
92-
"doctoc": "^1.3.1",
93-
"eslint": "^5.5.0",
94-
"fs-extra": "^7.0.0",
95-
"glob-gitignore": "^1.0.9",
96-
"husky": "^0.14.3",
97-
"jest": "^23.6.0",
98-
"js-yaml": "^3.12.0",
99-
"lint-staged": "^7.2.2",
100-
"lodash.memoize": "^4.1.2",
101-
"lodash.merge": "^4.6.1",
102-
"lodash.set": "^4.3.2",
103-
"npm-run-all": "^4.1.3",
104-
"prettier": "^1.14.2",
105-
"source-map": "^0.7.3",
106-
"tslint": "^5.11.0",
107-
"tslint-config-prettier": "^1.15.0",
108-
"tslint-plugin-prettier": "^1.3.0",
109-
"typescript": "^3.0.3"
74+
"@commitlint/cli": "7.x",
75+
"@commitlint/config-conventional": "7.x",
76+
"@types/babel__core": "7.x",
77+
"@types/buffer-from": "*",
78+
"@types/cross-spawn": "*",
79+
"@types/fs-extra": "*",
80+
"@types/jest": "23.x",
81+
"@types/js-yaml": "*",
82+
"@types/json5": "*",
83+
"@types/lodash.memoize": "4.x",
84+
"@types/lodash.merge": "4.x",
85+
"@types/lodash.set": "4.x",
86+
"@types/mkdirp": "*",
87+
"@types/node": "10.x",
88+
"@types/semver": "*",
89+
"@types/yargs": "*",
90+
"conventional-changelog-cli": "2.x",
91+
"cross-spawn": "*",
92+
"eslint": "*",
93+
"fs-extra": "*",
94+
"glob-gitignore": "*",
95+
"husky": "*",
96+
"jest": "23.x",
97+
"js-yaml": "*",
98+
"lint-staged": "*",
99+
"lodash.memoize": "4.x",
100+
"lodash.merge": "4.x",
101+
"lodash.set": "4.x",
102+
"npm-run-all": "*",
103+
"prettier": "*",
104+
"source-map": "*",
105+
"tslint": "*",
106+
"tslint-config-prettier": "*",
107+
"tslint-plugin-prettier": "*",
108+
"typescript": "3.x"
110109
},
111110
"lint-staged": {
112111
"linters": {

src/__helpers__/mocks.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,40 @@ export function spied<T>(val: T): T extends (...args: any[]) => any ? jest.SpyIn
1111
}
1212

1313
export const logTargetMock = () => (rootLogger as testing.LoggerMock).target
14+
15+
export const mockObject = <T, M>(obj: T, newProps: M): T & M & { mockRestore: () => T } => {
16+
const backup: any = Object.create(null)
17+
18+
Object.keys(newProps).forEach(key => {
19+
const desc = (backup[key] = Object.getOwnPropertyDescriptor(obj, key))
20+
const newDesc: any = { ...desc }
21+
if (newDesc.get) {
22+
newDesc.get = () => (newProps as any)[key]
23+
} else {
24+
newDesc.value = (newProps as any)[key]
25+
}
26+
Object.defineProperty(obj, key, newDesc)
27+
})
28+
if ((obj as any).mockRestore) backup.mockRestore = Object.getOwnPropertyDescriptor(obj, 'mockRestore')
29+
return Object.defineProperty(obj, 'mockRestore', {
30+
value() {
31+
Object.keys(backup).forEach(key => {
32+
Object.defineProperty(obj, key, backup[key])
33+
})
34+
return obj
35+
},
36+
configurable: true,
37+
})
38+
}
39+
40+
export const mockWriteStream = () => {
41+
return {
42+
written: [] as string[],
43+
write(text: string) {
44+
this.written.push(text)
45+
},
46+
clear() {
47+
this.written = []
48+
},
49+
}
50+
}

0 commit comments

Comments
 (0)