Skip to content

Commit 416a747

Browse files
committed
Run tests with webpack 4 and fix them
Also ensures that no warnings or errors are reported by webpack
1 parent 537226d commit 416a747

File tree

8 files changed

+833
-210
lines changed

8 files changed

+833
-210
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
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

package.json

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

test/cache.test.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ 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: {
1920
rules: [
@@ -69,8 +70,8 @@ test.cb("should output files to cache directory", t => {
6970

7071
webpack(config, (err, stats) => {
7172
t.is(err, null);
72-
t.deepEqual(stats.compilation.errors, []);
73-
t.deepEqual(stats.compilation.warnings, []);
73+
t.is(stats.compilation.errors.length, 0);
74+
t.is(stats.compilation.warnings.length, 0);
7475

7576
fs.readdir(t.context.cacheDirectory, (err, files) => {
7677
t.is(err, null);
@@ -104,8 +105,8 @@ test.cb.serial(
104105

105106
webpack(config, (err, stats) => {
106107
t.is(err, null);
107-
t.deepEqual(stats.compilation.errors, []);
108-
t.deepEqual(stats.compilation.warnings, []);
108+
t.is(stats.compilation.errors.length, 0);
109+
t.is(stats.compilation.warnings.length, 0);
109110

110111
fs.readdir(defaultCacheDir, (err, files) => {
111112
files = files.filter(file => /\b[0-9a-f]{5,40}\.json\.gz\b/.test(file));
@@ -138,8 +139,8 @@ test.cb.serial(
138139

139140
webpack(config, (err, stats) => {
140141
t.is(err, null);
141-
t.deepEqual(stats.compilation.errors, []);
142-
t.deepEqual(stats.compilation.warnings, []);
142+
t.is(stats.compilation.errors.length, 0);
143+
t.is(stats.compilation.warnings.length, 0);
143144

144145
fs.readdir(defaultCacheDir, (err, files) => {
145146
files = files.filter(file => /\b[0-9a-f]{5,40}\.json\.gz\b/.test(file));
@@ -177,8 +178,8 @@ test.cb.skip("should read from cache directory if cached file exists", t => {
177178
// Istanbul for coverage.
178179
webpack(config, (err, stats) => {
179180
t.is(err, null);
180-
t.deepEqual(stats.compilation.errors, []);
181-
t.deepEqual(stats.compilation.warnings, []);
181+
t.is(stats.compilation.errors.length, 0);
182+
t.is(stats.compilation.warnings.length, 0);
182183

183184
webpack(config, err => {
184185
t.is(err, null);
@@ -213,8 +214,8 @@ test.cb("should have one file per module", t => {
213214

214215
webpack(config, (err, stats) => {
215216
t.is(err, null);
216-
t.deepEqual(stats.compilation.errors, []);
217-
t.deepEqual(stats.compilation.warnings, []);
217+
t.is(stats.compilation.errors.length, 0);
218+
t.is(stats.compilation.warnings.length, 0);
218219

219220
fs.readdir(t.context.cacheDirectory, (err, files) => {
220221
t.is(err, null);
@@ -270,8 +271,8 @@ test.cb("should generate a new file if the identifier changes", t => {
270271
configs.forEach(config => {
271272
webpack(config, (err, stats) => {
272273
t.is(err, null);
273-
t.deepEqual(stats.compilation.errors, []);
274-
t.deepEqual(stats.compilation.warnings, []);
274+
t.is(stats.compilation.errors.length, 0);
275+
t.is(stats.compilation.warnings.length, 0);
275276
counter -= 1;
276277

277278
if (!counter) {
@@ -331,10 +332,10 @@ test.cb("should allow to specify the .babelrc file", t => {
331332

332333
webpack(config, (err, multiStats) => {
333334
t.is(err, null);
334-
t.deepEqual(multiStats.stats[0].compilation.errors, []);
335-
t.deepEqual(multiStats.stats[0].compilation.warnings, []);
336-
t.deepEqual(multiStats.stats[1].compilation.errors, []);
337-
t.deepEqual(multiStats.stats[1].compilation.warnings, []);
335+
t.is(multiStats.stats[0].compilation.errors.length, 0);
336+
t.is(multiStats.stats[0].compilation.warnings.length, 0);
337+
t.is(multiStats.stats[1].compilation.errors.length, 0);
338+
t.is(multiStats.stats[1].compilation.warnings.length, 0);
338339

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

test/loader.test.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import createTestDirectory from "./helpers/createTestDirectory";
88
const outputDir = path.join(__dirname, "output/loader");
99
const babelLoader = path.join(__dirname, "../lib");
1010
const globalConfig = {
11+
mode: "development",
1112
entry: path.join(__dirname, "fixtures/basic.js"),
1213
module: {
1314
rules: [
@@ -42,8 +43,10 @@ test.cb("should transpile the code snippet", t => {
4243
},
4344
});
4445

45-
webpack(config, err => {
46+
webpack(config, (err, stats) => {
4647
t.is(err, null);
48+
t.is(stats.compilation.errors.length, 0);
49+
t.is(stats.compilation.warnings.length, 0);
4750

4851
fs.readdir(t.context.directory, (err, files) => {
4952
t.is(err, null);
@@ -72,13 +75,15 @@ test.cb("should not throw error on syntax error", t => {
7275
webpack(config, (err, stats) => {
7376
t.true(stats.compilation.errors.length === 1);
7477
t.true(stats.compilation.errors[0] instanceof Error);
78+
t.is(stats.compilation.warnings.length, 0);
7579

7680
t.end();
7781
});
7882
});
7983

8084
test.cb("should use correct env", t => {
8185
const config = {
86+
mode: "development",
8287
entry: path.join(__dirname, "fixtures/basic.js"),
8388
output: {
8489
path: t.context.directory,
@@ -108,7 +113,8 @@ test.cb("should use correct env", t => {
108113
webpack(config, (err, stats) => {
109114
t.is(err, null);
110115

111-
t.true(stats.compilation.errors.length === 1);
116+
t.is(stats.compilation.errors.length, 1);
117+
t.is(stats.compilation.warnings.length, 0);
112118

113119
t.truthy(stats.compilation.errors[0].message.match(/es2015abc/));
114120
t.falsy(stats.compilation.errors[0].message.match(/es2015xyz/));
@@ -121,6 +127,7 @@ test.serial.cb("should not polute BABEL_ENV after using forceEnv", t => {
121127
const initialBabelEnv = process.env.BABEL_ENV;
122128

123129
const config = {
130+
mode: "development",
124131
entry: path.join(__dirname, "fixtures/basic.js"),
125132
output: {
126133
path: t.context.directory,
@@ -134,7 +141,7 @@ test.serial.cb("should not polute BABEL_ENV after using forceEnv", t => {
134141
forceEnv: "testenv",
135142
env: {
136143
testenv: {
137-
presets: ["es2015"],
144+
presets: ["@babel/env"],
138145
},
139146
},
140147
},
@@ -144,7 +151,9 @@ test.serial.cb("should not polute BABEL_ENV after using forceEnv", t => {
144151
},
145152
};
146153

147-
webpack(config, () => {
154+
webpack(config, (err, stats) => {
155+
t.is(stats.compilation.errors.length, 0);
156+
t.is(stats.compilation.warnings.length, 0);
148157
t.truthy(process.env.BABEL_ENV === initialBabelEnv);
149158
t.end();
150159
});
@@ -156,6 +165,7 @@ test.serial.cb(
156165
const initialBabelEnv = process.env.BABEL_ENV;
157166

158167
const config = {
168+
mode: "development",
159169
entry: path.join(__dirname, "fixtures/basic.js"),
160170
output: {
161171
path: t.context.directory,
@@ -179,7 +189,11 @@ test.serial.cb(
179189
},
180190
};
181191

182-
webpack(config, () => {
192+
webpack(config, (err, stats) => {
193+
t.is(err, null);
194+
t.is(stats.compilation.errors.length, 1);
195+
t.is(stats.compilation.warnings.length, 0);
196+
183197
t.truthy(process.env.BABEL_ENV === initialBabelEnv);
184198
t.end();
185199
});
@@ -192,6 +206,7 @@ test.serial.cb("should not change BABEL_ENV when using forceEnv", t => {
192206
process.env.BABEL_ENV = "nontestenv";
193207

194208
const config = {
209+
mode: "development",
195210
entry: path.join(__dirname, "fixtures/basic.js"),
196211
output: {
197212
path: t.context.directory,
@@ -221,7 +236,8 @@ test.serial.cb("should not change BABEL_ENV when using forceEnv", t => {
221236
webpack(config, (err, stats) => {
222237
t.is(err, null);
223238

224-
t.true(stats.compilation.errors.length === 1);
239+
t.is(stats.compilation.errors.length, 1);
240+
t.is(stats.compilation.warnings.length, 0);
225241

226242
t.truthy(stats.compilation.errors[0].message.match(/es2015abc/));
227243
t.falsy(stats.compilation.errors[0].message.match(/es2015xyz/));
@@ -240,6 +256,7 @@ test.serial.cb("should not change BABEL_ENV when using forceEnv", t => {
240256

241257
test.cb("should not throw without config", t => {
242258
const config = {
259+
mode: "development",
243260
entry: path.join(__dirname, "fixtures/basic.js"),
244261
output: {
245262
path: t.context.directory,
@@ -257,8 +274,8 @@ test.cb("should not throw without config", t => {
257274

258275
webpack(config, (err, stats) => {
259276
t.is(err, null);
260-
261-
t.true(stats.compilation.errors.length === 0);
277+
t.is(stats.compilation.errors.length, 0);
278+
t.is(stats.compilation.warnings.length, 0);
262279

263280
t.end();
264281
});
@@ -274,6 +291,8 @@ test.cb(
274291
},
275292
});
276293
webpack(config, (err, stats) => {
294+
t.is(err, null);
295+
t.is(stats.compilation.warnings.length, 0);
277296
const moduleBuildError = stats.compilation.errors[0];
278297
const babelLoaderError = moduleBuildError.error;
279298
t.regex(babelLoaderError.stack, /Unexpected character/);

test/metadata.test.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const cacheDir = path.join(__dirname, "output/cache/cachefiles");
1212
const outputDir = path.join(__dirname, "output/metadata");
1313
const babelLoader = path.join(__dirname, "../lib");
1414
const globalConfig = {
15+
mode: "development",
1516
entry: "./test/fixtures/metadata.js",
1617
output: {
1718
path: outputDir,
@@ -54,8 +55,10 @@ test.cb("should pass metadata code snippet", t => {
5455
},
5556
});
5657

57-
webpack(config, err => {
58+
webpack(config, (err, stats) => {
5859
t.is(err, null);
60+
t.is(stats.compilation.errors.length, 0);
61+
t.is(stats.compilation.warnings.length, 0);
5962

6063
fs.readdir(t.context.directory, (err, files) => {
6164
t.is(err, null);
@@ -87,6 +90,7 @@ test.cb("should not throw error", t => {
8790
webpack(config, (err, stats) => {
8891
t.is(err, null);
8992
t.is(stats.compilation.errors.length, 0);
93+
t.is(stats.compilation.warnings.length, 0);
9094
t.end();
9195
});
9296
});
@@ -103,6 +107,7 @@ test.cb("should throw error", t => {
103107
webpack(config, (err, stats) => {
104108
t.is(err, null);
105109
t.true(stats.compilation.errors.length > 0);
110+
t.is(stats.compilation.warnings.length, 0);
106111
t.end();
107112
});
108113
});
@@ -130,8 +135,10 @@ test.cb("should pass metadata code snippet ( cache version )", t => {
130135
},
131136
});
132137

133-
webpack(config, err => {
138+
webpack(config, (err, stats) => {
134139
t.is(err, null);
140+
t.is(stats.compilation.errors.length, 0);
141+
t.is(stats.compilation.warnings.length, 0);
135142

136143
fs.readdir(t.context.directory, (err, files) => {
137144
t.is(err, null);

test/options.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import createTestDirectory from "./helpers/createTestDirectory";
88
const outputDir = path.join(__dirname, "output/options");
99
const babelLoader = path.join(__dirname, "../lib");
1010
const globalConfig = {
11+
mode: "development",
1112
entry: path.join(__dirname, "fixtures/basic.js"),
1213
module: {
1314
rules: [
@@ -41,15 +42,17 @@ test.cb("should interpret options given to the loader", t => {
4142
rules: [
4243
{
4344
test: /\.jsx?/,
44-
loader: babelLoader + "?presets[]=env",
45+
loader: babelLoader + "?presets[]=@babel/env",
4546
exclude: /node_modules/,
4647
},
4748
],
4849
},
4950
});
5051

51-
webpack(config, err => {
52+
webpack(config, (err, stats) => {
5253
t.is(err, null);
54+
t.is(stats.compilation.errors.length, 0);
55+
t.is(stats.compilation.warnings.length, 0);
5356

5457
fs.readdir(outputDir, (err, files) => {
5558
t.is(err, null);

test/sourcemaps.test.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import createTestDirectory from "./helpers/createTestDirectory";
88
const outputDir = path.join(__dirname, "output/sourcemaps");
99
const babelLoader = path.join(__dirname, "../lib");
1010
const globalConfig = {
11+
mode: "development",
1112
entry: path.join(__dirname, "fixtures/basic.js"),
1213
module: {
1314
rules: [
@@ -42,15 +43,17 @@ test.cb("should output webpack's sourcemap", t => {
4243
rules: [
4344
{
4445
test: /\.jsx?/,
45-
loader: babelLoader + "?presets[]=env",
46+
loader: babelLoader + "?presets[]=@babel/env",
4647
exclude: /node_modules/,
4748
},
4849
],
4950
},
5051
});
5152

52-
webpack(config, err => {
53+
webpack(config, (err, stats) => {
5354
t.is(err, null);
55+
t.is(stats.compilation.errors.length, 0);
56+
t.is(stats.compilation.warnings.length, 0);
5457

5558
fs.readdir(t.context.directory, (err, files) => {
5659
t.is(err, null);
@@ -59,11 +62,13 @@ test.cb("should output webpack's sourcemap", t => {
5962

6063
t.true(map.length > 0);
6164

62-
fs.readFile(path.resolve(t.context.directory, map[0]), (err, data) => {
63-
t.is(err, null);
64-
t.not(data.toString().indexOf("webpack:///"), -1);
65-
t.end();
66-
});
65+
if (map.length > 0) {
66+
fs.readFile(path.resolve(t.context.directory, map[0]), (err, data) => {
67+
t.is(err, null);
68+
t.not(data.toString().indexOf("webpack:///"), -1);
69+
t.end();
70+
});
71+
}
6772
});
6873
});
6974
});

0 commit comments

Comments
 (0)