Skip to content

Commit 63b86f0

Browse files
test: check
1 parent b5e011b commit 63b86f0

File tree

3 files changed

+225
-61
lines changed

3 files changed

+225
-61
lines changed

src/utils.js

-4
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ function normalizeSourceMap(map, requestShortener) {
164164
newMap = JSON.parse(newMap);
165165
}
166166

167-
console.log(newMap);
168-
169167
// Source maps should use forward slash because it is URLs (https://github.com/mozilla/source-map/issues/91)
170168
// We should normalize path because previous loaders like `sass-loader` using backslash when generate source map
171169

@@ -183,8 +181,6 @@ function normalizeSourceMap(map, requestShortener) {
183181
);
184182
}
185183

186-
console.log(newMap);
187-
188184
return newMap;
189185
}
190186

+218-51
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,228 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`loader should have same "contenthash" with "css-loader" and with source maps: errors 1`] = `Array []`;
4-
5-
exports[`loader should have same "contenthash" with "css-loader" and with source maps: module 1`] = `
6-
Array [
7-
"main.54b9712c1981e48c12c4.bundle.js",
8-
]
9-
`;
10-
11-
exports[`loader should have same "contenthash" with "css-loader" and with source maps: warnings 1`] = `Array []`;
12-
13-
exports[`loader should have same "contenthash" with "css-loader" and without source maps: errors 1`] = `Array []`;
14-
15-
exports[`loader should have same "contenthash" with "css-loader" and without source maps: module 1`] = `
16-
Array [
17-
"main.b38d5f87c88c55a4258e.bundle.js",
18-
]
19-
`;
20-
21-
exports[`loader should have same "contenthash" with "css-loader" and without source maps: warnings 1`] = `Array []`;
22-
23-
exports[`loader should have same "contenthash" with "postcss-loader" and with source maps: errors 1`] = `Array []`;
24-
25-
exports[`loader should have same "contenthash" with "postcss-loader" and with source maps: module 1`] = `
26-
Array [
27-
"main.d77dd6564bc6e6297cd4.bundle.js",
28-
]
29-
`;
30-
31-
exports[`loader should have same "contenthash" with "postcss-loader" and with source maps: warnings 1`] = `Array []`;
32-
33-
exports[`loader should have same "contenthash" with "postcss-loader" and without source maps: errors 1`] = `Array []`;
34-
35-
exports[`loader should have same "contenthash" with "postcss-loader" and without source maps: module 1`] = `
36-
Array [
37-
"main.f8e62206a43c13393798.bundle.js",
38-
]
39-
`;
40-
41-
exports[`loader should have same "contenthash" with "postcss-loader" and without source maps: warnings 1`] = `Array []`;
42-
433
exports[`loader should have same "contenthash" with "sass-loader" and with source maps: errors 1`] = `Array []`;
444

