Skip to content

Commit 11fd715

Browse files
committed
Update test cases and npm scripts
1 parent 4744eac commit 11fd715

File tree

7 files changed

+128
-15
lines changed

7 files changed

+128
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.idea/
22
.cache/
3+
coverage/
34
node_modules/
45
*.log*
56
.DS_Store

package-lock.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
"description": "The custom `sort` method (mobile-first / desktop-first) of CSS media queries for `postcss-sort-media-queries`, `css-mqpacker` or `pleeease` (which uses css-mqpacker) or, perhaps, something else ))",
55
"main": "lib/index.js",
66
"files": [
7-
"lib/index.js",
8-
"lib/index.d.ts"
7+
"lib"
98
],
109
"scripts": {
1110
"test": "npm run prettier && npm run eslint && npm run jest",
12-
"jest": "jest",
11+
"test:fix": "npm run prettier:fix && npm run eslint:fix && npm run jest:coverage",
1312
"prettier": "prettier \"./{lib,tests}/**\" --check",
1413
"prettier:fix": "npm run prettier -- --write",
1514
"eslint": "eslint \"./{lib,tests}/**/*.js\"",
16-
"eslint:fix": "npm run eslint -- --fix"
15+
"eslint:fix": "npm run eslint -- --fix",
16+
"jest": "jest",
17+
"jest:coverage": "npm run jest -- --coverage"
1718
},
1819
"jest": {
1920
"verbose": true,
@@ -57,5 +58,8 @@
5758
"eslint-plugin-promise": "^5.1.0",
5859
"jest": "^26.4.2",
5960
"prettier": "^2.3.0"
61+
},
62+
"dependencies": {
63+
"mkdirp": "^1.0.4"
6064
}
6165
}

sort-css-mq.config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"unitlessMqAlwaysFirst": false
3+
}

tests/bundle.test.js renamed to tests/create-sort.spec.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
const sortCSSmq = require('../lib');
1+
const createSort = require('../lib/create-sort');
2+
const sortCSSmq = createSort();
23

