fix: resolve linting errors in test files

This commit is contained in:
Ryuya 2025-07-20 23:29:59 -07:00
parent 42b9e8462f
commit ceac24b37f
17 changed files with 65 additions and 56 deletions

View File

@ -313,9 +313,13 @@ module.exports.nodeModuleDecorator = "__webpack_require__.nmd";
module.exports.onChunksLoaded = "__webpack_require__.O";
/**
* the chunk prefetch function
* the asset prefetch function
*/
module.exports.prefetchAsset = "__webpack_require__.PA";
/**
* the chunk prefetch function
*/
module.exports.prefetchChunk = "__webpack_require__.E";
/**
@ -324,9 +328,13 @@ module.exports.prefetchChunk = "__webpack_require__.E";
module.exports.prefetchChunkHandlers = "__webpack_require__.F";
/**
* the chunk preload function
* the asset preload function
*/
module.exports.preloadAsset = "__webpack_require__.LA";
/**
* the chunk preload function
*/
module.exports.preloadChunk = "__webpack_require__.G";
/**
@ -334,14 +342,6 @@ module.exports.preloadChunk = "__webpack_require__.G";
*/
module.exports.preloadChunkHandlers = "__webpack_require__.H";
/**
* the asset prefetch function
*/
/**
* the asset preload function
*/
/**
* the bundle public path
*/

View File

