File tree Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
### Features
4
4
5
+ - ` [jest-core] ` Add newlines to JSON output ([ #13817 ] ( https://github.com/facebook/jest/pull/13817 ) )
6
+
5
7
### Fixes
6
8
7
9
- ` [@jest/expect-utils] ` ` toMatchObject ` diffs should include ` Symbol ` properties ([ #13810 ] ( https://github.com/facebook/jest/pull/13810 ) )
Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ describe('JSON Reporter', () => {
28
28
runJest ( 'json-reporter' , [ '--json' , `--outputFile=${ outputFileName } ` ] ) ;
29
29
const testOutput = fs . readFileSync ( outputFilePath , 'utf8' ) ;
30
30
31
+ expect ( testOutput . endsWith ( '\n' ) ) . toBe ( true ) ;
32
+
31
33
try {
32
34
jsonResult = JSON . parse ( testOutput ) ;
33
35
} catch ( err : any ) {
@@ -71,12 +73,16 @@ describe('JSON Reporter', () => {
71
73
} ) ;
72
74
73
75
it ( 'outputs coverage report' , ( ) => {
74
- const result = runJest ( 'json-reporter' , [ '--json' ] ) ;
76
+ const result = runJest ( 'json-reporter' , [ '--json' ] , {
77
+ keepTrailingNewline : true ,
78
+ } ) ;
75
79
let jsonResult : FormattedTestResults ;
76
80
77
81
expect ( result . stderr ) . toMatch ( / 1 f a i l e d , 1 s k i p p e d , 2 p a s s e d / ) ;
78
82
expect ( result . exitCode ) . toBe ( 1 ) ;
79
83
84
+ expect ( result . stdout . endsWith ( '\n' ) ) . toBe ( true ) ;
85
+
80
86
try {
81
87
jsonResult = JSON . parse ( result . stdout ) ;
82
88
} catch ( err : any ) {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import {normalizeIcons} from './Utils';
20
20
const JEST_PATH = path . resolve ( __dirname , '../packages/jest-cli/bin/jest.js' ) ;
21
21
22
22
type RunJestOptions = {
23
+ keepTrailingNewline ?: boolean ; // keep final newline in output from stdout and stderr
23
24
nodeOptions ?: string ;
24
25
nodePath ?: string ;
25
26
skipPkgJsonCheck ?: boolean ; // don't complain if can't find package.json
@@ -97,6 +98,7 @@ function spawnJest(
97
98
cwd : dir ,
98
99
env,
99
100
reject : false ,
101
+ stripFinalNewline : ! options . keepTrailingNewline ,
100
102
timeout : options . timeout || 0 ,
101
103
} ;
102
104
Original file line number Diff line number Diff line change @@ -106,12 +106,17 @@ const processResults = async (
106
106
const cwd = tryRealpath ( process . cwd ( ) ) ;
107
107
const filePath = path . resolve ( cwd , outputFile ) ;
108
108
109
- fs . writeFileSync ( filePath , JSON . stringify ( formatTestResults ( runResults ) ) ) ;
109
+ fs . writeFileSync (
110
+ filePath ,
111
+ `${ JSON . stringify ( formatTestResults ( runResults ) ) } \n` ,
112
+ ) ;
110
113
outputStream . write (
111
114
`Test results written to: ${ path . relative ( cwd , filePath ) } \n` ,
112
115
) ;
113
116
} else {
114
- process . stdout . write ( JSON . stringify ( formatTestResults ( runResults ) ) ) ;
117
+ process . stdout . write (
118
+ `${ JSON . stringify ( formatTestResults ( runResults ) ) } \n` ,
119
+ ) ;
115
120
}
116
121
}
117
122
You can’t perform that action at this time.
0 commit comments