File tree 3 files changed +26
-1
lines changed
packages/jest-message-util/src
3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 7
7
- ` [matcher-utils] ` Correct diff for expected asymmetric matchers ([ #12264 ] ( https://github.com/facebook/jest/pull/12264 ) )
8
8
- ` [expect] ` Add a fix for ` .toHaveProperty('') ` ([ #12251 ] ( https://github.com/facebook/jest/pull/12251 ) )
9
9
- ` [jest-environment-node] ` Add ` atob ` and ` btoa ` ([ #12269 ] ( https://github.com/facebook/jest/pull/12269 ) )
10
+ - ` [jest-message-util] ` Fix ` .getTopFrame() ` (and ` toMatchInlineSnapshot() ` ) with ` mjs ` files ([ #12277 ] ( https://github.com/facebook/jest/pull/12277 ) )
10
11
11
12
### Chore & Maintenance
12
13
Original file line number Diff line number Diff line change 9
9
import { readFileSync } from 'graceful-fs' ;
10
10
import slash = require( 'slash' ) ;
11
11
import tempy = require( 'tempy' ) ;
12
- import { formatExecError , formatResultsErrors , formatStackTrace } from '..' ;
12
+ import {
13
+ formatExecError ,
14
+ formatResultsErrors ,
15
+ formatStackTrace ,
16
+ getTopFrame ,
17
+ } from '..' ;
13
18
14
19
const rootDir = tempy . directory ( ) ;
15
20
@@ -365,3 +370,18 @@ describe('formatStackTrace', () => {
365
370
expect ( message ) . toMatchSnapshot ( ) ;
366
371
} ) ;
367
372
} ) ;
373
+
374
+ it ( 'getTopFrame should return a path for mjs files' , ( ) => {
375
+ let stack : Array < string > ;
376
+ let expectedFile : string ;
377
+ if ( process . platform === 'win32' ) {
378
+ stack = [ ' at stack (file:///C:/Users/user/project/inline.mjs:1:1)' ] ;
379
+ expectedFile = 'C:/Users/user/project/inline.mjs' ;
380
+ } else {
381
+ stack = [ ' at stack (file:///Users/user/project/inline.mjs:1:1)' ] ;
382
+ expectedFile = '/Users/user/project/inline.mjs' ;
383
+ }
384
+ const frame = getTopFrame ( stack ) ;
385
+
386
+ expect ( frame . file ) . toBe ( expectedFile ) ;
387
+ } ) ;
Original file line number Diff line number Diff line change 6
6
*/
7
7
8
8
import * as path from 'path' ;
9
+ import { fileURLToPath } from 'url' ;
9
10
import { codeFrameColumns } from '@babel/code-frame' ;
10
11
import chalk = require( 'chalk' ) ;
11
12
import * as fs from 'graceful-fs' ;
@@ -273,6 +274,9 @@ export const getTopFrame = (lines: Array<string>): Frame | null => {
273
274
const parsedFrame = stackUtils . parseLine ( line . trim ( ) ) ;
274
275
275
276
if ( parsedFrame && parsedFrame . file ) {
277
+ if ( parsedFrame . file . startsWith ( 'file://' ) ) {
278
+ parsedFrame . file = slash ( fileURLToPath ( parsedFrame . file ) ) ;
279
+ }
276
280
return parsedFrame as Frame ;
277
281
}
278
282
}
You can’t perform that action at this time.
0 commit comments