@@ -3,6 +3,7 @@ import * as fs from 'fs';
33import * as os from 'os' ;
44import * as path from 'path' ;
55import type { JSONSchemaForNPMPackageJsonFiles } from '@schemastore/package' ;
6+ import stripAnsi from 'strip-ansi' ;
67import { create } from 'ts-node' ;
78import { detectJestVersion } from '../detectJestVersion' ;
89
@@ -18,10 +19,13 @@ const compiledFn = compileFnCode(require.resolve('../detectJestVersion.ts'));
1819const relativePathToFn = 'eslint-plugin-jest/lib/rules/detectJestVersion.js' ;
1920
2021const runNodeScript = ( cwd : string , script : string ) => {
21- return spawnSync ( 'node' , [ '-e' , script . split ( '\n' ) . join ( ' ' ) ] , {
22- cwd,
23- encoding : 'utf-8' ,
24- } ) ;
22+ const { stdout, stderr } = spawnSync (
23+ 'node' ,
24+ [ '-e' , script . split ( '\n' ) . join ( ' ' ) ] ,
25+ { cwd, encoding : 'utf-8' } ,
26+ ) ;
27+
28+ return { stdout : stripAnsi ( stdout . trim ( ) ) , stderr : stripAnsi ( stderr . trim ( ) ) } ;
2529} ;
2630
2731const runDetectJestVersion = ( cwd : string ) => {
@@ -120,8 +124,8 @@ describe('detectJestVersion', () => {
120124
121125 const { stdout, stderr } = runDetectJestVersion ( projectDir ) ;
122126
123- expect ( stdout . trim ( ) ) . toBe ( '21' ) ;
124- expect ( stderr . trim ( ) ) . toBe ( '' ) ;
127+ expect ( stdout ) . toBe ( '21' ) ;
128+ expect ( stderr ) . toBe ( '' ) ;
125129 } ) ;
126130 } ) ;
127131
@@ -140,8 +144,8 @@ describe('detectJestVersion', () => {
140144
141145 const { stdout, stderr } = runDetectJestVersion ( projectDir ) ;
142146
143- expect ( stdout . trim ( ) ) . toBe ( '19' ) ;
144- expect ( stderr . trim ( ) ) . toBe ( '' ) ;
147+ expect ( stdout ) . toBe ( '19' ) ;
148+ expect ( stderr ) . toBe ( '' ) ;
145149 } ) ;
146150 } ) ;
147151
@@ -165,14 +169,14 @@ describe('detectJestVersion', () => {
165169 const { stdout : stdoutBackend , stderr : stderrBackend } =
166170 runDetectJestVersion ( path . join ( projectDir , 'backend' ) ) ;
167171
168- expect ( stdoutBackend . trim ( ) ) . toBe ( '24' ) ;
169- expect ( stderrBackend . trim ( ) ) . toBe ( '' ) ;
172+ expect ( stdoutBackend ) . toBe ( '24' ) ;
173+ expect ( stderrBackend ) . toBe ( '' ) ;
170174
171175 const { stdout : stdoutFrontend , stderr : stderrFrontend } =
172176 runDetectJestVersion ( path . join ( projectDir , 'frontend' ) ) ;
173177
174- expect ( stdoutFrontend . trim ( ) ) . toBe ( '15' ) ;
175- expect ( stderrFrontend . trim ( ) ) . toBe ( '' ) ;
178+ expect ( stdoutFrontend ) . toBe ( '15' ) ;
179+ expect ( stderrFrontend ) . toBe ( '' ) ;
176180 } ) ;
177181 } ) ;
178182
@@ -186,8 +190,8 @@ describe('detectJestVersion', () => {
186190
187191 const { stdout, stderr } = runDetectJestVersion ( projectDir ) ;
188192
189- expect ( stdout . trim ( ) ) . toBe ( '' ) ;
190- expect ( stderr . trim ( ) ) . toContain ( 'Unable to detect Jest version' ) ;
193+ expect ( stdout ) . toBe ( '' ) ;
194+ expect ( stderr ) . toContain ( 'Unable to detect Jest version' ) ;
191195 } ) ;
192196 } ) ;
193197
@@ -221,7 +225,7 @@ describe('detectJestVersion', () => {
221225
222226 expect ( firstCall ) . toBe ( '26' ) ;
223227 expect ( secondCall ) . toBe ( '26' ) ;
224- expect ( stderr . trim ( ) ) . toBe ( '' ) ;
228+ expect ( stderr ) . toBe ( '' ) ;
225229 } ) ;
226230 } ) ;
227231} ) ;
0 commit comments