Skip to content

Commit

Permalink
test: loading order (#236)
Browse files Browse the repository at this point in the history
* fix css files load order mismatch #188

* fix(src): fix sort bug

* feat(test): add test

* test(sorting): add test case which uses the fallback behavior

* fix(sorting): revert change to restore original behavior

This fixes the testcase
  • Loading branch information
ShanaMaid authored and evilebottnawi committed Aug 14, 2018
1 parent 30b89d0 commit 97e2f4c
Show file tree
Hide file tree
Showing 26 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/cases/simple-async-load-css-fallback/a.css
@@ -0,0 +1 @@
body { background: red; }
2 changes: 2 additions & 0 deletions test/cases/simple-async-load-css-fallback/async-one.js
@@ -0,0 +1,2 @@
import './c.css';
import './d.css';
2 changes: 2 additions & 0 deletions test/cases/simple-async-load-css-fallback/async-two.js
@@ -0,0 +1,2 @@
import './e.css';
import './f.css';
1 change: 1 addition & 0 deletions test/cases/simple-async-load-css-fallback/b.css
@@ -0,0 +1 @@
body { background: green; }
1 change: 1 addition & 0 deletions test/cases/simple-async-load-css-fallback/c.css
@@ -0,0 +1 @@
body { background: blue; }
1 change: 1 addition & 0 deletions test/cases/simple-async-load-css-fallback/d.css
@@ -0,0 +1 @@
body { background: yellow; }
1 change: 1 addition & 0 deletions test/cases/simple-async-load-css-fallback/e.css
@@ -0,0 +1 @@
body { background: purple; }
@@ -0,0 +1,4 @@
body { background: blue; }

body { background: yellow; }

@@ -0,0 +1,4 @@
body { background: purple; }

body { background: indigo; }

4 changes: 4 additions & 0 deletions test/cases/simple-async-load-css-fallback/expected/main.css
@@ -0,0 +1,4 @@
body { background: red; }

body { background: green; }

1 change: 1 addition & 0 deletions test/cases/simple-async-load-css-fallback/f.css
@@ -0,0 +1 @@
body { background: indigo; }
5 changes: 5 additions & 0 deletions test/cases/simple-async-load-css-fallback/index.js
@@ -0,0 +1,5 @@
import './a.css';
import './b.css';
import(/* webpackChunkName: 'async-one' */'./async-one');
import(/* webpackChunkName: 'async-two' */'./async-two');

33 changes: 33 additions & 0 deletions test/cases/simple-async-load-css-fallback/webpack.config.js
@@ -0,0 +1,33 @@
const Self = require('../../../');

module.exports = {
entry: {
'main': './index.js',
},
module: {
rules: [
{
test: /\.css$/,
use: [
Self.loader,
'css-loader',
],
},
],
},
plugins: [
function() {
this.hooks.compilation.tap("Test", compilation => {
compilation.hooks.beforeChunkAssets.tap("Test", () => {
for (const chunkGroup of compilation.chunkGroups) {
// remove getModuleIndex2 to enforce using fallback
chunkGroup.getModuleIndex2 = undefined;
}
});
})
},
new Self({
filename: '[name].css',
}),
],
};
1 change: 1 addition & 0 deletions test/cases/simple-async-load-css/a.css
@@ -0,0 +1 @@
body { background: red; }
2 changes: 2 additions & 0 deletions test/cases/simple-async-load-css/async-one.js
@@ -0,0 +1,2 @@
import './c.css';
import './d.css';
2 changes: 2 additions & 0 deletions test/cases/simple-async-load-css/async-two.js
@@ -0,0 +1,2 @@
import './e.css';
import './f.css';
1 change: 1 addition & 0 deletions test/cases/simple-async-load-css/b.css
@@ -0,0 +1 @@
body { background: green; }
1 change: 1 addition & 0 deletions test/cases/simple-async-load-css/c.css
@@ -0,0 +1 @@
body { background: blue; }
1 change: 1 addition & 0 deletions test/cases/simple-async-load-css/d.css
@@ -0,0 +1 @@
body { background: yellow; }
1 change: 1 addition & 0 deletions test/cases/simple-async-load-css/e.css
@@ -0,0 +1 @@
body { background: purple; }
4 changes: 4 additions & 0 deletions test/cases/simple-async-load-css/expected/async-one.css
@@ -0,0 +1,4 @@
body { background: blue; }

body { background: yellow; }

4 changes: 4 additions & 0 deletions test/cases/simple-async-load-css/expected/async-two.css
@@ -0,0 +1,4 @@
body { background: purple; }

body { background: indigo; }

4 changes: 4 additions & 0 deletions test/cases/simple-async-load-css/expected/main.css
@@ -0,0 +1,4 @@
body { background: red; }

body { background: green; }

1 change: 1 addition & 0 deletions test/cases/simple-async-load-css/f.css
@@ -0,0 +1 @@
body { background: indigo; }
5 changes: 5 additions & 0 deletions test/cases/simple-async-load-css/index.js
@@ -0,0 +1,5 @@
import './a.css';
import './b.css';
import(/* webpackChunkName: 'async-one' */'./async-one');
import(/* webpackChunkName: 'async-two' */'./async-two');

23 changes: 23 additions & 0 deletions test/cases/simple-async-load-css/webpack.config.js
@@ -0,0 +1,23 @@
const Self = require('../../../');

module.exports = {
entry: {
'main': './index.js',
},
module: {
rules: [
{
test: /\.css$/,
use: [
Self.loader,
'css-loader',
],
},
],
},
plugins: [
new Self({
filename: '[name].css',
}),
],
};

2 comments on commit 97e2f4c

@boraturant
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this only the test commit? Nothing seemed to change on index.js?

@alexander-akait
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.