Skip to content

Commit 8170080

Browse files
committed
Run tests with webpack 4 and fix them
Also ensures that no warnings or errors are reported by webpack # Conflicts: # test/cache.test.js # yarn.lock
1 parent b9f4d60 commit 8170080

File tree

8 files changed

+1578
-751
lines changed

8 files changed

+1578
-751
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
sudo: false
22
language: node_js
33
node_js:
4+
- "9"
45
- "8"
56
- "6"
6-
- "4"
77

88
env:
99
- JOB=test
@@ -22,7 +22,7 @@ before_script:
2222
- 'if [ "$JOB" = "test" ]; then BABEL_ENV=test yarn run build; fi'
2323

2424
script:
25-
- 'if [ "$JOB" = "test" ]; then yarn test-only; fi'
25+
- 'if [ "$JOB" = "test" ]; then yarn run test-only; fi'
2626
- 'if [ "$JOB" = "lint" ]; then yarn run lint; fi'
2727

2828
after_script:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"react-intl": "^2.1.2",
4141
"react-intl-webpack-plugin": "^0.0.3",
4242
"rimraf": "^2.4.3",
43-
"webpack": "^3.0.0"
43+
"webpack": "^4.0.0"
4444
},
4545
"scripts": {
4646
"clean": "rimraf lib/",

test/cache.test.js

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ const outputDir = path.join(__dirname, "output/cache");
1414
const babelLoader = path.join(__dirname, "../lib");
1515

1616
const globalConfig = {
17+
mode: "development",
1718
entry: path.join(__dirname, "fixtures/basic.js"),
1819
module: {
19-
loaders: [
20+
rules: [
2021
{
2122
test: /\.js$/,
2223
loader: babelLoader,
@@ -53,12 +54,12 @@ test.cb("should output files to cache directory", t => {
5354
path: t.context.directory,
5455
},
5556
module: {
56-
loaders: [
57+
rules: [
5758
{
5859
test: /\.js$/,
5960
loader: babelLoader,
6061
exclude: /node_modules/,
61-
query: {
62+
options: {
6263
cacheDirectory: t.context.cacheDirectory,
6364
presets: ["env"],
6465
},
@@ -67,8 +68,10 @@ test.cb("should output files to cache directory", t => {
6768
},
6869
});
6970

70-
webpack(config, err => {
71+
webpack(config, (err, stats) => {
7172
t.is(err, null);
73+
t.is(stats.compilation.errors.length, 0);
74+
t.is(stats.compilation.warnings.length, 0);
7275

7376
fs.readdir(t.context.cacheDirectory, (err, files) => {
7477
t.is(err, null);
@@ -86,12 +89,12 @@ test.cb.serial(
8689
path: t.context.directory,
8790
},
8891
module: {
89-
loaders: [
92+
rules: [
9093
{
9194
test: /\.jsx?/,
9295
loader: babelLoader,
9396
exclude: /node_modules/,
94-
query: {
97+
options: {
9598
cacheDirectory: true,
9699
presets: ["env"],
97100
},
@@ -100,8 +103,10 @@ test.cb.serial(
100103
},
101104
});
102105

103-
webpack(config, err => {
106+
webpack(config, (err, stats) => {
104107
t.is(err, null);
108+
t.is(stats.compilation.errors.length, 0);
109+
t.is(stats.compilation.warnings.length, 0);
105110

106111
fs.readdir(defaultCacheDir, (err, files) => {
107112
files = files.filter(file => /\b[0-9a-f]{5,40}\.json\.gz\b/.test(file));
@@ -122,7 +127,7 @@ test.cb.serial(
122127
path: t.context.directory,
123128
},
124129
module: {
125-
loaders: [
130+
rules: [
126131
{
127132
test: /\.jsx?/,
128133
loader: `${babelLoader}?cacheDirectory=true&presets[]=env`,
@@ -132,8 +137,10 @@ test.cb.serial(
132137
},
133138
});
134139

135-
webpack(config, err => {
140+
webpack(config, (err, stats) => {
136141
t.is(err, null);
142+
t.is(stats.compilation.errors.length, 0);
143+
t.is(stats.compilation.warnings.length, 0);
137144

138145
fs.readdir(defaultCacheDir, (err, files) => {
139146
files = files.filter(file => /\b[0-9a-f]{5,40}\.json\.gz\b/.test(file));
@@ -152,12 +159,12 @@ test.cb.skip("should read from cache directory if cached file exists", t => {
152159
path: t.context.directory,
153160
},
154161
module: {
155-
loaders: [
162+
rules: [
156163
{
157164
test: /\.jsx?/,
158165
loader: babelLoader,
159166
exclude: /node_modules/,
160-
query: {
167+
options: {
161168
cacheDirectory: t.context.cacheDirectory,
162169
presets: ["env"],
163170
},
@@ -168,8 +175,10 @@ test.cb.skip("should read from cache directory if cached file exists", t => {
168175

169176
// @TODO Find a way to know if the file as correctly read without relying on
170177
// Istanbul for coverage.
171-
webpack(config, err => {
178+
webpack(config, (err, stats) => {
172179
t.is(err, null);
180+
t.is(stats.compilation.errors.length, 0);
181+
t.is(stats.compilation.warnings.length, 0);
173182

174183
webpack(config, err => {
175184
t.is(err, null);
@@ -188,12 +197,12 @@ test.cb("should have one file per module", t => {
188197
path: t.context.directory,
189198
},
190199
module: {
191-
loaders: [
200+
rules: [
192201
{
193202
test: /\.jsx?/,
194203
loader: babelLoader,
195204
exclude: /node_modules/,
196-
query: {
205+
options: {
197206
cacheDirectory: t.context.cacheDirectory,
198207
presets: ["env"],
199208
},
@@ -202,8 +211,10 @@ test.cb("should have one file per module", t => {
202211
},
203212
});
204213

205-
webpack(config, err => {
214+
webpack(config, (err, stats) => {
206215
t.is(err, null);
216+
t.is(stats.compilation.errors.length, 0);
217+
t.is(stats.compilation.warnings.length, 0);
207218

208219
fs.readdir(t.context.cacheDirectory, (err, files) => {
209220
t.is(err, null);
@@ -220,12 +231,12 @@ test.cb("should generate a new file if the identifier changes", t => {
220231
path: t.context.directory,
221232
},
222233
module: {
223-
loaders: [
234+
rules: [
224235
{
225236
test: /\.jsx?/,
226237
loader: babelLoader,
227238
exclude: /node_modules/,
228-
query: {
239+
options: {
229240
cacheDirectory: t.context.cacheDirectory,
230241
cacheIdentifier: "a",
231242
presets: ["env"],
@@ -239,12 +250,12 @@ test.cb("should generate a new file if the identifier changes", t => {
239250
path: t.context.directory,
240251
},
241252
module: {
242-
loaders: [
253+
rules: [
243254
{
244255
test: /\.jsx?/,
245256
loader: babelLoader,
246257
exclude: /node_modules/,
247-
query: {
258+
options: {
248259
cacheDirectory: t.context.cacheDirectory,
249260
cacheIdentifier: "b",
250261
presets: ["env"],
@@ -257,8 +268,10 @@ test.cb("should generate a new file if the identifier changes", t => {
257268
let counter = configs.length;
258269

259270
configs.forEach(config => {
260-
webpack(config, err => {
271+
webpack(config, (err, stats) => {
261272
t.is(err, null);
273+
t.is(stats.compilation.errors.length, 0);
274+
t.is(stats.compilation.warnings.length, 0);
262275
counter -= 1;
263276

264277
if (!counter) {
@@ -280,12 +293,12 @@ test.cb("should allow to specify the .babelrc file", t => {
280293
path: t.context.directory,
281294
},
282295
module: {
283-
loaders: [
296+
rules: [
284297
{
285298
test: /\.jsx?/,
286299
loader: babelLoader,
287300
exclude: /node_modules/,
288-
query: {
301+
options: {
289302
cacheDirectory: t.context.cacheDirectory,
290303
babelrc: path.join(__dirname, "fixtures/babelrc"),
291304
presets: ["env"],
@@ -300,12 +313,12 @@ test.cb("should allow to specify the .babelrc file", t => {
300313
path: t.context.directory,
301314
},
302315
module: {
303-
loaders: [
316+
rules: [
304317
{
305318
test: /\.jsx?/,
306319
loader: babelLoader,
307320
exclude: /node_modules/,
308-
query: {
321+
options: {
309322
cacheDirectory: t.context.cacheDirectory,
310323
presets: ["env"],
311324
},
@@ -315,8 +328,12 @@ test.cb("should allow to specify the .babelrc file", t => {
315328
}),
316329
];
317330

318-
webpack(config, err => {
331+
webpack(config, (err, multiStats) => {
319332
t.is(err, null);
333+
t.is(multiStats.stats[0].compilation.errors.length, 0);
334+
t.is(multiStats.stats[0].compilation.warnings.length, 0);
335+
t.is(multiStats.stats[1].compilation.errors.length, 0);
336+
t.is(multiStats.stats[1].compilation.warnings.length, 0);
320337

321338
fs.readdir(t.context.cacheDirectory, (err, files) => {
322339
t.is(err, null);

0 commit comments

Comments
 (0)