Skip to content

Commit 5d03c4d

Browse files
committed
feat(logging): improves log messages + tests
1 parent 4322701 commit 5d03c4d

46 files changed

Lines changed: 657 additions & 619 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737
- [Angular 2](#angular-2)
3838
- [Tips](#tips)
3939
- [Importing packages written in TypeScript](#importing-packages-written-in-typescript)
40+
- [Logging](#logging)
4041
- [Known Limitations](#known-limitations)
4142
- [Known limitations for TS compiler options](#known-limitations-for-ts-compiler-options)
42-
- [`const enum` is not supported](#const-enum-is-not-supported)
43+
- [`const enum` is not supported if `typeCheck` is not enabled](#const-enum-is-not-supported-if-typecheck-is-not-enabled)
4344
- [How to Contribute](#how-to-contribute)
4445
- [Quickstart to run tests (only if you're working on this package)](#quickstart-to-run-tests-only-if-youre-working-on-this-package)
4546
- [License](#license)
@@ -364,6 +365,20 @@ your Jest configuration:
364365

365366
By default Jest ignores everything in `node_modules`. This setting prevents Jest from ignoring the package you're interested in, in this case `@foo/bar`, while continuing to ignore everything else in `node_modules`.
366367

368+
### Logging
369+
370+
This package is using [`bs-logger`](https://www.npmjs.com/package/bs-logger).
371+
372+
Use environment variable `TS_JEST_LOG=xxx` to configure log targets. By default it'll log entries with level _warning_ and above to **stderr**.
373+
374+
See the examples in [there](https://github.com/huafu/bs-logger#using-targets) to configure different target(s).
375+
376+
When posting an issue, it's best to join the full log file which you can create in CWD using:
377+
```sh
378+
TS_JEST_LOG=ts-jest.log jest
379+
# or
380+
TS_JEST_LOG=ts-jest.log npm run test
381+
```
367382

368383
## Known Limitations
369384

doc/tech/process/ts-jest.puml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ if (has afterProcess hook?) then (yes)
8787
:call afterProcess hook;
8888
-> update
8989
source;
90-
floating note left
90+
note left
9191
if the hook returns
9292
something it'll be
9393
used as new source

e2e/__helpers__/test-case/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RunTestOptions } from './types'
2-
import RunDescriptor from './RunDescriptor'
2+
import RunDescriptor from './run-descriptor'
33

44
export function configureTestCase(
55
name: string,

e2e/__helpers__/test-case/ProcessedFileIo.ts renamed to e2e/__helpers__/test-case/processed-file-io.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ProcessedSource from '../../../src/__helpers__/ProcessedSource'
1+
import ProcessedSource from '../../../src/__helpers__/processed-source'
22

33
// tslint:disable-next-line:no-default-export
44
export default class ProcessedFileIo extends ProcessedSource {

e2e/__helpers__/test-case/RunDescriptor.ts renamed to e2e/__helpers__/test-case/run-descriptor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from './types'
77
import { join } from 'path'
88
import * as Paths from '../../../scripts/lib/paths'
9-
import RunResult from './RunResult'
9+
import RunResult from './run-result'
1010
import { run } from './runtime'
1111

1212
// tslint:disable-next-line:no-default-export
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { SpawnSyncReturns } from 'child_process'
2-
import ProcessedFileIo from './ProcessedFileIo'
2+
import ProcessedFileIo from './processed-file-io'
33
import { stripAnsiColors, normalizeJestOutput, escapeRegex } from './utils'
44
import { resolve } from 'path'
55
import { readFileSync, realpathSync } from 'fs'
6-
import { LOG_PREFIX } from '../../../src/util/debug'
76
import { tmpdir } from 'os'
7+
import { LogMessage } from 'bs-logger'
88

99
// tslint:disable-next-line:no-default-export
1010
export default class RunResult {
@@ -18,13 +18,13 @@ export default class RunResult {
1818
env: { [key: string]: string },
1919
}>,
2020
) { }
21-
get logFilePath() { return resolve(this.cwd, 'ts-jest-debug.log') }
21+
get logFilePath() { return resolve(this.cwd, 'ts-jest.log') }
2222
get logFileContent() { return readFileSync(this.logFilePath).toString('utf8') }
23-
get normalizedLogFileContent() {
24-
const prefix = ` ${LOG_PREFIX} `
25-
return this.normalize(this.logFileContent.split(/\n/g).map(s => {
26-
return s.split(prefix).slice(1).join(prefix)
27-
}).join('\n'))
23+
get logFileEntries(): LogMessage[] {
24+
const lines = this.logFileContent.split(/\n/g)
25+
// remove last, empty line
26+
lines.pop()
27+
return lines.map(s => JSON.parse(s))
2828
}
2929
get isPass() { return this.status === 0 }
3030
get isFail() { return !this.isPass }
@@ -35,7 +35,7 @@ export default class RunResult {
3535
get stdout() { return stripAnsiColors((this.result.stdout || '').toString()) }
3636
get normalizedStdout() { return normalizeJestOutput(this.stdout) }
3737
get cmdLine() {
38-
return [this.context.cmd, ...this.context.args].join(' ')
38+
return [this.context.cmd, ...this.context.args].filter(a => !['-u', '--updateSnapshot'].includes(a)).join(' ')
3939
}
4040

4141
ioFor(relFilePath: string): ProcessedFileIo {

e2e/__helpers__/test-case/runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RunTestOptions, PreparedTest } from './types'
2-
import RunResult from './RunResult'
2+
import RunResult from './run-result'
33
import { templateNameForPath } from './utils'
44
import { join, relative, sep } from 'path'
55
import * as Paths from '../../../scripts/lib/paths'

e2e/__helpers__/test-case/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TsJestConfig } from '../../../src/types'
2-
import RunResult from './RunResult'
2+
import RunResult from './run-result'
33

44
export interface RunTestOptions {
55
template?: string

e2e/__serializers__/run-result.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import RunResult from '../__helpers__/test-case/RunResult'
1+
import RunResult from '../__helpers__/test-case/run-result'
22

33
export const test = (val: any) => val && val instanceof RunResult
44
export const print = (val: RunResult, serialize: any, indent: any) => {

e2e/__tests__/__snapshots__/hoisting.test.ts.snap

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "default" 1`] = `
4-
√ jest --runInBand
5-
↳ exit code: 0
6-
===[ STDOUT ]===================================================================
7-
8-
===[ STDERR ]===================================================================
9-
PASS ./hello.spec.ts
10-
hello
11-
√ should have been mocked
12-
13-
Test Suites: 1 passed, 1 total
14-
Tests: 1 passed, 1 total
15-
Snapshots: 0 total
16-
Time: XXs
17-
Ran all test suites.
18-
================================================================================
19-
`;
20-
21-
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "default" 2`] = `
3+
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "default": io 1`] = `
224
===[ FILE: hello.spec.ts ]======================================================
235
"use strict";
246
var __importDefault = (this && this.__importDefault) || function (mod) {
@@ -79,7 +61,7 @@ exports[`Hoisting jest.mock() & jest.unmock() should pass using template "defaul
7961
================================================================================
8062
`;
8163
82-
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-babel-6" 1`] = `
64+
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "default": output 1`] = `
8365
√ jest --runInBand
8466
↳ exit code: 0
8567
===[ STDOUT ]===================================================================
@@ -97,7 +79,7 @@ exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-b
9779
================================================================================
9880
`;
9981
100-
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-babel-6" 2`] = `
82+
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-babel-6": io 1`] = `
10183
===[ FILE: hello.spec.ts ]======================================================
10284
"use strict";
10385
@@ -159,7 +141,7 @@ exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-b
159141
================================================================================
160142
`;
161143
162-
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-babel-7" 1`] = `
144+
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-babel-6": output 1`] = `
163145
√ jest --runInBand
164146
↳ exit code: 0
165147
===[ STDOUT ]===================================================================
@@ -177,7 +159,7 @@ exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-b
177159
================================================================================
178160
`;
179161
180-
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-babel-7" 2`] = `
162+
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-babel-7": io 1`] = `
181163
===[ FILE: hello.spec.ts ]======================================================
182164
"use strict";
183165
@@ -251,7 +233,7 @@ exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-b
251233
================================================================================
252234
`;
253235
254-
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-jest-22" 1`] = `
236+
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-babel-7": output 1`] = `
255237
√ jest --runInBand
256238
↳ exit code: 0
257239
===[ STDOUT ]===================================================================
@@ -269,7 +251,7 @@ exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-j
269251
================================================================================
270252
`;
271253
272-
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-jest-22" 2`] = `
254+
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-jest-22": io 1`] = `
273255
===[ FILE: hello.spec.ts ]======================================================
274256
"use strict";
275257
var __importDefault = (this && this.__importDefault) || function (mod) {
@@ -330,7 +312,7 @@ exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-j
330312
================================================================================
331313
`;
332314
333-
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-typescript-2-7" 1`] = `
315+
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-jest-22": output 1`] = `
334316
√ jest --runInBand
335317
↳ exit code: 0
336318
===[ STDOUT ]===================================================================
@@ -348,7 +330,7 @@ exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-t
348330
================================================================================
349331
`;
350332
351-
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-typescript-2-7" 2`] = `
333+
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-typescript-2-7": io 1`] = `
352334
===[ FILE: hello.spec.ts ]======================================================
353335
"use strict";
354336
var __importDefault = (this && this.__importDefault) || function (mod) {
@@ -408,3 +390,21 @@ exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-t
408390
version: 3
409391
================================================================================
410392
`;
393+
394+
exports[`Hoisting jest.mock() & jest.unmock() should pass using template "with-typescript-2-7": output 1`] = `
395+
√ jest --runInBand
396+
↳ exit code: 0
397+
===[ STDOUT ]===================================================================
398+
399+
===[ STDERR ]===================================================================
400+
PASS ./hello.spec.ts
401+
hello
402+
√ should have been mocked
403+
404+
Test Suites: 1 passed, 1 total
405+
Tests: 1 passed, 1 total
406+
Snapshots: 0 total
407+
Time: XXs
408+
Ran all test suites.
409+
================================================================================
410+
`;

0 commit comments

Comments
 (0)