1- import { sentryWebpackPlugin } from '@sentry/webpack-plugin' ;
2- import { onCreateWebpackConfig } from '../gatsby-node' ;
1+ import { describe , afterAll , afterEach , beforeEach , beforeAll , vi , it , expect } from 'vitest' ;
2+
3+ vi . hoisted (
4+ ( ) =>
5+ void mock ( '@sentry/webpack-plugin' , {
6+ sentryWebpackPlugin : vi . fn ( ) . mockReturnValue ( { } ) ,
7+ } ) ,
8+ ) ;
9+
10+ // Need to override mock because `gatsby-node.js` loads `@sentry/webpack-plugin` as a CJS file.
11+ async function mock ( mockedUri : string , stub : any ) {
12+ const { Module } = await import ( 'module' ) ;
13+
14+ // @ts -expect-error test
15+ Module . _load_original = Module . _load ;
16+ // @ts -expect-error test
17+ Module . _load = ( uri , parent ) => {
18+ if ( uri === mockedUri ) return stub ;
19+ // @ts -expect-error test
20+ return Module . _load_original ( uri , parent ) ;
21+ } ;
22+ }
323
4- jest . mock ( '@sentry/webpack-plugin' , ( ) => ( {
5- sentryWebpackPlugin : jest . fn ( ) . mockReturnValue ( {
6- apply : jest . fn ( ) ,
7- } ) ,
8- } ) ) ;
24+ import { onCreateWebpackConfig } from '../gatsby-node' ;
925
1026describe ( 'onCreateWebpackConfig' , ( ) => {
27+ // eslint-disable-next-line @typescript-eslint/no-var-requires
28+ const { sentryWebpackPlugin } = require ( '@sentry/webpack-plugin' ) ;
1129 let originalNodeEnv : string | undefined ;
1230
1331 beforeAll ( ( ) => {
@@ -20,15 +38,15 @@ describe('onCreateWebpackConfig', () => {
2038 } ) ;
2139
2240 afterEach ( ( ) => {
23- jest . clearAllMocks ( ) ;
41+ vi . clearAllMocks ( ) ;
2442 } ) ;
2543
2644 it ( 'sets a webpack config' , ( ) => {
2745 const actions = {
28- setWebpackConfig : jest . fn ( ) ,
46+ setWebpackConfig : vi . fn ( ) ,
2947 } ;
3048
31- const getConfig = jest . fn ( ) . mockReturnValue ( { devtool : 'source-map' } ) ;
49+ const getConfig = vi . fn ( ) . mockReturnValue ( { devtool : 'source-map' } ) ;
3250
3351 onCreateWebpackConfig ( { actions, getConfig } , { } ) ;
3452
@@ -38,10 +56,10 @@ describe('onCreateWebpackConfig', () => {
3856
3957 it ( 'does not set a webpack config if enableClientWebpackPlugin is false' , ( ) => {
4058 const actions = {
41- setWebpackConfig : jest . fn ( ) ,
59+ setWebpackConfig : vi . fn ( ) ,
4260 } ;
4361
44- const getConfig = jest . fn ( ) . mockReturnValue ( { devtool : 'source-map' } ) ;
62+ const getConfig = vi . fn ( ) . mockReturnValue ( { devtool : 'source-map' } ) ;
4563
4664 onCreateWebpackConfig ( { actions, getConfig } , { enableClientWebpackPlugin : false } ) ;
4765
@@ -50,21 +68,21 @@ describe('onCreateWebpackConfig', () => {
5068
5169 describe ( 'delete source maps after upload' , ( ) => {
5270 beforeEach ( ( ) => {
53- jest . clearAllMocks ( ) ;
71+ vi . clearAllMocks ( ) ;
5472 } ) ;
5573
5674 const actions = {
57- setWebpackConfig : jest . fn ( ) ,
75+ setWebpackConfig : vi . fn ( ) ,
5876 } ;
5977
60- const getConfig = jest . fn ( ) ;
78+ const getConfig = vi . fn ( ) ;
6179
6280 it ( 'sets sourceMapFilesToDeleteAfterUpload when provided in options' , ( ) => {
6381 const actions = {
64- setWebpackConfig : jest . fn ( ) ,
82+ setWebpackConfig : vi . fn ( ) ,
6583 } ;
6684
67- const getConfig = jest . fn ( ) . mockReturnValue ( { devtool : 'source-map' } ) ;
85+ const getConfig = vi . fn ( ) . mockReturnValue ( { devtool : 'source-map' } ) ;
6886
6987 onCreateWebpackConfig ( { actions, getConfig } , { deleteSourcemapsAfterUpload : true } ) ;
7088
@@ -79,7 +97,7 @@ describe('onCreateWebpackConfig', () => {
7997 ) ;
8098 } ) ;
8199
82- test . each ( [
100+ it . each ( [
83101 {
84102 name : 'without provided options: sets hidden source maps and deletes source maps' ,
85103 initialConfig : undefined ,
0 commit comments