Skip to content

Commit

Permalink
Run tests with webpack 4 and fix them
Browse files Browse the repository at this point in the history
Also ensures that no warnings or errors are reported by webpack

# Conflicts:
#	test/cache.test.js
#	yarn.lock
  • Loading branch information
danez committed Feb 25, 2018
1 parent b9f4d60 commit 8170080
Show file tree
Hide file tree
Showing 8 changed files with 1,578 additions and 751 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,9 +1,9 @@
sudo: false
language: node_js
node_js:
- "9"
- "8"
- "6"
- "4"

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

script:
- 'if [ "$JOB" = "test" ]; then yarn test-only; fi'
- 'if [ "$JOB" = "test" ]; then yarn run test-only; fi'
- 'if [ "$JOB" = "lint" ]; then yarn run lint; fi'

after_script:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -40,7 +40,7 @@
"react-intl": "^2.1.2",
"react-intl-webpack-plugin": "^0.0.3",
"rimraf": "^2.4.3",
"webpack": "^3.0.0"
"webpack": "^4.0.0"
},
"scripts": {
"clean": "rimraf lib/",
Expand Down
67 changes: 42 additions & 25 deletions test/cache.test.js
Expand Up @@ -14,9 +14,10 @@ const outputDir = path.join(__dirname, "output/cache");
const babelLoader = path.join(__dirname, "../lib");

const globalConfig = {
mode: "development",
entry: path.join(__dirname, "fixtures/basic.js"),
module: {
loaders: [
rules: [
{
test: /\.js$/,
loader: babelLoader,
Expand Down Expand Up @@ -53,12 +54,12 @@ test.cb("should output files to cache directory", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.js$/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: t.context.cacheDirectory,
presets: ["env"],
},
Expand All @@ -67,8 +68,10 @@ test.cb("should output files to cache directory", t => {
},
});

webpack(config, err => {
webpack(config, (err, stats) => {
t.is(err, null);
t.is(stats.compilation.errors.length, 0);
t.is(stats.compilation.warnings.length, 0);

fs.readdir(t.context.cacheDirectory, (err, files) => {
t.is(err, null);
Expand All @@ -86,12 +89,12 @@ test.cb.serial(
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: true,
presets: ["env"],
},
Expand All @@ -100,8 +103,10 @@ test.cb.serial(
},
});

webpack(config, err => {
webpack(config, (err, stats) => {
t.is(err, null);
t.is(stats.compilation.errors.length, 0);
t.is(stats.compilation.warnings.length, 0);

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

webpack(config, err => {
webpack(config, (err, stats) => {
t.is(err, null);
t.is(stats.compilation.errors.length, 0);
t.is(stats.compilation.warnings.length, 0);

fs.readdir(defaultCacheDir, (err, files) => {
files = files.filter(file => /\b[0-9a-f]{5,40}\.json\.gz\b/.test(file));
Expand All @@ -152,12 +159,12 @@ test.cb.skip("should read from cache directory if cached file exists", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: t.context.cacheDirectory,
presets: ["env"],
},
Expand All @@ -168,8 +175,10 @@ test.cb.skip("should read from cache directory if cached file exists", t => {

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

webpack(config, err => {
t.is(err, null);
Expand All @@ -188,12 +197,12 @@ test.cb("should have one file per module", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: t.context.cacheDirectory,
presets: ["env"],
},
Expand All @@ -202,8 +211,10 @@ test.cb("should have one file per module", t => {
},
});

webpack(config, err => {
webpack(config, (err, stats) => {
t.is(err, null);
t.is(stats.compilation.errors.length, 0);
t.is(stats.compilation.warnings.length, 0);

fs.readdir(t.context.cacheDirectory, (err, files) => {
t.is(err, null);
Expand All @@ -220,12 +231,12 @@ test.cb("should generate a new file if the identifier changes", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: t.context.cacheDirectory,
cacheIdentifier: "a",
presets: ["env"],
Expand All @@ -239,12 +250,12 @@ test.cb("should generate a new file if the identifier changes", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: t.context.cacheDirectory,
cacheIdentifier: "b",
presets: ["env"],
Expand All @@ -257,8 +268,10 @@ test.cb("should generate a new file if the identifier changes", t => {
let counter = configs.length;

configs.forEach(config => {
webpack(config, err => {
webpack(config, (err, stats) => {
t.is(err, null);
t.is(stats.compilation.errors.length, 0);
t.is(stats.compilation.warnings.length, 0);
counter -= 1;

if (!counter) {
Expand All @@ -280,12 +293,12 @@ test.cb("should allow to specify the .babelrc file", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: t.context.cacheDirectory,
babelrc: path.join(__dirname, "fixtures/babelrc"),
presets: ["env"],
Expand All @@ -300,12 +313,12 @@ test.cb("should allow to specify the .babelrc file", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: t.context.cacheDirectory,
presets: ["env"],
},
Expand All @@ -315,8 +328,12 @@ test.cb("should allow to specify the .babelrc file", t => {
}),
];

webpack(config, err => {
webpack(config, (err, multiStats) => {
t.is(err, null);
t.is(multiStats.stats[0].compilation.errors.length, 0);
t.is(multiStats.stats[0].compilation.warnings.length, 0);
t.is(multiStats.stats[1].compilation.errors.length, 0);
t.is(multiStats.stats[1].compilation.warnings.length, 0);

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

0 comments on commit 8170080

Please sign in to comment.