|
2 | 2 |
|
3 | 3 | const fs = require("node:fs"); |
4 | 4 | const path = require("node:path"); |
| 5 | +const url = require("node:url"); |
5 | 6 | const { isWindows, processKill, run, runWatch } = require("../../utils/test-utils"); |
6 | 7 |
|
7 | 8 | describe("cache", () => { |
@@ -219,6 +220,145 @@ describe("cache", () => { |
219 | 220 | expect(stdout).toBeTruthy(); |
220 | 221 | }); |
221 | 222 |
|
| 223 | + it("should work with relative path to configuration without build dependencies", async () => { |
| 224 | + fs.rmSync( |
| 225 | + path.join( |
| 226 | + __dirname, |
| 227 | + "../../../node_modules/.cache/webpack/no-build-dependencies-development", |
| 228 | + ), |
| 229 | + { recursive: true, force: true }, |
| 230 | + ); |
| 231 | + |
| 232 | + let { exitCode, stderr, stdout } = await run(__dirname, [ |
| 233 | + "-c", |
| 234 | + "./no-build-dependencies.config.js", |
| 235 | + ]); |
| 236 | + |
| 237 | + expect(exitCode).toBe(0); |
| 238 | + expect(stderr.match(/No pack exists at/g)).toHaveLength(1); |
| 239 | + expect(stderr.match(/Stored pack/g)).toHaveLength(1); |
| 240 | + expect(stderr).toBeTruthy(); |
| 241 | + expect(stdout).toBeTruthy(); |
| 242 | + |
| 243 | + ({ exitCode, stderr, stdout } = await run(__dirname, [ |
| 244 | + "-c", |
| 245 | + "./no-build-dependencies.config.js", |
| 246 | + ])); |
| 247 | + |
| 248 | + expect(exitCode).toBe(0); |
| 249 | + expect(stderr.match(/restore cache container:/g)).toHaveLength(1); |
| 250 | + expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1); |
| 251 | + expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1); |
| 252 | + expect(stderr).toBeTruthy(); |
| 253 | + expect(stdout).toBeTruthy(); |
| 254 | + }); |
| 255 | + |
| 256 | + it("should work with file path to configuration without build dependencies", async () => { |
| 257 | + fs.rmSync( |
| 258 | + path.join( |
| 259 | + __dirname, |
| 260 | + "../../../node_modules/.cache/webpack/no-build-dependencies-file-development", |
| 261 | + ), |
| 262 | + { recursive: true, force: true }, |
| 263 | + ); |
| 264 | + |
| 265 | + let { exitCode, stderr, stdout } = await run(__dirname, [ |
| 266 | + "-c", |
| 267 | + path.resolve(__dirname, "./no-build-dependencies-file.config.js"), |
| 268 | + ]); |
| 269 | + |
| 270 | + expect(exitCode).toBe(0); |
| 271 | + expect(stderr.match(/No pack exists at/g)).toHaveLength(1); |
| 272 | + expect(stderr.match(/Stored pack/g)).toHaveLength(1); |
| 273 | + expect(stderr).toBeTruthy(); |
| 274 | + expect(stdout).toBeTruthy(); |
| 275 | + |
| 276 | + ({ exitCode, stderr, stdout } = await run(__dirname, [ |
| 277 | + "-c", |
| 278 | + path.resolve(__dirname, "./no-build-dependencies-file.config.js"), |
| 279 | + ])); |
| 280 | + |
| 281 | + expect(exitCode).toBe(0); |
| 282 | + expect(stderr.match(/restore cache container:/g)).toHaveLength(1); |
| 283 | + expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1); |
| 284 | + expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1); |
| 285 | + expect(stderr).toBeTruthy(); |
| 286 | + expect(stdout).toBeTruthy(); |
| 287 | + }); |
| 288 | + |
| 289 | + it("should work with absolute path to configuration without build dependencies", async () => { |
| 290 | + fs.rmSync( |
| 291 | + path.join( |
| 292 | + __dirname, |
| 293 | + "../../../node_modules/.cache/webpack/no-build-dependencies-absolute-development", |
| 294 | + ), |
| 295 | + { recursive: true, force: true }, |
| 296 | + ); |
| 297 | + |
| 298 | + let { exitCode, stderr, stdout } = await run(__dirname, [ |
| 299 | + "-c", |
| 300 | + url |
| 301 | + .pathToFileURL(path.resolve(__dirname, "./no-build-dependencies-absolute.config.js")) |
| 302 | + .toString(), |
| 303 | + ]); |
| 304 | + |
| 305 | + expect(exitCode).toBe(0); |
| 306 | + expect(stderr.match(/No pack exists at/g)).toHaveLength(1); |
| 307 | + expect(stderr.match(/Stored pack/g)).toHaveLength(1); |
| 308 | + expect(stderr).toBeTruthy(); |
| 309 | + expect(stdout).toBeTruthy(); |
| 310 | + |
| 311 | + ({ exitCode, stderr, stdout } = await run(__dirname, [ |
| 312 | + "-c", |
| 313 | + url |
| 314 | + .pathToFileURL(path.resolve(__dirname, "./no-build-dependencies-absolute.config.js")) |
| 315 | + .toString(), |
| 316 | + ])); |
| 317 | + |
| 318 | + expect(exitCode).toBe(0); |
| 319 | + expect(stderr.match(/restore cache container:/g)).toHaveLength(1); |
| 320 | + expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1); |
| 321 | + expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1); |
| 322 | + expect(stderr).toBeTruthy(); |
| 323 | + expect(stdout).toBeTruthy(); |
| 324 | + }); |
| 325 | + |
| 326 | + it("should work with multiple configuration and merge", async () => { |
| 327 | + fs.rmSync( |
| 328 | + path.join(__dirname, "../../../node_modules/.cache/webpack/base-override-development"), |
| 329 | + { recursive: true, force: true }, |
| 330 | + ); |
| 331 | + |
| 332 | + let { exitCode, stderr, stdout } = await run(__dirname, [ |
| 333 | + "-c", |
| 334 | + "./base.config.js", |
| 335 | + "-c", |
| 336 | + url.pathToFileURL(path.resolve(__dirname, "./base-override.config.js")).toString(), |
| 337 | + "--merge", |
| 338 | + ]); |
| 339 | + |
| 340 | + expect(exitCode).toBe(0); |
| 341 | + expect(stderr.match(/No pack exists at/g)).toHaveLength(1); |
| 342 | + expect(stderr.match(/Stored pack/g)).toHaveLength(1); |
| 343 | + expect(stderr).toBeTruthy(); |
| 344 | + expect(stdout).toBeTruthy(); |
| 345 | + |
| 346 | + ({ exitCode, stderr, stdout } = await run(__dirname, [ |
| 347 | + "-c", |
| 348 | + "./base.config.js", |
| 349 | + "-c", |
| 350 | + url.pathToFileURL(path.resolve(__dirname, "./base-override.config.js")).toString(), |
| 351 | + "--merge", |
| 352 | + ])); |
| 353 | + |
| 354 | + expect(exitCode).toBe(0); |
| 355 | + expect(stderr.match(/restore cache container:/g)).toHaveLength(1); |
| 356 | + expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1); |
| 357 | + expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1); |
| 358 | + expect(stderr).toBeTruthy(); |
| 359 | + expect(stdout).toBeTruthy(); |
| 360 | + }); |
| 361 | + |
222 | 362 | if (!isWindows) { |
223 | 363 | it("should graceful shutdown", async () => { |
224 | 364 | fs.rmSync( |
|
0 commit comments