@@ -11,8 +11,6 @@ import test from 'tape'
11
11
import strip from 'strip-ansi'
12
12
import touch from 'touch'
13
13
14
- const cross = process . platform === 'win32' ? '×' : '✖'
15
-
16
14
const fixtures = path . join ( 'test' , 'fixtures' )
17
15
const cwd = path . join ( fixtures , 'example' )
18
16
const bin = path . join ( cwd , 'cli.js' )
@@ -23,9 +21,11 @@ test('unified-args', (t) => {
23
21
t . test ( 'should fail on missing files' , ( t ) => {
24
22
const expected = [
25
23
'missing.txt' ,
26
- ' 1:1 error No such file or directory' ,
24
+ ' error No such file or folder' ,
25
+ ' [cause]:' ,
26
+ ' Error: ENOENT:…' ,
27
27
'' ,
28
- cross + ' 1 error'
28
+ '✖ 1 error'
29
29
] . join ( '\n' )
30
30
31
31
t . plan ( 1 )
@@ -34,7 +34,7 @@ test('unified-args', (t) => {
34
34
( ) => t . fail ( ) ,
35
35
( /** @type {ExecaReturnValue } */ error ) => {
36
36
t . deepEqual (
37
- [ error . exitCode , strip ( error . stderr ) ] ,
37
+ [ error . exitCode , cleanError ( error . stderr ) ] ,
38
38
[ 1 , expected ] ,
39
39
'should fail'
40
40
)
@@ -597,11 +597,11 @@ test('unified-args', (t) => {
597
597
t . test ( 'should fail when given an ignored path' , ( t ) => {
598
598
const expected = [
599
599
'one.txt' ,
600
- ' 1:1 error Cannot process specified file: it’s ignored' ,
600
+ ' error Cannot process specified file: it’s ignored' ,
601
601
'' ,
602
602
'two.txt: no issues found' ,
603
603
'' ,
604
- cross + ' 1 error'
604
+ '✖ 1 error'
605
605
] . join ( '\n' )
606
606
607
607
t . plan ( 1 )
@@ -780,3 +780,32 @@ test('unified-args', (t) => {
780
780
781
781
t . end ( )
782
782
} )
783
+
784
+ /**
785
+ * Clean an error so that it’s easier to test.
786
+ *
787
+ * This particularly removed error cause messages, which change across Node
788
+ * versions.
789
+ * It also drops file paths, which differ across platforms.
790
+ *
791
+ * @param {string } value
792
+ * Error, report, or stack.
793
+ * @param {number | undefined } [max=Infinity]
794
+ * Lines to include.
795
+ * @returns {string }
796
+ * Clean error.
797
+ */
798
+ function cleanError ( value , max ) {
799
+ return (
800
+ strip ( value )
801
+ // Clean syscal errors
802
+ . replace ( / ( * E r r o r : [ A - Z ] + : ) [ ^ \n ] * / g, '$1…' )
803
+
804
+ . replace ( / \( .+ [ / \\ ] / g, '(' )
805
+ . replace ( / f i l e : .+ \/ / g, '' )
806
+ . replace ( / \d + : \d + / g, '1:1' )
807
+ . split ( '\n' )
808
+ . slice ( 0 , max || Number . POSITIVE_INFINITY )
809
+ . join ( '\n' )
810
+ )
811
+ }
0 commit comments