3-
it(`simple #1. mobile-first`, () => {
4+
test(`simple #1. mobile-first`, () => {
45
const receivedOrder = [
56
'screen and (max-width: 640px)',
67
'screen and (min-width: 980px)',
@@ -29,7 +30,7 @@ it(`simple #1. mobile-first`, () => {
2930
expect(received).toBe(expected);
3031
});
3132

32-
it(`simple #1. desktop-first`, () => {
33+
test(`simple #1. desktop-first`, () => {
3334
const receivedOrder = [
3435
'screen and (max-width: 640px)',
3536
'screen and (min-width: 980px)',
@@ -58,7 +59,7 @@ it(`simple #1. desktop-first`, () => {
5859
expect(received).toBe(expected);
5960
});
6061

61-
it(`simple #2. mobile-first`, () => {
62+
test(`simple #2. mobile-first`, () => {
6263
const receivedOrder = [
6364
'screen and (max-width: 640px)',
6465
'screen and (max-width: 640px)',
@@ -79,7 +80,7 @@ it(`simple #2. mobile-first`, () => {
7980
expect(received).toBe(expected);
8081
});
8182

82-
it(`simple #2. desktop-first`, () => {
83+
test(`simple #2. desktop-first`, () => {
8384
const receivedOrder = [
8485
'screen and (max-width: 640px)',
8586
'screen and (max-width: 640px)',
@@ -100,7 +101,7 @@ it(`simple #2. desktop-first`, () => {
100101
expect(received).toBe(expected);
101102
});
102103

103-
it(`without dimension #1. mobile-first`, () => {
104+
test(`without dimension #1. mobile-first`, () => {
104105
const receivedOrder = [
105106
'tv',
106107
'print and (orientation: landscape)',
@@ -131,7 +132,7 @@ it(`without dimension #1. mobile-first`, () => {
131132
expect(received).toBe(expected);
132133
});
133134

134-
it(`without dimension #1. desktop-first`, () => {
135+
test(`without dimension #1. desktop-first`, () => {
135136
const receivedOrder = [
136137
'tv',
137138
'print and (orientation: landscape)',
@@ -162,7 +163,7 @@ it(`without dimension #1. desktop-first`, () => {
162163
expect(received).toBe(expected);
163164
});
164165

165-
it(`mixed #1. mobile-first`, () => {
166+
test(`mixed #1. mobile-first`, () => {
166167
const receivedOrder = [
167168
'tv',
168169
'print and (orientation: landscape)',
@@ -195,7 +196,7 @@ it(`mixed #1. mobile-first`, () => {
195196
expect(received).toBe(expected);
196197
});
197198

198-
it(`mixed #1. desktop-first`, () => {
199+
test(`mixed #1. desktop-first`, () => {
199200
const receivedOrder = [
200201
'tv',
201202
'print and (orientation: landscape)',
@@ -228,7 +229,7 @@ it(`mixed #1. desktop-first`, () => {
228229
expect(received).toBe(expected);
229230
});
230231

231-
it(`multiline #1. mobile-first`, () => {
232+
test(`multiline #1. mobile-first`, () => {
232233
const receivedOrder = [
233234
`@media (min-width: 48em)
234235
and (max-width: 59.999em)`,
@@ -269,7 +270,7 @@ it(`multiline #1. mobile-first`, () => {
269270
expect(received).toBe(expected);
270271
});
271272

272-
it(`multiline #2. mobile-first`, () => {
273+
test(`multiline #2. mobile-first`, () => {
273274
// Edge cases
274275
const receivedOrder = [
275276
`
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const createSort = require('../lib/create-sort');
2+
3+
test(`unitlessMqAlwaysFirst: FALSE`, () => {
4+
const sort = createSort({
5+
unitlessMqAlwaysFirst: false
6+
});
7+
8+
const receivedOrder = [
9+
'screen and (max-width: 640px)',
10+
'screen and (min-width: 980px)',
11+
'screen and (max-width: 980px)',
12+
'tv',
13+
'screen and (max-width: 768px)',
14+
'screen and (min-width: 640px)',
15+
'print',
16+
'screen and (min-width: 1280px)',
17+
'screen',
18+
'screen and (min-width: 768px)',
19+
'screen and (max-width: 1280px)'
20+
];
21+
22+
const expectedOrder = [
23+
'screen and (min-width: 640px)',
24+
'screen and (min-width: 768px)',
25+
'screen and (min-width: 980px)',
26+
'screen and (min-width: 1280px)',
27+
'screen and (max-width: 1280px)',
28+
'screen and (max-width: 980px)',
29+
'screen and (max-width: 768px)',
30+
'screen and (max-width: 640px)',
31+
'screen',
32+
'tv',
33+
'print' // always last
34+
];
35+
36+
const expected = expectedOrder.join('\n');
37+
const received = receivedOrder.sort(sort).join('\n');
38+
expect(received).toBe(expected);
39+
});
40+
41+
test(`unitlessMqAlwaysFirst: TRUE`, () => {
42+
// eslint-disable-next-line no-unused-vars
43+
const sort = createSort({
44+
unitlessMqAlwaysFirst: true
45+
});
46+
47+
// TODO add test cases
48+
expect(true).toBe(true);
49+
});

tests/load-config.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const mkdirp = require('mkdirp');
4+
5+
const loadConfig = require('../lib/load-config');
6+
const defaultConfig = require('../sort-css-mq.config.json');
7+
8+
test('load default config', () => {
9+
const loadedConfig = loadConfig();
10+
expect(loadedConfig).toEqual(defaultConfig);
11+
});
12+
13+
describe('load custom config', () => {
14+
const customConfig = { unitlessMqAlwaysFirst: true };
15+
const cwd = process.cwd();
16+
const testFolder = '.cache/tests/';
17+
mkdirp.sync(path.join(cwd, '.cache/tests/'));
18+
19+
const testConfigPath = path.join(testFolder, 'sort-css-mq.config.json');
20+
const testConfigString = JSON.stringify(customConfig, undefined, ' ');
21+
fs.writeFileSync(testConfigPath, testConfigString);
22+
23+
const testPkgPath = path.join(testFolder, 'pkg.json');
24+
const testPkgString = JSON.stringify({ sortCssMQ: customConfig }, undefined, ' ');
25+
fs.writeFileSync(testPkgPath, testPkgString);
26+
27+
test('load from custom config file', () => {
28+
const loadedConfig = loadConfig(testConfigPath);
29+
expect(loadedConfig).toEqual(customConfig);
30+
});
31+
32+
test('load from custom pkg file', () => {
33+
const loadedConfig = loadConfig('some-non-existent-file.json', testPkgPath);
34+
expect(loadedConfig).toEqual(customConfig);
35+
});
36+
});

0 commit comments

Comments
 (0)