Skip to content

Commit

Permalink
test: add some es-modules concatenation cases (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
irudoy committed Aug 13, 2020
1 parent e6e07bb commit 25b0ecd
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
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
@@ -0,0 +1,3 @@
.a {
background: red;
}
3 changes: 3 additions & 0 deletions test/cases/es-module-concatenation/b.css
@@ -0,0 +1,3 @@
.b {
background: green;
}
3 changes: 3 additions & 0 deletions test/cases/es-module-concatenation/c.css
@@ -0,0 +1,3 @@
.c {
background: blue;
}
12 changes: 12 additions & 0 deletions test/cases/es-module-concatenation/expected/webpack-4/main.css
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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

0 comments on commit 25b0ecd

Please sign in to comment.