11import { describe , it , expect } from 'vitest' ;
22
3- import type { BuildContext , NextConfigObject } from '../../../src/config/types' ;
4- import { getWebpackPluginOptions } from '../../../src/config/webpackPluginOptions' ;
3+ import { getBuildPluginOptions } from '../../../src/config/buildPluginOptions' ;
54
6- function generateBuildContext ( overrides : {
7- dir ?: string ;
8- isServer : boolean ;
9- nextjsConfig ?: NextConfigObject ;
10- } ) : BuildContext {
11- return {
12- dev : false , // The plugin is not included in dev mode
13- isServer : overrides . isServer ,
14- buildId : 'test-build-id' ,
15- dir : overrides . dir ?? '/my/project/dir' ,
16- config : overrides . nextjsConfig ?? { } ,
17- totalPages : 2 ,
18- defaultLoaders : true ,
19- webpack : {
20- version : '4.0.0' ,
21- DefinePlugin : { } as any ,
22- } ,
23- } ;
24- }
25-
26- describe ( 'getWebpackPluginOptions()' , ( ) => {
5+ describe ( 'getBuildPluginOptions()' , ( ) => {
276 it ( 'forwards relevant options' , ( ) => {
28- const buildContext = generateBuildContext ( { isServer : false } ) ;
29- const generatedPluginOptions = getWebpackPluginOptions (
30- buildContext ,
7+ const generatedPluginOptions = getBuildPluginOptions (
318 {
329 authToken : 'my-auth-token' ,
3310 headers : { 'my-test-header' : 'test' } ,
@@ -60,6 +37,8 @@ describe('getWebpackPluginOptions()', () => {
6037 } ,
6138 } ,
6239 'my-release' ,
40+ 'webpack-client' ,
41+ '/my/project/dir/.next' ,
6342 ) ;
6443
6544 expect ( generatedPluginOptions . authToken ) . toBe ( 'my-auth-token' ) ;
@@ -119,16 +98,16 @@ describe('getWebpackPluginOptions()', () => {
11998 } ) ;
12099
121100 it ( 'forwards bundleSizeOptimization options' , ( ) => {
122- const buildContext = generateBuildContext ( { isServer : false } ) ;
123- const generatedPluginOptions = getWebpackPluginOptions (
124- buildContext ,
101+ const generatedPluginOptions = getBuildPluginOptions (
125102 {
126103 bundleSizeOptimizations : {
127104 excludeTracing : true ,
128105 excludeReplayShadowDom : false ,
129106 } ,
130107 } ,
131108 undefined ,
109+ 'webpack-client' ,
110+ '/my/project/dir/.next' ,
132111 ) ;
133112
134113 expect ( generatedPluginOptions ) . toMatchObject ( {
@@ -140,17 +119,15 @@ describe('getWebpackPluginOptions()', () => {
140119 } ) ;
141120
142121 it ( 'returns the right `assets` and `ignore` values during the server build' , ( ) => {
143- const buildContext = generateBuildContext ( { isServer : true } ) ;
144- const generatedPluginOptions = getWebpackPluginOptions ( buildContext , { } , undefined ) ;
122+ const generatedPluginOptions = getBuildPluginOptions ( { } , undefined , 'webpack-nodejs' , '/my/project/dir/.next' ) ;
145123 expect ( generatedPluginOptions . sourcemaps ) . toMatchObject ( {
146124 assets : [ '/my/project/dir/.next/server/**' , '/my/project/dir/.next/serverless/**' ] ,
147125 ignore : [ ] ,
148126 } ) ;
149127 } ) ;
150128
151129 it ( 'returns the right `assets` and `ignore` values during the client build' , ( ) => {
152- const buildContext = generateBuildContext ( { isServer : false } ) ;
153- const generatedPluginOptions = getWebpackPluginOptions ( buildContext , { } , undefined ) ;
130+ const generatedPluginOptions = getBuildPluginOptions ( { } , undefined , 'webpack-client' , '/my/project/dir/.next' ) ;
154131 expect ( generatedPluginOptions . sourcemaps ) . toMatchObject ( {
155132 assets : [ '/my/project/dir/.next/static/chunks/pages/**' , '/my/project/dir/.next/static/chunks/app/**' ] ,
156133 ignore : [
@@ -164,8 +141,12 @@ describe('getWebpackPluginOptions()', () => {
164141 } ) ;
165142
166143 it ( 'returns the right `assets` and `ignore` values during the client build with `widenClientFileUpload`' , ( ) => {
167- const buildContext = generateBuildContext ( { isServer : false } ) ;
168- const generatedPluginOptions = getWebpackPluginOptions ( buildContext , { widenClientFileUpload : true } , undefined ) ;
144+ const generatedPluginOptions = getBuildPluginOptions (
145+ { widenClientFileUpload : true } ,
146+ undefined ,
147+ 'webpack-client' ,
148+ '/my/project/dir/.next' ,
149+ ) ;
169150 expect ( generatedPluginOptions . sourcemaps ) . toMatchObject ( {
170151 assets : [ '/my/project/dir/.next/static/chunks/**' ] ,
171152 ignore : [
@@ -179,20 +160,24 @@ describe('getWebpackPluginOptions()', () => {
179160 } ) ;
180161
181162 it ( 'sets `sourcemaps.disable` plugin options to true when `sourcemaps.disable` is true' , ( ) => {
182- const buildContext = generateBuildContext ( { isServer : false } ) ;
183- const generatedPluginOptions = getWebpackPluginOptions ( buildContext , { sourcemaps : { disable : true } } , undefined ) ;
163+ const generatedPluginOptions = getBuildPluginOptions (
164+ { sourcemaps : { disable : true } } ,
165+ undefined ,
166+ 'webpack-client' ,
167+ '/my/project/dir/.next' ,
168+ ) ;
184169 expect ( generatedPluginOptions . sourcemaps ) . toMatchObject ( {
185170 disable : true ,
186171 } ) ;
187172 } ) ;
188173
189174 it ( 'passes posix paths to the plugin' , ( ) => {
190- const buildContext = generateBuildContext ( {
191- dir : 'C:\\my\\windows\\project\\dir' ,
192- nextjsConfig : { distDir : '.dist\\v1' } ,
193- isServer : false ,
194- } ) ;
195- const generatedPluginOptions = getWebpackPluginOptions ( buildContext , { widenClientFileUpload : true } , undefined ) ;
175+ const generatedPluginOptions = getBuildPluginOptions (
176+ { widenClientFileUpload : true } ,
177+ undefined ,
178+ 'webpack-client' ,
179+ 'C:\\my\\windows\\project\\dir\\.dist\\v1' ,
180+ ) ;
196181 expect ( generatedPluginOptions . sourcemaps ) . toMatchObject ( {
197182 assets : [ 'C:/my/windows/project/dir/.dist/v1/static/chunks/**' ] ,
198183 ignore : [
@@ -206,8 +191,7 @@ describe('getWebpackPluginOptions()', () => {
206191 } ) ;
207192
208193 it ( 'sets options to not create a release or do any release operations when releaseName is undefined' , ( ) => {
209- const buildContext = generateBuildContext ( { isServer : false } ) ;
210- const generatedPluginOptions = getWebpackPluginOptions ( buildContext , { } , undefined ) ;
194+ const generatedPluginOptions = getBuildPluginOptions ( { } , undefined , 'webpack-client' , '/my/project/dir/.next' ) ;
211195
212196 expect ( generatedPluginOptions ) . toMatchObject ( {
213197 release : {
0 commit comments