11"use strict" ;
22
33const path = require ( "node:path" ) ;
4+ const { pathToFileURL } = require ( "node:url" ) ;
45const { run } = require ( "../../utils/test-utils" ) ;
56
67describe ( "extends property" , ( ) => {
@@ -15,6 +16,38 @@ describe("extends property", () => {
1516 expect ( stdout ) . toContain ( "mode: 'development'" ) ;
1617 } ) ;
1718
19+ it ( "extends a provided webpack config correctly using file protocol" , async ( ) => {
20+ const { exitCode, stderr, stdout } = await run ( path . resolve ( __dirname , "./file-protocol" ) ) ;
21+
22+ expect ( exitCode ) . toBe ( 0 ) ;
23+ expect ( stderr ) . toBeFalsy ( ) ;
24+ expect ( stdout ) . toContain ( "base.webpack.config.js" ) ;
25+ expect ( stdout ) . toContain ( "derived.webpack.config.js" ) ;
26+ expect ( stdout ) . toContain ( "name: 'base_config'" ) ;
27+ expect ( stdout ) . toContain ( "mode: 'development'" ) ;
28+ } ) ;
29+
30+ it ( "extends a provided webpack config correctly using `require.resolve`" , async ( ) => {
31+ const { exitCode, stderr, stdout } = await run ( path . resolve ( __dirname , "./require-resolve" ) ) ;
32+
33+ expect ( exitCode ) . toBe ( 0 ) ;
34+ expect ( stderr ) . toBeFalsy ( ) ;
35+ expect ( stdout ) . toContain ( "base.webpack.config.js" ) ;
36+ expect ( stdout ) . toContain ( "derived.webpack.config.js" ) ;
37+ expect ( stdout ) . toContain ( "name: 'base_config'" ) ;
38+ expect ( stdout ) . toContain ( "mode: 'development'" ) ;
39+ } ) ;
40+
41+ it ( "extends a provided webpack config correctly using `JSON` format" , async ( ) => {
42+ const { exitCode, stderr, stdout } = await run ( path . resolve ( __dirname , "./json" ) ) ;
43+
44+ expect ( exitCode ) . toBe ( 0 ) ;
45+ expect ( stderr ) . toBeFalsy ( ) ;
46+ expect ( stdout ) . toContain ( "derived.webpack.config.js" ) ;
47+ expect ( stdout ) . toContain ( "name: 'base_config'" ) ;
48+ expect ( stdout ) . toContain ( "mode: 'development'" ) ;
49+ } ) ;
50+
1851 it ( "extends a provided array of webpack configs correctly" , async ( ) => {
1952 const { exitCode, stderr, stdout } = await run ( path . resolve ( __dirname , "./multiple-extends" ) ) ;
2053
@@ -89,7 +122,7 @@ describe("extends property", () => {
89122 "--extends" ,
90123 "./base.webpack.config.js" ,
91124 "--extends" ,
92- "./other.config.js" ,
125+ path . resolve ( __dirname , "./multiple-configs1/ other.config.js" ) ,
93126 ] ) ;
94127
95128 expect ( exitCode ) . toBe ( 0 ) ;
@@ -102,7 +135,7 @@ describe("extends property", () => {
102135 expect ( stdout ) . toContain ( "topLevelAwait: true" ) ;
103136 } ) ;
104137
105- it ( "cLI `extends` should override `extends` in a configuration" , async ( ) => {
138+ it ( "`extends` should override `extends` in a configuration" , async ( ) => {
106139 const { exitCode, stderr, stdout } = await run ( path . resolve ( __dirname , "./simple-case" ) , [
107140 "--extends" ,
108141 "./override.config.js" ,
@@ -116,6 +149,20 @@ describe("extends property", () => {
116149 expect ( stdout ) . toContain ( "mode: 'development'" ) ;
117150 } ) ;
118151
152+ it ( "`extends` should override `extends` in a configuration using file protocol" , async ( ) => {
153+ const { exitCode, stderr, stdout } = await run ( path . resolve ( __dirname , "./simple-case" ) , [
154+ "--extends" ,
155+ pathToFileURL ( path . resolve ( __dirname , "./simple-case/override.config.js" ) ) . toString ( ) ,
156+ ] ) ;
157+
158+ expect ( exitCode ) . toBe ( 0 ) ;
159+ expect ( stderr ) . toBeFalsy ( ) ;
160+ expect ( stdout ) . toContain ( "override.config.js" ) ;
161+ expect ( stdout ) . toContain ( "derived.webpack.config.js" ) ;
162+ expect ( stdout ) . toContain ( "name: 'override_config'" ) ;
163+ expect ( stdout ) . toContain ( "mode: 'development'" ) ;
164+ } ) ;
165+
119166 it ( "should throw an error on recursive" , async ( ) => {
120167 const { exitCode, stderr, stdout } = await run ( path . resolve ( __dirname , "./recursive-extends" ) ) ;
121168
0 commit comments