@@ -23,39 +23,42 @@ function formatPrettier(input) {
23
23
24
24
function format ( input ) {
25
25
try {
26
- return lightningcss
27
- . transform ( {
28
- filename : 'input.css' ,
29
- code : Buffer . from ( input ) ,
30
- minify : false ,
31
- targets : { chrome : 106 << 16 } ,
32
- drafts : {
33
- nesting : true ,
34
- customMedia : true ,
35
- } ,
36
- } )
37
- . code . toString ( 'utf8' )
26
+ return [
27
+ lightningcss
28
+ . transform ( {
29
+ filename : 'input.css' ,
30
+ code : Buffer . from ( input ) ,
31
+ minify : false ,
32
+ targets : { chrome : 106 << 16 } ,
33
+ drafts : {
34
+ nesting : true ,
35
+ customMedia : true ,
36
+ } ,
37
+ } )
38
+ . code . toString ( 'utf8' ) ,
39
+ null ,
40
+ ]
38
41
} catch ( err ) {
42
+ let lines = err . source . split ( '\n' )
43
+ let e = new Error (
44
+ [
45
+ 'Error formatting using Lightning CSS:' ,
46
+ '' ,
47
+ ...[
48
+ '```css' ,
49
+ ...lines . slice ( Math . max ( err . loc . line - 3 , 0 ) , err . loc . line ) ,
50
+ ' ' . repeat ( err . loc . column - 1 ) + '^-- ' + err . toString ( ) ,
51
+ ...lines . slice ( err . loc . line , err . loc . line + 2 ) ,
52
+ '```' ,
53
+ ] ,
54
+ ] . join ( '\n' )
55
+ )
39
56
try {
40
57
// Lightning CSS is pretty strict, so it will fail for `@media screen(md) {}` for example,
41
58
// in that case we can fallback to prettier since it doesn't really care. However if an
42
59
// actual syntax error is made, then we still want to show the proper error.
43
- return formatPrettier ( input . replace ( / \n / g, '' ) )
60
+ return [ formatPrettier ( input . replace ( / \n / g, '' ) ) , e ]
44
61
} catch {
45
- let lines = err . source . split ( '\n' )
46
- let e = new Error (
47
- [
48
- 'Error formatting using Lightning CSS:' ,
49
- '' ,
50
- ...[
51
- '```css' ,
52
- ...lines . slice ( Math . max ( err . loc . line - 3 , 0 ) , err . loc . line ) ,
53
- ' ' . repeat ( err . loc . column - 1 ) + '^-- ' + err . toString ( ) ,
54
- ...lines . slice ( err . loc . line , err . loc . line + 2 ) ,
55
- '```' ,
56
- ] ,
57
- ] . join ( '\n' )
58
- )
59
62
if ( Error . captureStackTrace ) {
60
63
Error . captureStackTrace ( e , toMatchFormattedCss )
61
64
}
@@ -71,8 +74,8 @@ function toMatchFormattedCss(received = '', argument = '') {
71
74
promise : this . promise ,
72
75
}
73
76
74
- let formattedReceived = format ( received )
75
- let formattedArgument = format ( argument )
77
+ let [ formattedReceived , formattingReceivedError ] = format ( received )
78
+ let [ formattedArgument , formattingArgumentError ] = format ( argument )
76
79
77
80
let pass = formattedReceived === formattedArgument
78
81
@@ -99,7 +102,9 @@ function toMatchFormattedCss(received = '', argument = '') {
99
102
( diffString && diffString . includes ( '- Expect' )
100
103
? `Difference:\n\n${ diffString } `
101
104
: `Expected: ${ this . utils . printExpected ( expected ) } \n` +
102
- `Received: ${ this . utils . printReceived ( actual ) } ` )
105
+ `Received: ${ this . utils . printReceived ( actual ) } ` ) +
106
+ ( formattingReceivedError ? '\n\n' + formattingReceivedError : '' ) +
107
+ ( formattingArgumentError ? '\n\n' + formattingArgumentError : '' )
103
108
)
104
109
}
105
110
@@ -118,7 +123,9 @@ expect.extend({
118
123
promise : this . promise ,
119
124
}
120
125
121
- let pass = format ( received ) . includes ( format ( argument ) )
126
+ let [ formattedReceived , formattedReceivedError ] = format ( received )
127
+ let [ formattedArgument , formattedArgumentError ] = format ( argument )
128
+ let pass = formattedReceived . includes ( formattedArgument )
122
129
123
130
let message = pass
124
131
? ( ) => {
@@ -143,7 +150,9 @@ expect.extend({
143
150
( diffString && diffString . includes ( '- Expect' )
144
151
? `Difference:\n\n${ diffString } `
145
152
: `Expected: ${ this . utils . printExpected ( expected ) } \n` +
146
- `Received: ${ this . utils . printReceived ( actual ) } ` )
153
+ `Received: ${ this . utils . printReceived ( actual ) } ` ) +
154
+ ( formattedReceivedError ? '\n\n' + formattedReceivedError : '' ) +
155
+ ( formattedArgumentError ? '\n\n' + formattedArgumentError : '' )
147
156
)
148
157
}
149
158
0 commit comments