Skip to content

Commit 354b48f

Browse files
test: adding and fixing broken tests
Following webpack here and getting my tests passing again
1 parent 03be38b commit 354b48f

File tree

121 files changed

+700
-66
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+700
-66
lines changed

test/TestCases.test.js

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,74 @@
1-
/* eslint-disable no-restricted-syntax, import/no-dynamic-require, global-require,
2-
no-console, no-undef, no-loop-func */
31
import fs from 'fs';
42
import path from 'path';
3+
54
import webpack from 'webpack';
65

76
describe('TestCases', () => {
87
const casesDirectory = path.resolve(__dirname, 'cases');
98
const outputDirectory = path.resolve(__dirname, 'js');
109
for (const directory of fs.readdirSync(casesDirectory)) {
1110
if (!/^(\.|_)/.test(directory)) {
11+
// eslint-disable-next-line no-loop-func
1212
it(`${directory} should compile to the expected result`, (done) => {
1313
const directoryForCase = path.resolve(casesDirectory, directory);
1414
const outputDirectoryForCase = path.resolve(outputDirectory, directory);
15-
const webpackConfig = require(path.resolve(directoryForCase, 'webpack.config.js'));
15+
// eslint-disable-next-line import/no-dynamic-require, global-require
16+
const webpackConfig = require(path.resolve(
17+
directoryForCase,
18+
'webpack.config.js'
19+
));
1620
for (const config of [].concat(webpackConfig)) {
17-
Object.assign(config, { mode: 'none', context: directoryForCase, output: Object.assign({ path: outputDirectoryForCase }, config.output) }, config);
21+
Object.assign(
22+
config,
23+
{
24+
mode: 'none',
25+
context: directoryForCase,
26+
output: Object.assign(
27+
{
28+
path: outputDirectoryForCase,
29+
},
30+
config.output
31+
),
32+
},
33+
config
34+
);
1835
}
1936
webpack(webpackConfig, (err, stats) => {
2037
if (err) {
2138
done(err);
2239
return;
2340
}
2441
done();
25-
console.log(stats.toString({ context: path.resolve(__dirname, '..'), chunks: true, chunkModules: true, modules: false }));
42+
// eslint-disable-next-line no-console
43+
console.log(
44+
stats.toString({
45+
context: path.resolve(__dirname, '..'),
46+
chunks: true,
47+
chunkModules: true,
48+
modules: false,
49+
})
50+
);
2651
if (stats.hasErrors()) {
27-
done(new Error(stats.toString({ context: path.resolve(__dirname, '..'), errorDetails: true })));
52+
done(
53+
new Error(
54+
stats.toString({
55+
context: path.resolve(__dirname, '..'),
56+
errorDetails: true,
57+
})
58+
)
59+
);
2860
return;
2961
}
3062
const expectedDirectory = path.resolve(directoryForCase, 'expected');
3163
for (const file of fs.readdirSync(expectedDirectory)) {
32-
const content = fs.readFileSync(path.resolve(expectedDirectory, file), 'utf-8');
33-
const actualContent = fs.readFileSync(path.resolve(outputDirectoryForCase, file), 'utf-8');
64+
const content = fs.readFileSync(
65+
path.resolve(expectedDirectory, file),
66+
'utf-8'
67+
);
68+
const actualContent = fs.readFileSync(
69+
path.resolve(outputDirectoryForCase, file),
70+
'utf-8'
71+
);
3472
expect(actualContent).toEqual(content);
3573
}
3674
done();

test/TestMemoryFS.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import path from 'path';
2+
3+
import MemoryFS from 'memory-fs';
4+
import webpack from 'webpack';
5+
6+
const assetsNames = (json) => json.assets.map((asset) => asset.name);
7+
8+
describe('TestMemoryFS', () => {
9+
it('should preserve asset even if not emitted', (done) => {
10+
const casesDirectory = path.resolve(__dirname, 'cases');
11+
const directoryForCase = path.resolve(casesDirectory, 'simple-publicpath');
12+
const webpackConfig = require(path.resolve(
13+
directoryForCase,
14+
'webpack.config.js'
15+
));
16+
const compiler = webpack({
17+
...webpackConfig,
18+
mode: 'development',
19+
context: directoryForCase,
20+
cache: false,
21+
});
22+
compiler.outputFileSystem = new MemoryFS();
23+
compiler.run((err1, stats1) => {
24+
if (err1) {
25+
done(err1);
26+
return;
27+
}
28+
compiler.run((err2, stats2) => {
29+
if (err2) {
30+
done(err2);
31+
return;
32+
}
33+
expect(assetsNames(stats1.toJson())).toEqual(
34+
assetsNames(stats2.toJson())
35+
);
36+
done();
37+
});
38+
});
39+
});
40+
});

test/cases/at-import/a.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@import './ae.css';
2+
@import './aa.css';
3+
@import './ab.css';
4+
@import './ac.css';
5+
@import './ad.css';
6+
7+
body {
8+
background: red;
9+
}

test/cases/at-import/aa.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.aa {
2+
background: green;
3+
}

test/cases/at-import/ab.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.ab {
2+
background: green;
3+
}

test/cases/at-import/ac.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.ac {
2+
background: green;
3+
}

test/cases/at-import/ad.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.ad {
2+
background: green;
3+
}

test/cases/at-import/ae.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.ae {
2+
background: green;
3+
}

test/cases/at-import/b.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@import './ba.css';
2+
@import './bb.css';
3+
4+
body {
5+
background: yellow;
6+
}

test/cases/at-import/ba.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.ba {
2+
background: green;
3+
}

test/cases/at-import/bb.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.bb {
2+
background: green;
3+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.ae {
2+
background: green;
3+
}
4+
5+
.aa {
6+
background: green;
7+
}
8+
9+
.ab {
10+
background: green;
11+
}
12+
13+
.ac {
14+
background: green;
15+
}
16+
17+
.ad {
18+
background: green;
19+
}
20+
21+
body {
22+
background: red;
23+
}
24+
25+
.ba {
26+
background: green;
27+
}
28+
29+
.bb {
30+
background: green;
31+
}
32+
33+
body {
34+
background: yellow;
35+
}
36+

test/cases/at-import/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import './a.css';
2+
import './b.css';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const Self = require('../../../');
2+
3+
module.exports = {
4+
entry: './index.js',
5+
module: {
6+
rules: [
7+
{
8+
test: /\.css$/,
9+
use: [
10+
Self.loader,
11+
'css-loader',
12+
],
13+
},
14+
],
15+
},
16+
plugins: [
17+
new Self({
18+
filename: '[name].css',
19+
}),
20+
],
21+
};
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.base {
2-
background: blue;
1+
.composed {
2+
background: green;
33
}
44

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.base {
2+
background: blue;
3+
}
4+

test/cases/composes-async/webpack.config.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ module.exports = {
1111
{
1212
loader: 'css-loader',
1313
options: {
14-
localIdentName: '[local]',
15-
},
16-
},
14+
localIdentName: '[local]'
15+
}
16+
}
1717
],
1818
},
1919
],
@@ -25,10 +25,10 @@ module.exports = {
2525
test: /\.css$/,
2626
chunks: 'all',
2727
minChunks: 2,
28-
enforce: true,
29-
},
30-
},
31-
},
28+
enforce: true
29+
}
30+
}
31+
}
3232
},
3333
plugins: [
3434
new Self({
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import "./styleA.css";
2+
import "./styleB.css";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "./styleA.css";

test/cases/contenthash-multiple-entries/entryC.js

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import "./styleA.css";
2+
import "./styleB.css";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import "./styleC.css";
2+
import "./styleD.css";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.styleA { background: red; }
2+
3+
.styleB { background: blue; }
4+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.styleA { background: red; }
2+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.styleA { background: red; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.styleB { background: blue; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.styleA { background: red; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.styleB { background: blue; }
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const Self = require('../../../');
2+
3+
module.exports = {
4+
entry: {
5+
'entryA': './entryA.js',
6+
'entryB': './entryB.js',
7+
'entryC': './entryC.js',
8+
'entryD': './entryD.js',
9+
'entryE': './entryE.js',
10+
},
11+
module: {
12+
rules: [
13+
{
14+
test: /\.css$/,
15+
use: [
16+
Self.loader,
17+
'css-loader',
18+
],
19+
},
20+
],
21+
},
22+
output: {
23+
filename: '[name]-[contenthash].js',
24+
},
25+
plugins: [
26+
new Self({
27+
filename: '[contenthash].css',
28+
}),
29+
],
30+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
body { background: red; }
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
body { background: green; }
2+

test/cases/contenthash/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import './style.css'; // eslint-disable-line import/no-unresolved
1+
import './style.css';

test/cases/contenthash/webpack.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ module.exports = [1, 2].map(n => ({
1414
],
1515
},
1616
output: {
17-
filename: `${n}.[name].js`,
17+
filename: `${n}.[name].js`
1818
},
1919
resolve: {
2020
alias: {
21-
'./style.css': `./style${n}.css`,
22-
},
21+
'./style.css': `./style${n}.css`
22+
}
2323
},
2424
plugins: [
2525
new Self({

test/cases/css-import/a.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body { background: red; }

test/cases/css-import/b.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.b { background: red; }
2+
3+
@import url("https://some/external/css");
4+
5+
.b { color: yellow; }

test/cases/css-import/c.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.c { background: red; }
2+
@import './a.css';
3+
@import url("https://some/other/external/css");
4+
5+
.c { color: yellow; }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@import url(https://some/other/external/css);
2+
@import url(https://some/external/css);
3+
body { background: red; }
4+
5+
.c { background: red; }
6+
7+
.c { color: yellow; }
8+
9+
.b { background: red; }
10+
11+
.b { color: yellow; }
12+
13+
14+

test/cases/css-import/index.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@import './c.css';
2+
@import './b.css';

0 commit comments

Comments
 (0)