@@ -22,13 +22,49 @@ test('@mdx-js/loader', async () => {
2222 // Setup.
2323 const base = new URL ( '.' , import . meta. url )
2424
25+ await fs . writeFile (
26+ new URL ( 'webpack.mdx' , base ) ,
27+ '# Hello, {<Message />'
28+ )
29+
30+ // Errors.
31+ const failedResult = await promisify ( webpack ) ( {
32+ // @ts -expect-error To do: webpack types miss support for `context`.
33+ context : fileURLToPath ( base ) ,
34+ entry : './webpack.mdx' ,
35+ mode : 'none' ,
36+ module : {
37+ rules : [
38+ {
39+ test : / \. m d x $ / ,
40+ use : [ fileURLToPath ( new URL ( '../index.cjs' , import . meta. url ) ) ]
41+ }
42+ ]
43+ } ,
44+ output : {
45+ path : fileURLToPath ( base ) ,
46+ filename : 'react.cjs' ,
47+ libraryTarget : 'commonjs'
48+ }
49+ } )
50+
51+ const error = failedResult ?. toJson ( ) ?. errors ?. [ 0 ]
52+
53+ assert . ok ( error ) ;
54+ assert . equal (
55+ error . message ,
56+ `Module build failed (from ../index.cjs):
57+ webpack.mdx:1:22: Unexpected end of file in expression, expected a corresponding closing brace for \`{\`` ,
58+ 'received expected error message'
59+ )
60+
2561 await fs . writeFile (
2662 new URL ( 'webpack.mdx' , base ) ,
2763 'export const Message = () => <>World!</>\n\n# Hello, <Message />'
2864 )
2965
3066 // React.
31- await promisify ( webpack ) ( {
67+ const reactBuild = await promisify ( webpack ) ( {
3268 // @ts -expect-error To do: webpack types miss support for `context`.
3369 context : fileURLToPath ( base ) ,
3470 entry : './webpack.mdx' ,
@@ -48,6 +84,8 @@ test('@mdx-js/loader', async () => {
4884 }
4985 } )
5086
87+ assert . not . ok ( reactBuild ?. hasErrors ( ) )
88+
5189 // One for ESM loading CJS, one for webpack.
5290 const modReact = /** @type {{default: {default: MDXContent}} } */ (
5391 // @ts -expect-error file is dynamically generated
@@ -63,7 +101,7 @@ test('@mdx-js/loader', async () => {
63101 await fs . unlink ( new URL ( 'react.cjs' , base ) )
64102
65103 // Preact and source maps
66- await promisify ( webpack ) ( {
104+ const preactBuild = await promisify ( webpack ) ( {
67105 // @ts -expect-error To do: webpack types miss support for `context`.
68106 context : fileURLToPath ( base ) ,
69107 entry : './webpack.mdx' ,
@@ -89,6 +127,9 @@ test('@mdx-js/loader', async () => {
89127 }
90128 } )
91129
130+ assert . not . ok ( preactBuild ?. hasErrors ( ) )
131+
132+
92133 // One for ESM loading CJS, one for webpack.
93134 const modPreact = /** @type {{default: {default: PreactComponent}} } */ (
94135 // @ts -expect-error file is dynamically generated.
@@ -110,7 +151,7 @@ test('@mdx-js/loader', async () => {
110151 await fs . unlink ( new URL ( 'preact.cjs' , base ) )
111152
112153 // Vue.
113- await promisify ( webpack ) ( {
154+ const vueBuild = await promisify ( webpack ) ( {
114155 // @ts -expect-error To do: webpack types miss support for `context`.
115156 context : fileURLToPath ( base ) ,
116157 entry : './webpack.mdx' ,
@@ -140,6 +181,8 @@ test('@mdx-js/loader', async () => {
140181 }
141182 } )
142183
184+ assert . not . ok ( vueBuild ?. hasErrors ( ) )
185+
143186 // One for ESM loading CJS, one for webpack.
144187 const modVue = /** @type {{default: {default: VueComponent}} } */ (
145188 // @ts -expect-error file is dynamically generated
0 commit comments