Skip to content

Commit 5269e88

Browse files
author
dutchenkoOleg
committed
tests
1 parent e8db5e7 commit 5269e88

File tree

5 files changed

+124
-5
lines changed

5 files changed

+124
-5
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- "7"
5+
- "6"

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Change log
2+
3+
:back: [README.md](./README.md)
4+
5+
> _All notable changes to this project will be documented in this file._
6+
> _This project adheres to [Semantic Versioning](http://semver.org/)._
7+
8+
---
9+
10+
### [1.1.9] - 2017-07-07
11+
12+
#### Added
13+
14+
- this CHANGELOG.md file ))
15+
- test for code style
16+
- test of sorting result, see [./tests/index.js](./tests/index.js)
17+
- [Travis CI](https://travis-ci.org/dutchenkoOleg/gulp-not-supported-file) builds
18+
19+
#### Changed
20+
21+
- js code style with accordance to [`happiness`]((https://github.com/JedWatson/happiness))
22+
23+
---

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
![npm](https://img.shields.io/badge/node-6.3.0-yellow.svg)
44
![es2015](https://img.shields.io/badge/ECMAScript-2015_(ES6)-blue.svg)
5+
![license](https://img.shields.io/badge/License-MIT-orange.svg)
6+
[![Build Status](https://travis-ci.org/dutchenkoOleg/sort-css-media-queries.svg?branch=master)](https://travis-ci.org/dutchenkoOleg/sort-css-media-queries)
57

6-
The custom `sort` method for [`css-mqpacker`](https://www.npmjs.com/package/css-mqpacker) or [`pleeease`](https://www.npmjs.com/package/pleeease) (which uses css-mqpacker) or, perhaps, something else ))
8+
> The custom `sort` method for [`css-mqpacker`](https://www.npmjs.com/package/css-mqpacker) or [`pleeease`](https://www.npmjs.com/package/pleeease) (which uses css-mqpacker) or, perhaps, something else ))
9+
10+
[![js happiness style](https://cdn.rawgit.com/JedWatson/happiness/master/badge.svg)](https://github.com/JedWatson/happiness)
711

812
## Installing
913

@@ -42,7 +46,12 @@ it's use es6 syntax
4246

4347
## Tests
4448

45-
Sorry but here no tests yet.
49+
1. `npm test` for testing js code style and test sorting method
50+
1. `npm run fix` for automatically fix most of problems with **js code style**
51+
52+
## Changelog
53+
54+
Please read [CHANGELOG.md](https://github.com/dutchenkoOleg/sort-css-media-queries/blob/master/CHANGELOG.md)
4655

4756

4857
## Contributing

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "sort-css-media-queries",
3-
"version": "1.1.1",
3+
"version": "1.1.9",
44
"description": "The custom `sort` method for `css-mqpacker` or `pleeease` (which uses css-mqpacker) or, perhaps, something else ))",
55
"main": "index.js",
66
"scripts": {
7-
"test": "happiness --verbose | snazzy",
7+
"test": "happiness --verbose | snazzy && node ./tests/index.js",
88
"fix": "happiness --verbose --fix | snazzy"
99
},
1010
"repository": {
@@ -19,7 +19,7 @@
1919
"media",
2020
"queries"
2121
],
22-
"author": "Oleg Dutchenko <dutchenko.o.wezom@gmail.com>",
22+
"author": "Oleg Dutchenko <dutchenko.o.dev@gmail.com>",
2323
"license": "MIT",
2424
"bugs": {
2525
"url": "https://github.com/dutchenkoOleg/sort-css-media-queries/issues"

tests/index.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* > Sorting test
3+
* @module path/to
4+
* @author Oleg Dutchenko <[email protected]>
5+
*/
6+
7+
'use strict';
8+
9+
// ----------------------------------------
10+
// Imports
11+
// ----------------------------------------
12+
13+
const sortCSSmq = require('../');
14+
15+
// ----------------------------------------
16+
// Helpers / Private
17+
// ----------------------------------------
18+
19+
// randomize
20+
function shuffleArray (array) {
21+
let newArray = array.concat();
22+
23+
for (let i = array.length - 1; i > 0; i--) {
24+
let j = Math.floor(Math.random() * (i + 1));
25+
let temp = newArray[i];
26+
27+
newArray[i] = newArray[j];
28+
newArray[j] = temp;
29+
}
30+
return newArray;
31+
}
32+
33+
// ----------------------------------------
34+
// Public
35+
// ----------------------------------------
36+
37+
// correct sorted order
38+
const queries = [
39+
// min-width/-height -> from smallest to largest
40+
'only screen and (min-width: 320px) and (max-width: 767px)',
41+
'screen and (min-height: 480px)',
42+
'screen and (min-height: 480px) and (min-width: 320px)',
43+
'only screen and (min-width: 640px)',
44+
'screen and (min-width: 1024px)',
45+
'only screen and (min-width: 1280px)',
46+
47+
// device
48+
'only screen and (min-device-width: 320px) and (max-device-width: 767px)',
49+
50+
// max-width/-height <- from largest to smallest
51+
'only screen and (max-width: 1023px)',
52+
'only screen and (max-height: 767px) and (min-height: 320px)',
53+
'only screen and (max-width: 767px) and (min-width: 320px)',
54+
'screen and (max-width: 639px)'
55+
];
56+
57+
// shuffle it
58+
const random = shuffleArray(queries);
59+
60+
// sort by module
61+
random.sort(sortCSSmq);
62+
63+
// make strings for compare
64+
const correct = queries.join(',');
65+
const sorted = random.join(',');
66+
67+
// lets test
68+
if (correct !== sorted) {
69+
let msg = [
70+
'',
71+
'ERROR -----------------',
72+
'sortCSSmq result should be same as correct!',
73+
'Correct sort',
74+
`- ${queries.join('\n- ')}`,
75+
'sortCSSmq result:',
76+
`- ${random.join('\n- ')}`,
77+
''
78+
].join('\n\n');
79+
80+
console.log(msg);
81+
process.exit(1);
82+
}

0 commit comments

Comments
 (0)