Skip to content

Commit 5c8f225

Browse files
test: improving tests
1 parent 20f6f56 commit 5c8f225

14 files changed

+234
-141
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
"eslint-config-prettier": "6.9.0",
9494
"eslint-plugin-import": "2.19.1",
9595
"eslint-plugin-prettier": "3.1.2",
96-
"execa": "^4.0.0",
9796
"file-loader": "4.3.0",
9897
"husky": "3.1.0",
9998
"jest": "24.9.0",

test/cases/insert-function/expected/26572b08b02e3c023d0d.js renamed to test/cases/insert-function/expected/1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* 1 */
44
/***/ (function(module, exports, __webpack_require__) {
55

6-
// extracted by extract-css-chunks-webpack-plugin
6+
// extracted by mini-css-extract-plugin
77

88
/***/ })
99
]]);

test/cases/insert-function/expected/main.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
/******/
4949
/******/ // script path function
5050
/******/ function jsonpScriptSrc(chunkId) {
51-
/******/ return __webpack_require__.p + "" + {"1":"26572b08b02e3c023d0d"}[chunkId] + ".js"
51+
/******/ return __webpack_require__.p + "" + ({}[chunkId]||chunkId) + ".js"
5252
/******/ }
5353
/******/
5454
/******/ // The require function
@@ -81,12 +81,12 @@
8181
/******/ var promises = [];
8282
/******/
8383
/******/
84-
/******/ // extract-css-chunks-webpack-plugin CSS loading
84+
/******/ // mini-css-extract-plugin CSS loading
8585
/******/ var cssChunks = {"1":1};
8686
/******/ if(installedCssChunks[chunkId]) promises.push(installedCssChunks[chunkId]);
8787
/******/ else if(installedCssChunks[chunkId] !== 0 && cssChunks[chunkId]) {
8888
/******/ promises.push(installedCssChunks[chunkId] = new Promise(function(resolve, reject) {
89-
/******/ var href = "" + {"1":"c4d90d38e7a606ae4d4c"}[chunkId] + ".css";
89+
/******/ var href = "" + chunkId + ".css";
9090
/******/ var fullhref = __webpack_require__.p + href;
9191
/******/ var existingLinkTags = document.getElementsByTagName("link");
9292
/******/ for(var i = 0; i < existingLinkTags.length; i++) {
@@ -114,16 +114,14 @@
114114
/******/ reject(err);
115115
/******/ };
116116
/******/ linkTag.href = fullhref;
117-
/******/ if (linkTag.href.indexOf(window.location.origin + '/') !== 0) {
118-
/******/ linkTag.crossOrigin = "anonymous";
119-
/******/ }
117+
/******/
120118
/******/ var insert = function insert(linkTag) {
121119
/******/ const reference = document.querySelector('.hot-reload');
122120
/******/
123121
/******/ if (reference) {
124122
/******/ reference.parentNode.insertBefore(linkTag, reference);
125123
/******/ }
126-
/******/ }; console.log('insert',insert)
124+
/******/ };
127125
/******/ if (typeof insert === 'function') { insert(linkTag); }
128126
/******/ else { var target = document.querySelector(function insert(linkTag) {
129127
/******/ const reference = document.querySelector('.hot-reload');
@@ -162,9 +160,7 @@
162160
/******/ script.setAttribute("nonce", __webpack_require__.nc);
163161
/******/ }
164162
/******/ script.src = jsonpScriptSrc(chunkId);
165-
/******/ if (script.src.indexOf(window.location.origin + '/') !== 0) {
166-
/******/ script.crossOrigin = "anonymous";
167-
/******/ }
163+
/******/
168164
/******/ // create error before stack unwound to get useful stacktrace later
169165
/******/ var error = new Error();
170166
/******/ onScriptComplete = function (event) {
@@ -245,7 +241,7 @@
245241
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
246242
/******/
247243
/******/ // __webpack_public_path__
248-
/******/ __webpack_require__.p = "/";
244+
/******/ __webpack_require__.p = "";
249245
/******/
250246
/******/ // on error function for async loading
251247
/******/ __webpack_require__.oe = function(err) { console.error(err); throw err; };

test/cases/insert-function/insert-function.test.js

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
const path = require('path');
2+
3+
const Self = require('../../../');
4+
5+
const ENABLE_HMR =
6+
typeof process.env.ENABLE_HMR !== 'undefined'
7+
? Boolean(process.env.ENABLE_HMR)
8+
: false;
9+
10+
const ENABLE_ES_MODULE =
11+
typeof process.env.ES_MODULE !== 'undefined'
12+
? Boolean(process.env.ES_MODULE)
13+
: false;
14+
15+
module.exports = {
16+
mode: 'development',
17+
output: {
18+
path: path.resolve(__dirname, 'expected'),
19+
chunkFilename: '[contenthash].js',
20+
publicPath: '/',
21+
crossOriginLoading: 'anonymous',
22+
},
23+
module: {
24+
rules: [
25+
{
26+
test: /\.css$/,
27+
exclude: [/\.module\.css$/i],
28+
use: [
29+
{
30+
loader: Self.loader,
31+
options: {
32+
hmr: ENABLE_HMR,
33+
},
34+
},
35+
{
36+
loader: 'css-loader',
37+
options: {
38+
esModule: ENABLE_ES_MODULE,
39+
},
40+
},
41+
],
42+
},
43+
{
44+
test: /\.module\.css$/i,
45+
use: [
46+
{
47+
loader: Self.loader,
48+
options: {
49+
hmr: ENABLE_HMR,
50+
},
51+
},
52+
{
53+
loader: 'css-loader',
54+
options: {
55+
modules: true,
56+
esModule: ENABLE_ES_MODULE,
57+
},
58+
},
59+
],
60+
},
61+
],
62+
},
63+
plugins: [
64+
new Self({
65+
filename: '[name].css',
66+
chunkFilename: '[id].css',
67+
insert: 'body',
68+
}),
69+
],
70+
devServer: {
71+
contentBase: __dirname,
72+
port: 3001,
73+
headers: {
74+
'Access-Control-Allow-Origin': '*',
75+
},
76+
},
77+
};

test/cases/insert-function/webpack.config.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/* global document */
22

3-
const path = require('path');
4-
53
const Self = require('../../../');
64

75
const ENABLE_HMR =
@@ -15,13 +13,6 @@ const ENABLE_ES_MODULE =
1513
: false;
1614

1715
module.exports = {
18-
mode: 'development',
19-
output: {
20-
path: path.resolve(__dirname, 'expected'),
21-
chunkFilename: '[contenthash].js',
22-
publicPath: '/',
23-
crossOriginLoading: 'anonymous',
24-
},
2516
module: {
2617
rules: [
2718
{
@@ -65,7 +56,7 @@ module.exports = {
6556
plugins: [
6657
new Self({
6758
filename: '[name].css',
68-
chunkFilename: '[contenthash].css',
59+
chunkFilename: '[id].css',
6960
insert: function insert(linkTag) {
7061
const reference = document.querySelector('.hot-reload');
7162
if (reference) {
@@ -74,11 +65,4 @@ module.exports = {
7465
},
7566
}),
7667
],
77-
devServer: {
78-
contentBase: `${__dirname}`,
79-
port: 3001,
80-
headers: {
81-
'Access-Control-Allow-Origin': '*',
82-
},
83-
},
8468
};

test/cases/insert-string/expected/26572b08b02e3c023d0d.js renamed to test/cases/insert-string/expected/1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* 1 */
44
/***/ (function(module, exports, __webpack_require__) {
55

6-
// extracted by extract-css-chunks-webpack-plugin
6+
// extracted by mini-css-extract-plugin
77

88
/***/ })
99
]]);

test/cases/insert-string/expected/main.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
/******/
4949
/******/ // script path function
5050
/******/ function jsonpScriptSrc(chunkId) {
51-
/******/ return __webpack_require__.p + "" + {"1":"26572b08b02e3c023d0d"}[chunkId] + ".js"
51+
/******/ return __webpack_require__.p + "" + ({}[chunkId]||chunkId) + ".js"
5252
/******/ }
5353
/******/
5454
/******/ // The require function
@@ -81,12 +81,12 @@
8181
/******/ var promises = [];
8282
/******/
8383
/******/
84-
/******/ // extract-css-chunks-webpack-plugin CSS loading
84+
/******/ // mini-css-extract-plugin CSS loading
8585
/******/ var cssChunks = {"1":1};
8686
/******/ if(installedCssChunks[chunkId]) promises.push(installedCssChunks[chunkId]);
8787
/******/ else if(installedCssChunks[chunkId] !== 0 && cssChunks[chunkId]) {
8888
/******/ promises.push(installedCssChunks[chunkId] = new Promise(function(resolve, reject) {
89-
/******/ var href = "" + {"1":"c4d90d38e7a606ae4d4c"}[chunkId] + ".css";
89+
/******/ var href = "" + chunkId + ".css";
9090
/******/ var fullhref = __webpack_require__.p + href;
9191
/******/ var existingLinkTags = document.getElementsByTagName("link");
9292
/******/ for(var i = 0; i < existingLinkTags.length; i++) {
@@ -114,10 +114,8 @@
114114
/******/ reject(err);
115115
/******/ };
116116
/******/ linkTag.href = fullhref;
117-
/******/ if (linkTag.href.indexOf(window.location.origin + '/') !== 0) {
118-
/******/ linkTag.crossOrigin = "anonymous";
119-
/******/ }
120-
/******/ var insert = "body"; console.log('insert',insert)
117+
/******/
118+
/******/ var insert = "body";
121119
/******/ if (typeof insert === 'function') { insert(linkTag); }
122120
/******/ else { var target = document.querySelector("body"); target && insert === 'body' ? target && target.insertBefore(linkTag,target.firstChild) : target.appendChild(linkTag); }
123121
/******/ }).then(function() {
@@ -150,9 +148,7 @@
150148
/******/ script.setAttribute("nonce", __webpack_require__.nc);
151149
/******/ }
152150
/******/ script.src = jsonpScriptSrc(chunkId);
153-
/******/ if (script.src.indexOf(window.location.origin + '/') !== 0) {
154-
/******/ script.crossOrigin = "anonymous";
155-
/******/ }
151+
/******/
156152
/******/ // create error before stack unwound to get useful stacktrace later
157153
/******/ var error = new Error();
158154
/******/ onScriptComplete = function (event) {
@@ -233,7 +229,7 @@
233229
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
234230
/******/
235231
/******/ // __webpack_public_path__
236-
/******/ __webpack_require__.p = "/";
232+
/******/ __webpack_require__.p = "";
237233
/******/
238234
/******/ // on error function for async loading
239235
/******/ __webpack_require__.oe = function(err) { console.error(err); throw err; };

test/cases/insert-string/inject-string.test.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)