mirror of https://github.com/webpack/webpack.git
Add test
This commit is contained in:
parent
f378471064
commit
0414fd4f1c
|
@ -35,13 +35,13 @@ const {
|
|||
intersectRuntime
|
||||
} = require("./util/runtime");
|
||||
|
||||
const ChunkRenderError = require("./ChunkRenderError");
|
||||
const {
|
||||
JAVASCRIPT_MODULE_TYPE_AUTO,
|
||||
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
||||
JAVASCRIPT_MODULE_TYPE_ESM,
|
||||
WEBPACK_MODULE_TYPE_RUNTIME
|
||||
} = require("./ModuleTypeConstants");
|
||||
const ChunkRenderError = require("./ChunkRenderError");
|
||||
|
||||
/** @typedef {import("estree").CallExpression} CallExpression */
|
||||
/** @typedef {import("estree").Expression} Expression */
|
||||
|
|
|
@ -550,6 +550,9 @@ module.exports = mergeExports(fn, {
|
|||
css: {
|
||||
get CssModulesPlugin() {
|
||||
return require("./css/CssModulesPlugin");
|
||||
},
|
||||
get CssModule() {
|
||||
return require("./CssModule");
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
module.exports = [
|
||||
[
|
||||
// main.js render error
|
||||
/Failed/
|
||||
],
|
||||
[
|
||||
// main.hot-update.js render error
|
||||
/Failed/
|
||||
]
|
||||
];
|
|
@ -0,0 +1,7 @@
|
|||
.html {
|
||||
color: red;
|
||||
}
|
||||
---
|
||||
html {
|
||||
color: blue;
|
||||
}Failed
|
|
@ -0,0 +1,12 @@
|
|||
import "./index.css";
|
||||
|
||||
it("should work", done => {
|
||||
const links = window.document.getElementsByTagName("link");
|
||||
expect(links[0].sheet.css).toContain("color: red;");
|
||||
NEXT(
|
||||
require("../../update")(done, true, () => {
|
||||
const links = window.document.getElementsByTagName("link");
|
||||
expect(links[0].sheet.css).toContain("color: blue;");
|
||||
})
|
||||
);
|
||||
});
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (config) {
|
||||
return config.target === "web";
|
||||
};
|
|
@ -0,0 +1,39 @@
|
|||
const webpack = require("../../../../");
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
entry: ["./index.js"],
|
||||
experiments: {
|
||||
css: true
|
||||
},
|
||||
plugins: [
|
||||
{
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("Test", compilation => {
|
||||
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
||||
"Test",
|
||||
(module, set, context) => {
|
||||
// To prevent the runtime error `ReferenceError: __webpack_exports__ is not defined`,
|
||||
// which occurs because the default `output.library` setting is `commonjs2`,
|
||||
// resulting in adding `module.exports = __webpack_exports__;`.
|
||||
set.add(webpack.RuntimeGlobals.startup);
|
||||
set.add(webpack.RuntimeGlobals.exports);
|
||||
}
|
||||
);
|
||||
|
||||
webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(
|
||||
compilation
|
||||
).renderModuleContent.tap("Test", (source, module) => {
|
||||
if (module instanceof webpack.css.CssModule && module.hot) {
|
||||
const s = module._source.source();
|
||||
if (s.includes("Failed")) {
|
||||
throw new Error("Failed");
|
||||
}
|
||||
}
|
||||
return source;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
|
@ -906,6 +906,12 @@ declare abstract class ByTypeGenerator extends Generator {
|
|||
) => null | Source;
|
||||
}
|
||||
declare const CIRCULAR_CONNECTION: unique symbol;
|
||||
type CSSModuleCreateData = NormalModuleCreateData & {
|
||||
cssLayer: CssLayer;
|
||||
supports: Supports;
|
||||
media: Media;
|
||||
inheritance: [CssLayer, Supports, Media][];
|
||||
};
|
||||
declare class Cache {
|
||||
constructor();
|
||||
hooks: {
|
||||
|
@ -3278,11 +3284,16 @@ declare interface CssLoadingRuntimeModulePluginHooks {
|
|||
linkPreload: SyncWaterfallHook<[string, Chunk]>;
|
||||
linkPrefetch: SyncWaterfallHook<[string, Chunk]>;
|
||||
}
|
||||
declare abstract class CssModule extends NormalModule {
|
||||
declare class CssModule extends NormalModule {
|
||||
constructor(options: CSSModuleCreateData);
|
||||
cssLayer: CssLayer;
|
||||
supports: Supports;
|
||||
media: Media;
|
||||
inheritance: [CssLayer, Supports, Media][];
|
||||
static deserialize(context: ObjectDeserializerContext): CssModule;
|
||||
static getCompilationHooks(
|
||||
compilation: Compilation
|
||||
): NormalModuleCompilationHooks;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16550,7 +16561,7 @@ declare namespace exports {
|
|||
export { AsyncWebAssemblyModulesPlugin, EnableWasmLoadingPlugin };
|
||||
}
|
||||
export namespace css {
|
||||
export { CssModulesPlugin };
|
||||
export { CssModulesPlugin, CssModule };
|
||||
}
|
||||
export namespace library {
|
||||
export { AbstractLibraryPlugin, EnableLibraryPlugin };
|
||||
|
|
Loading…
Reference in New Issue