455
exports[`loader should have same "contenthash" with "sass-loader" and with source maps: module 1`] = `
46-
Array [
47-
"main.151589c7e12ebfd445e7.bundle.js",
48-
]
49-
`;
6+
Object {
7+
"main.151589c7e12ebfd445e7.bundle.js": "/******/ (function(modules) { // webpackBootstrap
8+
/******/ // The module cache
9+
/******/ var installedModules = {};
10+
/******/
11+
/******/ // The require function
12+
/******/ function __webpack_require__(moduleId) {
13+
/******/
14+
/******/ // Check if module is in cache
15+
/******/ if(installedModules[moduleId]) {
16+
/******/ return installedModules[moduleId].exports;
17+
/******/ }
18+
/******/ // Create a new module (and put it into the cache)
19+
/******/ var module = installedModules[moduleId] = {
20+
/******/ i: moduleId,
21+
/******/ l: false,
22+
/******/ exports: {}
23+
/******/ };
24+
/******/
25+
/******/ // Execute the module function
26+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
27+
/******/
28+
/******/ // Flag the module as loaded
29+
/******/ module.l = true;
30+
/******/
31+
/******/ // Return the exports of the module
32+
/******/ return module.exports;
33+
/******/ }
34+
/******/
35+
/******/
36+
/******/ // expose the modules object (__webpack_modules__)
37+
/******/ __webpack_require__.m = modules;
38+
/******/
39+
/******/ // expose the module cache
40+
/******/ __webpack_require__.c = installedModules;
41+
/******/
42+
/******/ // define getter function for harmony exports
43+
/******/ __webpack_require__.d = function(exports, name, getter) {
44+
/******/ if(!__webpack_require__.o(exports, name)) {
45+
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
46+
/******/ }
47+
/******/ };
48+
/******/
49+
/******/ // define __esModule on exports
50+
/******/ __webpack_require__.r = function(exports) {
51+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
52+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
53+
/******/ }
54+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
55+
/******/ };
56+
/******/
57+
/******/ // create a fake namespace object
58+
/******/ // mode & 1: value is a module id, require it
59+
/******/ // mode & 2: merge all properties of value into the ns
60+
/******/ // mode & 4: return value when already ns object
61+
/******/ // mode & 8|1: behave like require
62+
/******/ __webpack_require__.t = function(value, mode) {
63+
/******/ if(mode & 1) value = __webpack_require__(value);
64+
/******/ if(mode & 8) return value;
65+
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
66+
/******/ var ns = Object.create(null);
67+
/******/ __webpack_require__.r(ns);
68+
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
69+
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
70+
/******/ return ns;
71+
/******/ };
72+
/******/
73+
/******/ // getDefaultExport function for compatibility with non-harmony modules
74+
/******/ __webpack_require__.n = function(module) {
75+
/******/ var getter = module && module.__esModule ?
76+
/******/ function getDefault() { return module['default']; } :
77+
/******/ function getModuleExports() { return module; };
78+
/******/ __webpack_require__.d(getter, 'a', getter);
79+
/******/ return getter;
80+
/******/ };
81+
/******/
82+
/******/ // Object.prototype.hasOwnProperty.call
83+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
84+
/******/
85+
/******/ // __webpack_public_path__
86+
/******/ __webpack_require__.p = \\"/webpack/public/path/\\";
87+
/******/
88+
/******/
89+
/******/ // Load entry module and return exports
90+
/******/ return __webpack_require__(__webpack_require__.s = \\"./contenthash/basic-sass.js\\");
91+
/******/ })
92+
/************************************************************************/
93+
/******/ ({
94+
95+
/***/ \\"../../src/runtime/api.js\\":
96+
/*!**********************************************************************!*\\\\
97+
!*** /home/evilebottnawi/IdeaProjects/css-loader/src/runtime/api.js ***!
98+
\\\\**********************************************************************/
99+
/*! no static exports found */
100+
/***/ (function(module, exports) {
101+
102+
/*
103+
MIT License http://www.opensource.org/licenses/mit-license.php
104+
Author Tobias Koppers @sokra
105+
*/
106+
// css base code, injected by the css-loader
107+
// eslint-disable-next-line func-names
108+
module.exports = function(useSourceMap) {
109+
const list = [];
110+
111+
// return the list of modules as css string
112+
list.toString = function toString() {
113+
return this.map((item) => {
114+
const content = cssWithMappingToString(item, useSourceMap);
115+
116+
if (item[2]) {
117+
return \`@media \${item[2]} {\${content}}\`;
118+
}
119+
120+
return content;
121+
}).join('');
122+
};
123+
124+
// import a list of modules into the list
125+
// eslint-disable-next-line func-names
126+
list.i = function(modules, mediaQuery) {
127+
if (typeof modules === 'string') {
128+
// eslint-disable-next-line no-param-reassign
129+
modules = [[null, modules, '']];
130+
}
131+
132+
for (let i = 0; i < modules.length; i++) {
133+
const item = [].concat(modules[i]);
134+
135+
if (mediaQuery) {
136+
if (!item[2]) {
137+
item[2] = mediaQuery;
138+
} else {
139+
item[2] = \`\${mediaQuery} and \${item[2]}\`;
140+
}
141+
}
142+
143+
list.push(item);
144+
}
145+
};
146+
147+
return list;
148+
};
149+
150+
function cssWithMappingToString(item, useSourceMap) {
151+
const content = item[1] || '';
152+
// eslint-disable-next-line prefer-destructuring
153+
const cssMapping = item[3];
154+
155+
if (!cssMapping) {
156+
return content;
157+
}
158+
159+
if (useSourceMap && typeof btoa === 'function') {
160+
const sourceMapping = toComment(cssMapping);
161+
const sourceURLs = cssMapping.sources.map(
162+
(source) => \`/*# sourceURL=\${cssMapping.sourceRoot}\${source} */\`
163+
);
164+
165+
return [content]
166+
.concat(sourceURLs)
167+
.concat([sourceMapping])
168+
.join('\\\\n');
169+
}
170+
171+
return [content].join('\\\\n');
172+
}
173+
174+
// Adapted from convert-source-map (MIT)
175+
function toComment(sourceMap) {
176+
// eslint-disable-next-line no-undef
177+
const base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
178+
const data = \`sourceMappingURL=data:application/json;charset=utf-8;base64,\${base64}\`;
179+
180+
return \`/*# \${data} */\`;
181+
}
182+
183+
184+
/***/ }),
185+
186+
/***/ \\"./contenthash/basic-sass.js\\":
187+
/*!***********************************!*\\\\
188+
!*** ./contenthash/basic-sass.js ***!
189+
\\\\***********************************/
190+
/*! exports provided: default */
191+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
192+
193+
\\"use strict\\";
194+
__webpack_require__.r(__webpack_exports__);
195+
/* harmony import */ var _basic_scss__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./basic.scss */ \\"./contenthash/basic.scss\\");
196+
/* harmony import */ var _basic_scss__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_basic_scss__WEBPACK_IMPORTED_MODULE_0__);
197+
198+
199+
__export__ = _basic_scss__WEBPACK_IMPORTED_MODULE_0___default.a;
200+
201+
/* harmony default export */ __webpack_exports__[\\"default\\"] = (_basic_scss__WEBPACK_IMPORTED_MODULE_0___default.a);
202+
203+
204+
/***/ }),
205+
206+
/***/ \\"./contenthash/basic.scss\\":
207+
/*!********************************!*\\\\
208+
!*** ./contenthash/basic.scss ***!
209+
\\\\********************************/
210+
/*! no static exports found */
211+
/***/ (function(module, exports, __webpack_require__) {
50212
51-
exports[`loader should have same "contenthash" with "sass-loader" and with source maps: warnings 1`] = `Array []`;
213+
// Imports
214+
var ___CSS_LOADER_API_IMPORT___ = __webpack_require__(/*! ../../../src/runtime/api.js */ \\"../../src/runtime/api.js\\");
215+
exports = ___CSS_LOADER_API_IMPORT___(true);
216+
// Module
217+
exports.push([module.i, \\"a {\\\\n color: red;\\\\n}\\\\na:hover {\\\\n color: red;\\\\n}\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"/home/evilebottnawi/IdeaProjects/css-loader/test/fixtures/contenthash/basic.scss\\",\\"basic.scss\\"],\\"names\\":[],\\"mappings\\":\\"AAEA;EACE,UAHI;ACEN;ADGE;EACE,UANE;ACKN\\",\\"file\\":\\"basic.scss\\",\\"sourcesContent\\":[\\"$var: red;\\\\n\\\\na {\\\\n color: $var;\\\\n\\\\n &:hover {\\\\n color: $var;\\\\n }\\\\n}\\\\n\\",\\"a {\\\\n color: red;\\\\n}\\\\na:hover {\\\\n color: red;\\\\n}\\"]}]);
218+
// Exports
219+
module.exports = exports;
52220
53-
exports[`loader should have same "contenthash" with "sass-loader" and without source maps: errors 1`] = `Array []`;
54221
55-
exports[`loader should have same "contenthash" with "sass-loader" and without source maps: module 1`] = `
56-
Array [
57-
"main.9ae036ace8bbbebbd185.bundle.js",
58-
]
222+
/***/ })
223+
224+
/******/ });",
225+
}
59226
`;
60227
61-
exports[`loader should have same "contenthash" with "sass-loader" and without source maps: warnings 1`] = `Array []`;
228+
exports[`loader should have same "contenthash" with "sass-loader" and with source maps: warnings 1`] = `Array []`;

test/loader.test.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
getExecutedCode,
1212
getModuleSource,
1313
getWarnings,
14+
readsAssets,
1415
} from './helpers/index';
1516

1617
describe('loader', () => {
@@ -309,7 +310,7 @@ describe('loader', () => {
309310
expect(getErrors(stats)).toMatchSnapshot('errors');
310311
});
311312

312-
it.only('should have same "contenthash" with "css-loader" and without source maps', async () => {
313+
it('should have same "contenthash" with "css-loader" and without source maps', async () => {
313314
const compiler = getCompiler(
314315
'./contenthash/basic-css.js',
315316
{},
@@ -342,7 +343,7 @@ describe('loader', () => {
342343
expect(getErrors(stats)).toMatchSnapshot('errors');
343344
});
344345

345-
it.only('should have same "contenthash" with "css-loader" and with source maps', async () => {
346+
it('should have same "contenthash" with "css-loader" and with source maps', async () => {
346347
const compiler = getCompiler(
347348
'./contenthash/basic-css.js',
348349
{},
@@ -375,7 +376,7 @@ describe('loader', () => {
375376
expect(getErrors(stats)).toMatchSnapshot('errors');
376377
});
377378

378-
it.only('should have same "contenthash" with "postcss-loader" and without source maps', async () => {
379+
it('should have same "contenthash" with "postcss-loader" and without source maps', async () => {
379380
const compiler = getCompiler(
380381
'./contenthash/basic-postcss.js',
381382
{},
@@ -418,7 +419,7 @@ describe('loader', () => {
418419
expect(getErrors(stats)).toMatchSnapshot('errors');
419420
});
420421

421-
it.only('should have same "contenthash" with "postcss-loader" and with source maps', async () => {
422+
it('should have same "contenthash" with "postcss-loader" and with source maps', async () => {
422423
const compiler = getCompiler(
423424
'./contenthash/basic-postcss.js',
424425
{},
@@ -461,7 +462,7 @@ describe('loader', () => {
461462
expect(getErrors(stats)).toMatchSnapshot('errors');
462463
});
463464

464-
it.only('should have same "contenthash" with "sass-loader" and without source maps', async () => {
465+
it('should have same "contenthash" with "sass-loader" and without source maps', async () => {
465466
const compiler = getCompiler(
466467
'./contenthash/basic-sass.js',
467468
{},
@@ -558,7 +559,7 @@ describe('loader', () => {
558559
);
559560
const stats = await compile(compiler);
560561

561-
expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('module');
562+
expect(readsAssets(compiler, stats)).toMatchSnapshot('module');
562563
expect(getWarnings(stats)).toMatchSnapshot('warnings');
563564
expect(getErrors(stats)).toMatchSnapshot('errors');
564565
});

0 commit comments

Comments
 (0)