Skip to content

Commit

Permalink
update tests & add recursive option to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vis97c committed Jun 12, 2023
1 parent b5b8d37 commit 97f24b1
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,18 @@ postcss([
]).process(css);
```

### Recursive

Sort nested media queries recursivey

```js
postcss([
sortMediaQueries({
recursive: true,
})
]).process(css);
```

---

## Changelog
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module.exports = (opts = {}) => {
if (!atRulesKeys.length) return;

sortAtRules(atRulesKeys).forEach(query => {
if (recursive) recursivelySort(atRules[query]);
if (!onlyTopLevel && recursive) recursivelySort(atRules[query]);

localRoot.append(atRules[query]);
});
Expand Down
8 changes: 8 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ it('[df] mixed #1', async () => {
await run('mixed-desktop.in', 'mixed-desktop.out', { sort: 'desktop-first' });
});

it('use custom sort function', async () => {
await run('custom-sort.in', 'custom-sort.out', { sort: (a, b) => a.length < b.length }, []);
});

it('sort recursively', async () => {
await run('recursive-sort.in', 'recursive-sort.out', { recursive: true }, []);
});

it('[mf] configuration(mixed #1): unitlessMqAlwaysFirst: FALSE', async () => {
const options = {
configuration: {
Expand Down
24 changes: 24 additions & 0 deletions test/custom-sort.in.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@media screen and (max-width: 640px) {
.s1m { color: #ccc }
}
@media tv {
.s1m { color: #ccc }
}
@media screen and (max-width: 980px) {
.s1m { color: #ccc }
}
@media screen and (max-width: 768px) {
.s1m { color: #ccc }
}
@media screen and (min-width: 640px) {
.s1m { color: #ccc }
}
@media screen and (min-width: 1280px) {
.s1m { color: #ccc }
}
@media print {
.s1m { color: #ccc }
}
@media screen and (max-width: 1280px) {
.s1m { color: #ccc }
}
16 changes: 16 additions & 0 deletions test/custom-sort.out.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@media screen and (max-width: 640px) {
.s1m { color: #ccc } }
@media tv {
.s1m { color: #ccc } }
@media screen and (max-width: 980px) {
.s1m { color: #ccc } }
@media screen and (max-width: 768px) {
.s1m { color: #ccc } }
@media screen and (min-width: 640px) {
.s1m { color: #ccc } }
@media screen and (min-width: 1280px) {
.s1m { color: #ccc } }
@media print {
.s1m { color: #ccc } }
@media screen and (max-width: 1280px) {
.s1m { color: #ccc } }
39 changes: 39 additions & 0 deletions test/recursive-sort.in.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@media (min-width: 700px) {
.a {
color: #00FF00;
}
}

@media print{
@media (min-width: 250px) {
.b {
color: #FF0000;
}
}

@media (min-width: 700px) {
.b {
color: #FF0000;
}
}

@media (min-width: 150px) {
.b {
color: #FF0000;
}
}
}

@media print {
@media (min-width: 700px) {
.b {
color: #FF0000;
}
}
}

@media (width >= 400px) {
.a {
color: #00FF00;
}
}
30 changes: 30 additions & 0 deletions test/recursive-sort.out.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@media (width >= 400px) {
.a {
color: #00FF00;
}
}
@media (min-width: 700px) {
.a {
color: #00FF00;
}
}
@media print {
@media (min-width: 150px) {
.b {
color: #FF0000;
}
}
@media (min-width: 250px) {
.b {
color: #FF0000;
}
}
@media (min-width: 700px) {
.b {
color: #FF0000;
}
.b {
color: #FF0000;
}
}
}

0 comments on commit 97f24b1

Please sign in to comment.