1
1
import { spawnSync } from 'child_process' ;
2
2
import path from 'path' ;
3
+ import { promises as fs } from 'fs' ;
3
4
import { testSuite , expect } from 'manten' ;
4
5
import { createFixture } from 'fs-fixture' ;
5
6
import {
6
7
transformSync ,
7
8
installSourceMapSupport ,
8
9
} from '#esbuild-kit/core-utils' ;
9
10
11
+ const isNode12 = process . version . startsWith ( 'v12.' ) ;
12
+
10
13
const applySourceMap = installSourceMapSupport ( ) ;
11
14
12
15
export default testSuite ( ( { describe } ) => {
13
16
describe ( 'source map' , ( { test } ) => {
14
- test ( 'sourcemap file' , async ( ) => {
17
+ test ( 'sourcemap file' , async ( { onTestFinish } ) => {
15
18
const rawFile = 'raw.js' ;
16
19
const code = 'let nameInError;\n\n\n nameInError();' ;
17
20
const transformedFile = 'transformed.mts' ;
@@ -26,16 +29,27 @@ export default testSuite(({ describe }) => {
26
29
[ transformedFile ] : applySourceMap ( transformed , '' ) ,
27
30
} ) ;
28
31
32
+ onTestFinish ( async ( ) => {
33
+ if ( isNode12 ) {
34
+ await fs . rmdir ( fixture . path , {
35
+ recursive : true ,
36
+ } ) ;
37
+ } else {
38
+ await fixture . rm ( ) ;
39
+ }
40
+ } ) ;
41
+
29
42
const expected = spawnSync ( process . execPath , [ path . join ( fixture . path , rawFile ) ] ) ;
30
43
const received = spawnSync ( process . execPath , [ '--enable-source-maps' , path . join ( fixture . path , transformedFile ) ] ) ;
31
44
32
- await fixture . rm ( ) ;
33
-
34
45
const stderrReceived = received . stderr . toString ( ) ;
35
46
expect ( stderrReceived ) . toMatch ( 'nameInError' ) ;
36
47
37
- const errorPosition = expected . stderr . toString ( ) . match ( new RegExp ( `${ rawFile } (:\\d+:\\d+)` ) ) ;
38
- expect ( stderrReceived ) . toMatch ( transformedFile + errorPosition ! [ 1 ] ) ;
48
+ // Node 12 doesn't support native source maps
49
+ if ( ! isNode12 ) {
50
+ const errorPosition = expected . stderr . toString ( ) . match ( new RegExp ( `${ rawFile } (:\\d+:\\d+)` ) ) ;
51
+ expect ( stderrReceived ) . toMatch ( transformedFile + errorPosition ! [ 1 ] ) ;
52
+ }
39
53
} ) ;
40
54
41
55
test ( 'path is same for windows' , async ( ) => {
0 commit comments