Skip to content

Commit 344528c

Browse files
adam-hMoOx
authored andcommitted
Add failing test for nested import ordering (#169)
1 parent 6bbcdbd commit 344528c

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import "bar.css";
2+
3+
foo.first{
4+
color: red;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import "bar.css";
2+
3+
foo.second{
4+
color: blue;
5+
}

test/fixtures/order.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@import "foo-first.css";
2+
@import "foo-second.css";
3+
4+
.baz {
5+
color: green;
6+
}

test/fixtures/order.expected.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
bar{}
2+
3+
foo.first{
4+
color: red;
5+
}
6+
7+
foo.second{
8+
color: blue;
9+
}
10+
11+
.baz {
12+
color: green;
13+
}

test/order.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import test from "ava"
2+
import compareFixtures from "./helpers/compare-fixtures"
3+
4+
test(`should order nested imports correctly`, t => {
5+
var first = true
6+
var resolve = require("resolve")
7+
8+
return compareFixtures(t, "order", {
9+
path: "fixtures/imports",
10+
resolve: (id, base, opts) => {
11+
var resolveOpts = {
12+
basedir: base,
13+
moduleDirectory: [],
14+
paths: opts.path,
15+
extensions: [ ".css" ],
16+
}
17+
18+
return new Promise(function(res, rej) {
19+
var doResolve = () => {
20+
resolve(id, resolveOpts, function(err, path) {
21+
if (err) {
22+
return rej(err)
23+
}
24+
res(path)
25+
})
26+
}
27+
28+
if (first) {
29+
// Delay the first import so the second gets loaded first
30+
setTimeout(doResolve, 100)
31+
first = false
32+
}
33+
else {
34+
doResolve()
35+
}
36+
})
37+
},
38+
})
39+
})

0 commit comments

Comments
 (0)