Skip to content

test: add some es-modules concatenation cases #566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ trim_trailing_whitespace = true
[*.md]
insert_final_newline = true
trim_trailing_whitespace = false

[test/cases/**]
insert_final_newline = false
3 changes: 3 additions & 0 deletions test/cases/es-module-concatenation/a.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.a {
background: red;
}
3 changes: 3 additions & 0 deletions test/cases/es-module-concatenation/b.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.b {
background: green;
}
3 changes: 3 additions & 0 deletions test/cases/es-module-concatenation/c.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.c {
background: blue;
}
12 changes: 12 additions & 0 deletions test/cases/es-module-concatenation/expected/webpack-4/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.a {
background: red;
}

.b {
background: green;
}

.c {
background: blue;
}

111 changes: 111 additions & 0 deletions test/cases/es-module-concatenation/expected/webpack-4/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);

// CONCATENATED MODULE: ./a.css
// extracted by mini-css-extract-plugin

// CONCATENATED MODULE: ./b.css
// extracted by mini-css-extract-plugin

// CONCATENATED MODULE: ./c.css
// extracted by mini-css-extract-plugin

// CONCATENATED MODULE: ./index.js





/***/ })
/******/ ]);
12 changes: 12 additions & 0 deletions test/cases/es-module-concatenation/expected/webpack-5/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.a {
background: red;
}

.b {
background: green;
}

.c {
background: blue;
}

69 changes: 69 additions & 0 deletions test/cases/es-module-concatenation/expected/webpack-5/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ([
/* 0 */
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);

// CONCATENATED MODULE: ./a.css
// extracted by mini-css-extract-plugin

// CONCATENATED MODULE: ./b.css
// extracted by mini-css-extract-plugin

// CONCATENATED MODULE: ./c.css
// extracted by mini-css-extract-plugin

// CONCATENATED MODULE: ./index.js





/***/ })
/******/ ]);
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(__webpack_module_cache__[moduleId]) {
/******/ return __webpack_module_cache__[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
/******/ // startup
/******/ // Load entry module
/******/ __webpack_require__(0);
/******/ // This entry module used 'exports' so it can't be inlined
/******/ })()
;
3 changes: 3 additions & 0 deletions test/cases/es-module-concatenation/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './a.css';
import './b.css';
import './c.css';
29 changes: 29 additions & 0 deletions test/cases/es-module-concatenation/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Self from '../../../src';

module.exports = {
entry: './index.js',
optimization: {
concatenateModules: true,
},
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: Self.loader,
options: {
esModule: true,
},
},
'css-loader',
],
},
],
},
plugins: [
new Self({
filename: '[name].css',
}),
],
};
6 changes: 6 additions & 0 deletions test/enforce-esm.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import webpack from 'webpack';

import { getCompiler, source, compile } from './helpers';

const isWebpack5 = webpack.version[0] === '5';

it('should enforce esm for empty module with options.esModule', async (done) => {
const compiler = getCompiler(
'./esm.js',
Expand All @@ -11,6 +15,7 @@ it('should enforce esm for empty module with options.esModule', async (done) =>
);
const stats = await compile(compiler);
expect(stats.hasErrors()).toBe(false);
expect(stats.compilation.modules.length).toBe(isWebpack5 ? 4 : 2);
expect(source('./simple.css', stats)).toMatchInlineSnapshot(`
"// extracted by mini-css-extract-plugin
export {};"
Expand All @@ -29,6 +34,7 @@ it('should keep empty module without options.esModule', async (done) => {
);
const stats = await compile(compiler);
expect(stats.hasErrors()).toBe(false);
expect(stats.compilation.modules.length).toBe(isWebpack5 ? 7 : 3);
expect(source('./simple.css', stats)).toMatchInlineSnapshot(
`"// extracted by mini-css-extract-plugin"`
);
Expand Down