Skip to content

Commit

Permalink
add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SassNinja committed Oct 30, 2019
1 parent ce5fc4c commit a93c383
Show file tree
Hide file tree
Showing 6 changed files with 3,580 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "lts/*"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# postcss-combine-media-query

[![Build Status](https://travis-ci.com/SassNinja/postcss-combine-media-query.svg?branch=master)](https://travis-ci.com/SassNinja/postcss-combine-media-query)

If you are used to write the media queries of your components within those components (what you should do instead of maintaining a large global media query file) you might end up with CSS that contains the same media query rule multiple times.

```css
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"author": "Kai Falkowski",
"license": "MIT",
"main": "index.js",
"scripts": {},
"scripts": {
"test": "jest"
},
"keywords": [
"postcss",
"plugin",
Expand All @@ -16,10 +18,12 @@
"combine",
"optimization"
],
"peerDependencies": {
"dependencies": {
"postcss": "^7.0.21"
},
"devDependencies": {},
"devDependencies": {
"jest": "^24.9.0"
},
"repository": {
"type": "git",
"url": "https://github.com/SassNinja/postcss-combine-media-query.git"
Expand Down
35 changes: 35 additions & 0 deletions test/default.data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

module.exports = `
.foo {
color: red;
}
@media (min-width: 1024px) {
.foo {
color: green;
}
}
@media (min-width: 1200px) {
.foo {
color: blue;
}
}
.bar {
font-size: 1rem;
@supports (display: grid) {
display: block;
}
}
@media (min-width: 1024px) {
.bar {
font-size: 2rem;
@supports (display: grid) {
display: grid;
}
}
}
@media screen and (min-width: 1024px) {
.bar {
content: 'similar but different query'
}
}
`;
34 changes: 34 additions & 0 deletions test/default.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

const postcss = require('postcss');
const plugin = require('../index');
const data = require('./default.data');

let root;

beforeAll(() => {
root = postcss([plugin()]).process(data).root;
});

test('should combine equal media rules', () => {
let count = 0;

root.walkAtRules('media', rule => {
count++;
});
expect(count).toBe(3);
});

test('should move all media rules to the end', () => {
let endsWithMedia = true;
let hasMedia = false;

root.nodes.forEach(node => {
if (node.name === 'media') {
hasMedia = true;
}
if (hasMedia && node.name !== 'media') {
endsWithMedia = false;
}
expect(endsWithMedia).toBe(true);
});
});
Loading

0 comments on commit a93c383

Please sign in to comment.