Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for nested import ordering #169

Merged
merged 1 commit into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/fixtures/imports/foo-first.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import "bar.css";

foo.first{
color: red;
}
5 changes: 5 additions & 0 deletions test/fixtures/imports/foo-second.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import "bar.css";

foo.second{
color: blue;
}
6 changes: 6 additions & 0 deletions test/fixtures/order.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@import "foo-first.css";
@import "foo-second.css";

.baz {
color: green;
}
13 changes: 13 additions & 0 deletions test/fixtures/order.expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
bar{}

foo.first{
color: red;
}

foo.second{
color: blue;
}

.baz {
color: green;
}
39 changes: 39 additions & 0 deletions test/order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import test from "ava"
import compareFixtures from "./helpers/compare-fixtures"

test(`should order nested imports correctly`, t => {
var first = true
var resolve = require("resolve")

return compareFixtures(t, "order", {
path: "fixtures/imports",
resolve: (id, base, opts) => {
var resolveOpts = {
basedir: base,
moduleDirectory: [],
paths: opts.path,
extensions: [ ".css" ],
}

return new Promise(function(res, rej) {
var doResolve = () => {
resolve(id, resolveOpts, function(err, path) {
if (err) {
return rej(err)
}
res(path)
})
}

if (first) {
// Delay the first import so the second gets loaded first
setTimeout(doResolve, 100)
first = false
}
else {
doResolve()
}
})
},
})
})