55 * LICENSE file in the root directory of this source tree.
66 */
77
8- import { beforeEach , describe , expect , it , vi } from 'vitest' ;
8+ import { describe , expect , it , vi } from 'vitest' ;
99import * as path from 'path' ;
1010import vfile from 'to-vfile' ;
1111import plugin , { type PluginOptions } from '../index' ;
@@ -68,10 +68,10 @@ describe('transformImage plugin', () => {
6868 } ) ;
6969
7070 it ( 'does not choke on invalid image' , async ( ) => {
71- const errorMock = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
71+ using warn = vi . spyOn ( console , 'warn' ) ;
7272 const result = await processContent ( `` ) ;
7373 expect ( result ) . toMatchSnapshot ( ) ;
74- expect ( errorMock ) . toHaveBeenCalledTimes ( 1 ) ;
74+ expect ( warn ) . toHaveBeenCalledTimes ( 1 ) ;
7575 } ) ;
7676
7777 describe ( 'onBrokenMarkdownImages' , ( ) => {
@@ -121,19 +121,15 @@ describe('transformImage plugin', () => {
121121 return processContent ( content , { onBrokenMarkdownImages : 'warn' } ) ;
122122 }
123123
124- const warnMock = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
125- beforeEach ( ( ) => {
126- warnMock . mockClear ( ) ;
127- } ) ;
128-
129124 it ( 'if image absolute path does not exist' , async ( ) => {
125+ using warn = vi . spyOn ( console , 'warn' ) ;
130126 const result = await processWarn ( fixtures . doesNotExistAbsolute ) ;
131127 expect ( result ) . toMatchInlineSnapshot ( `
132128 "
133129 "
134130 ` ) ;
135- expect ( warnMock ) . toHaveBeenCalledTimes ( 1 ) ;
136- expect ( warnMock . mock . calls ) . toMatchInlineSnapshot ( `
131+ expect ( warn ) . toHaveBeenCalledTimes ( 1 ) ;
132+ expect ( warn . mock . calls ) . toMatchInlineSnapshot ( `
137133 [
138134 [
139135 "[WARNING] Markdown image with URL \`/img/doesNotExist.png\` in source file "packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/__fixtures__/docs/myFile.mdx" (1:1) couldn't be resolved to an existing local image file.",
@@ -143,13 +139,14 @@ describe('transformImage plugin', () => {
143139 } ) ;
144140
145141 it ( 'if image relative path does not exist' , async ( ) => {
142+ using warn = vi . spyOn ( console , 'warn' ) ;
146143 const result = await processWarn ( fixtures . doesNotExistRelative ) ;
147144 expect ( result ) . toMatchInlineSnapshot ( `
148145 "
149146 "
150147 ` ) ;
151- expect ( warnMock ) . toHaveBeenCalledTimes ( 1 ) ;
152- expect ( warnMock . mock . calls ) . toMatchInlineSnapshot ( `
148+ expect ( warn ) . toHaveBeenCalledTimes ( 1 ) ;
149+ expect ( warn . mock . calls ) . toMatchInlineSnapshot ( `
153150 [
154151 [
155152 "[WARNING] Markdown image with URL \`./doesNotExist.png\` in source file "packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/__fixtures__/docs/myFile.mdx" (1:1) couldn't be resolved to an existing local image file.",
@@ -159,13 +156,14 @@ describe('transformImage plugin', () => {
159156 } ) ;
160157
161158 it ( 'if image @site path does not exist' , async ( ) => {
159+ using warn = vi . spyOn ( console , 'warn' ) ;
162160 const result = await processWarn ( fixtures . doesNotExistSiteAlias ) ;
163161 expect ( result ) . toMatchInlineSnapshot ( `
164162 "
165163 "
166164 ` ) ;
167- expect ( warnMock ) . toHaveBeenCalledTimes ( 1 ) ;
168- expect ( warnMock . mock . calls ) . toMatchInlineSnapshot ( `
165+ expect ( warn ) . toHaveBeenCalledTimes ( 1 ) ;
166+ expect ( warn . mock . calls ) . toMatchInlineSnapshot ( `
169167 [
170168 [
171169 "[WARNING] Markdown image with URL \`@site/doesNotExist.png\` in source file "packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/__fixtures__/docs/myFile.mdx" (1:1) couldn't be resolved to an existing local image file.",
@@ -175,13 +173,14 @@ describe('transformImage plugin', () => {
175173 } ) ;
176174
177175 it ( 'if image url empty' , async ( ) => {
176+ using warn = vi . spyOn ( console , 'warn' ) ;
178177 const result = await processWarn ( fixtures . urlEmpty ) ;
179178 expect ( result ) . toMatchInlineSnapshot ( `
180179 "![img]()
181180 "
182181 ` ) ;
183- expect ( warnMock ) . toHaveBeenCalledTimes ( 1 ) ;
184- expect ( warnMock . mock . calls ) . toMatchInlineSnapshot ( `
182+ expect ( warn ) . toHaveBeenCalledTimes ( 1 ) ;
183+ expect ( warn . mock . calls ) . toMatchInlineSnapshot ( `
185184 [
186185 [
187186 "[WARNING] Markdown image with empty URL found in source file "packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/__fixtures__/docs/myFile.mdx" (1:1).",
@@ -205,19 +204,16 @@ describe('transformImage plugin', () => {
205204 } ) ;
206205 }
207206
208- const logMock = vi . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
209- beforeEach ( ( ) => {
210- logMock . mockClear ( ) ;
211- } ) ;
212-
213207 it ( 'if image absolute path does not exist' , async ( ) => {
208+ using log = vi . spyOn ( console , 'log' ) ;
209+
214210 const result = await processWarn ( fixtures . doesNotExistAbsolute ) ;
215211 expect ( result ) . toMatchInlineSnapshot ( `
216212 "
217213 "
218214 ` ) ;
219- expect ( logMock ) . toHaveBeenCalledTimes ( 1 ) ;
220- expect ( logMock . mock . calls ) . toMatchInlineSnapshot ( `
215+ expect ( log ) . toHaveBeenCalledTimes ( 1 ) ;
216+ expect ( log . mock . calls ) . toMatchInlineSnapshot ( `
221217 [
222218 [
223219 "onBrokenMarkdownImages called for ",
@@ -249,13 +245,15 @@ describe('transformImage plugin', () => {
249245 } ) ;
250246
251247 it ( 'if image relative path does not exist' , async ( ) => {
248+ using log = vi . spyOn ( console , 'log' ) ;
249+
252250 const result = await processWarn ( fixtures . doesNotExistRelative ) ;
253251 expect ( result ) . toMatchInlineSnapshot ( `
254252 "
255253 "
256254 ` ) ;
257- expect ( logMock ) . toHaveBeenCalledTimes ( 1 ) ;
258- expect ( logMock . mock . calls ) . toMatchInlineSnapshot ( `
255+ expect ( log ) . toHaveBeenCalledTimes ( 1 ) ;
256+ expect ( log . mock . calls ) . toMatchInlineSnapshot ( `
259257 [
260258 [
261259 "onBrokenMarkdownImages called for ",
@@ -287,13 +285,15 @@ describe('transformImage plugin', () => {
287285 } ) ;
288286
289287 it ( 'if image @site path does not exist' , async ( ) => {
288+ using log = vi . spyOn ( console , 'log' ) ;
289+
290290 const result = await processWarn ( fixtures . doesNotExistSiteAlias ) ;
291291 expect ( result ) . toMatchInlineSnapshot ( `
292292 "
293293 "
294294 ` ) ;
295- expect ( logMock ) . toHaveBeenCalledTimes ( 1 ) ;
296- expect ( logMock . mock . calls ) . toMatchInlineSnapshot ( `
295+ expect ( log ) . toHaveBeenCalledTimes ( 1 ) ;
296+ expect ( log . mock . calls ) . toMatchInlineSnapshot ( `
297297 [
298298 [
299299 "onBrokenMarkdownImages called for ",
@@ -325,13 +325,15 @@ describe('transformImage plugin', () => {
325325 } ) ;
326326
327327 it ( 'if image url empty' , async ( ) => {
328+ using log = vi . spyOn ( console , 'log' ) ;
329+
328330 const result = await processWarn ( fixtures . urlEmpty ) ;
329331 expect ( result ) . toMatchInlineSnapshot ( `
330332 "
331333 "
332334 ` ) ;
333- expect ( logMock ) . toHaveBeenCalledTimes ( 1 ) ;
334- expect ( logMock . mock . calls ) . toMatchInlineSnapshot ( `
335+ expect ( log ) . toHaveBeenCalledTimes ( 1 ) ;
336+ expect ( log . mock . calls ) . toMatchInlineSnapshot ( `
335337 [
336338 [
337339 "onBrokenMarkdownImages called for ",
0 commit comments