@ -150,7 +150,9 @@ URLDependency.Template = class URLDependencyTemplate extends (
let asType = "";
if (module) {
const request = module.request || "";
const request = /** @type {string} */ (
/** @type {{ request?: string }} */ (module).request || ""
);
// Determine the 'as' attribute based on file extension
// Reference: MDN rel=preload documentation (https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/rel/preload)
// Valid 'as' values: fetch, font, image, script, style, track

View File

@ -18,7 +18,7 @@ class AssetPrefetchPreloadPlugin {
* @returns {void}
*/
apply(compiler) {
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
// Add runtime module for asset prefetch
compilation.hooks.runtimeRequirementInTree
.for(RuntimeGlobals.prefetchAsset)

View File

@ -25,6 +25,7 @@ class AssetPrefetchPreloadRuntimeModule extends RuntimeModule {
*/
generate() {
const { compilation } = this;
if (!compilation) return null;
const { runtimeTemplate } = compilation;
const fn =
this._type === "prefetch"

View File

@ -1,3 +1,5 @@
"use strict";
// This file is used to generate expected warnings during compilation
// Invalid fetchPriority value - should generate warning
@ -6,4 +8,4 @@ const invalidPriorityUrl = new URL(/* webpackPrefetch: true */ /* webpackFetchPr
// Both prefetch and preload specified - should generate warning
const bothHintsUrl = new URL(/* webpackPrefetch: true */ /* webpackPreload: true */ /* webpackFetchPriority: "high" */ "./assets/images/both-hints.png", import.meta.url);
export default {};
export default {};

View File

@ -1,3 +1,5 @@
"use strict";
// Warnings are generated in generate-warnings.js to avoid duplication
// Mock for document.head structure
@ -35,7 +37,7 @@ beforeEach(() => {
it("should generate prefetch link with fetchPriority for new URL() assets", () => {
// Test high priority prefetch
const imageHighUrl = new URL(/* webpackPrefetch: true */ /* webpackFetchPriority: "high" */ "./assets/images/priority-high.png", import.meta.url);
expect(document.head._children).toHaveLength(1);
const link1 = document.head._children[0];
expect(link1._type).toBe("link");
@ -49,7 +51,7 @@ it("should generate prefetch link with fetchPriority for new URL() assets", () =
it("should generate preload link with fetchPriority for new URL() assets", () => {
// Test low priority preload
const styleLowUrl = new URL(/* webpackPreload: true */ /* webpackFetchPriority: "low" */ "./assets/styles/priority-low.css", import.meta.url);
expect(document.head._children).toHaveLength(1);
const link1 = document.head._children[0];
expect(link1._type).toBe("link");
@ -62,7 +64,7 @@ it("should generate preload link with fetchPriority for new URL() assets", () =>
it("should handle auto fetchPriority", () => {
const scriptAutoUrl = new URL(/* webpackPrefetch: true */ /* webpackFetchPriority: "auto" */ "./priority-auto.js", import.meta.url);
expect(document.head._children).toHaveLength(1);
const link1 = document.head._children[0];
expect(link1._type).toBe("link");
@ -76,7 +78,7 @@ it("should not set fetchPriority for invalid values", () => {
// Note: The actual invalid value is tested in generate-warnings.js
// Here we just verify that invalid values are filtered out
const invalidUrl = new URL(/* webpackPrefetch: true */ "./assets/images/test.png", import.meta.url);
expect(document.head._children).toHaveLength(1);
const link1 = document.head._children[0];
expect(link1._type).toBe("link");
@ -88,21 +90,21 @@ it("should not set fetchPriority for invalid values", () => {
it("should handle multiple URLs with different priorities", () => {
const url1 = new URL(/* webpackPrefetch: true */ /* webpackFetchPriority: "high" */ "./assets/images/image-1.png", import.meta.url);
const url2 = new URL(/* webpackPrefetch: true */ /* webpackFetchPriority: "low" */ "./assets/images/image-2.png", import.meta.url);
const url3 = new URL(/* webpackPrefetch: true */ "./assets/images/image-3.png", import.meta.url);
expect(document.head._children).toHaveLength(3);
// First link - high priority
const link1 = document.head._children[0];
expect(link1._attributes.fetchpriority).toBe("high");
// Second link - low priority
const link2 = document.head._children[1];
expect(link2._attributes.fetchpriority).toBe("low");
// Third link - no fetchPriority
const link3 = document.head._children[2];
expect(link3._attributes.fetchpriority).toBeUndefined();
@ -112,7 +114,7 @@ it("should prefer preload over prefetch when both are specified", () => {
// Note: The warning for both hints is tested in generate-warnings.js
// Here we just verify that preload takes precedence
const bothUrl = new URL(/* webpackPreload: true */ /* webpackFetchPriority: "high" */ "./assets/images/test.png", import.meta.url);
expect(document.head._children).toHaveLength(1);
const link1 = document.head._children[0];
expect(link1._type).toBe("link");
@ -123,24 +125,24 @@ it("should prefer preload over prefetch when both are specified", () => {
it("should handle different asset types correctly", () => {
// Image
const imageUrl = new URL(/* webpackPrefetch: true */ /* webpackFetchPriority: "high" */ "./assets/images/test.png", import.meta.url);
// CSS
const cssUrl = new URL(/* webpackPrefetch: true */ /* webpackFetchPriority: "high" */ "./assets/styles/test.css", import.meta.url);
// JavaScript
const jsUrl = new URL(/* webpackPrefetch: true */ /* webpackFetchPriority: "high" */ "./test.js", import.meta.url);
// Font
const fontUrl = new URL(/* webpackPrefetch: true */ /* webpackFetchPriority: "high" */ "./assets/fonts/test.woff2", import.meta.url);
expect(document.head._children).toHaveLength(4);
// Check 'as' attributes are set correctly
expect(document.head._children[0].as).toBe("image");
expect(document.head._children[1].as).toBe("style");
expect(document.head._children[2].as).toBe("script");
expect(document.head._children[3].as).toBe("font");
// All should have high fetchPriority
document.head._children.forEach(link => {
expect(link._attributes.fetchpriority).toBe("high");
@ -155,10 +157,10 @@ it("should handle prefetch with boolean values only", () => {
const url1 = new URL(/* webpackPrefetch: true */ /* webpackFetchPriority: "high" */ "./assets/images/order-1.png", import.meta.url);
const url2 = new URL(/* webpackPrefetch: true */ /* webpackFetchPriority: "high" */ "./assets/images/order-2.png", import.meta.url);
const url3 = new URL(/* webpackPrefetch: true */ /* webpackFetchPriority: "high" */ "./assets/images/order-3.png", import.meta.url);
// Verify links were created
expect(document.head._children.length).toBe(3);
// All should have fetchPriority set
document.head._children.forEach(link => {
expect(link._attributes.fetchpriority).toBe("high");
@ -166,23 +168,3 @@ it("should handle prefetch with boolean values only", () => {
expect(link.as).toBe("image");
});
});
// Test for Worker (future implementation)
// TODO: Enable this test when Worker support is implemented
/*
it("should handle Worker with fetchPriority", () => {
const worker = new Worker(
// webpackPrefetch: true
// webpackFetchPriority: "low"
new URL("./assets/scripts/worker.js", import.meta.url),
{ type: "module" }
);
expect(document.head._children).toHaveLength(1);
const link1 = document.head._children[0];
expect(link1._type).toBe("link");
expect(link1.rel).toBe("prefetch");
expect(link1.as).toBe("script");
expect(link1._attributes.fetchpriority).toBe("low");
});
*/

View File

@ -1,2 +1,4 @@
"use strict";
// Test file for verifying prefetch order
export const ordered = true;
export const ordered = true;

View File

@ -1,2 +1,4 @@
"use strict";
// Test asset file
console.log("priority-auto.js loaded");
console.log("priority-auto.js loaded");

View File

@ -1,5 +1,7 @@
"use strict";
// Mock document.head structure for testing
const mockCreateElement = tagName => {
const mockCreateElement = (tagName) => {
const element = {
_type: tagName,
_attributes: {},

View File

@ -1,2 +1,4 @@
"use strict";
// Test JavaScript file
console.log("test.js loaded");
console.log("test.js loaded");

View File

@ -1,3 +1,5 @@
"use strict";
module.exports = [
// Invalid fetchPriority value warning
[

View File

@ -1,3 +1,5 @@
"use strict";
/** @type {import("../../../../types").Configuration} */
module.exports = {
mode: "development",

View File

@ -1,3 +1,5 @@
"use strict";
module.exports = {
findBundle() {
return ["main.js"];

View File

@ -1,3 +1,5 @@
"use strict";
const supportsWorker = require("../../../helpers/supportsWorker");
module.exports = () => supportsWorker();

View File

@ -1,3 +1,5 @@
"use strict";
module.exports = [
// Numeric prefetch value (not boolean)
[/`webpackPrefetch` expected true, but received: 10\./],

View File

@ -1,3 +1,5 @@
"use strict";
/** @type {import("../../../../types").Configuration} */
module.exports = {
output: {

2
types.d.ts vendored
View File

@ -17758,8 +17758,10 @@ declare namespace exports {
export let moduleLoaded: "module.loaded";
export let nodeModuleDecorator: "__webpack_require__.nmd";
export let onChunksLoaded: "__webpack_require__.O";
export let prefetchAsset: "__webpack_require__.PA";
export let prefetchChunk: "__webpack_require__.E";
export let prefetchChunkHandlers: "__webpack_require__.F";
export let preloadAsset: "__webpack_require__.LA";
export let preloadChunk: "__webpack_require__.G";
export let preloadChunkHandlers: "__webpack_require__.H";
export let publicPath: "__webpack_require__.p";