Skip to content

Commit 9e340c2

Browse files
committed
Simplify test setup
1 parent a7171d0 commit 9e340c2

4 files changed

Lines changed: 189 additions & 356 deletions

File tree

jest-setup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ global.groupTest = function groupTest(testGroups) {
2525
});
2626
};
2727

28-
global.runTest = function runTest(input, opts, dirname) {
29-
const dir = path.join(dirname, './fixtures/');
28+
global.runTest = function runTest(input, opts) {
29+
const dir = path.join(path.dirname(expect.getState().testPath), './fixtures/');
3030
const inputSplitted = input.split('.');
3131
let inputName = input;
3232
let inputExt = 'css';

lib/__tests__/test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import postcssSorting from '../../index.js';
22
import postcss from 'postcss';
33

4-
const __dirname = import.meta.dirname;
5-
64
test(`Should do nothing if config is undefined`, () => {
7-
runTest('empty-lines-preserve', undefined, __dirname);
5+
runTest('empty-lines-preserve', undefined);
86
});
97

108
test(`Should throw an error if config has error`, () => {

lib/order/__tests__/order.js

Lines changed: 93 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,114 @@
1-
const __dirname = import.meta.dirname;
2-
31
const config = {
42
order: ['declarations', 'rules'],
53
};
64

75
test('Should not remove comments in rules if they are only children', () =>
8-
runTest('rules-with-comments-only', config, __dirname));
6+
runTest('rules-with-comments-only', config));
97

108
test(`Should not remove first comment in the rule if it's not on separate line (order)`, () =>
11-
runTest('first-comment-in-the-rule', config, __dirname));
9+
runTest('first-comment-in-the-rule', config));
1210

13-
test('Should not remove last comments in the rule', () =>
14-
runTest('last-comments', config, __dirname));
11+
test('Should not remove last comments in the rule', () => runTest('last-comments', config));
1512

1613
test('Should assign comments before and after nodes correctly (order)', () =>
17-
runTest(
18-
'nodes-comments.css',
19-
{
20-
order: ['custom-properties', 'dollar-variables', 'at-variables', 'declarations'],
21-
},
22-
__dirname,
23-
));
14+
runTest('nodes-comments.css', {
15+
order: ['custom-properties', 'dollar-variables', 'at-variables', 'declarations'],
16+
}));
2417

2518
test('Should sort by keywords', () =>
26-
runTest(
27-
'keywords',
28-
{
29-
order: [
30-
'custom-properties',
31-
'dollar-variables',
32-
'at-variables',
33-
'declarations',
34-
'rules',
35-
'at-rules',
36-
],
37-
},
38-
__dirname,
39-
));
19+
runTest('keywords', {
20+
order: [
21+
'custom-properties',
22+
'dollar-variables',
23+
'at-variables',
24+
'declarations',
25+
'rules',
26+
'at-rules',
27+
],
28+
}));
4029

4130
test('At-rules combination from most specified to least specified', () =>
42-
runTest(
43-
'at-rules',
44-
{
45-
order: [
46-
{
47-
type: 'at-rule',
48-
name: 'include',
49-
parameter: 'media',
50-
hasBlock: true,
51-
},
52-
{
53-
type: 'at-rule',
54-
name: 'include',
55-
parameter: 'media',
56-
},
57-
{
58-
type: 'at-rule',
59-
name: 'include',
60-
hasBlock: true,
61-
},
62-
{
63-
type: 'at-rule',
64-
name: 'include',
65-
},
66-
{
67-
type: 'at-rule',
68-
hasBlock: true,
69-
},
70-
{
71-
type: 'at-rule',
72-
},
73-
],
74-
},
75-
__dirname,
76-
));
31+
runTest('at-rules', {
32+
order: [
33+
{
34+
type: 'at-rule',
35+
name: 'include',
36+
parameter: 'media',
37+
hasBlock: true,
38+
},
39+
{
40+
type: 'at-rule',
41+
name: 'include',
42+
parameter: 'media',
43+
},
44+
{
45+
type: 'at-rule',
46+
name: 'include',
47+
hasBlock: true,
48+
},
49+
{
50+
type: 'at-rule',
51+
name: 'include',
52+
},
53+
{
54+
type: 'at-rule',
55+
hasBlock: true,
56+
},
57+
{
58+
type: 'at-rule',
59+
},
60+
],
61+
}));
7762

7863
test('At-rules mixed combination', () =>
79-
runTest(
80-
'at-rules-mixed',
81-
{
82-
order: [
83-
{
84-
type: 'at-rule',
85-
name: 'include',
86-
hasBlock: true,
87-
},
88-
{
89-
type: 'at-rule',
90-
name: 'include',
91-
},
92-
{
93-
type: 'at-rule',
94-
hasBlock: true,
95-
},
96-
{
97-
type: 'at-rule',
98-
name: 'include',
99-
parameter: 'media',
100-
},
101-
{
102-
type: 'at-rule',
103-
name: 'include',
104-
parameter: 'media',
105-
hasBlock: true,
106-
},
107-
],
108-
},
109-
__dirname,
110-
));
64+
runTest('at-rules-mixed', {
65+
order: [
66+
{
67+
type: 'at-rule',
68+
name: 'include',
69+
hasBlock: true,
70+
},
71+
{
72+
type: 'at-rule',
73+
name: 'include',
74+
},
75+
{
76+
type: 'at-rule',
77+
hasBlock: true,
78+
},
79+
{
80+
type: 'at-rule',
81+
name: 'include',
82+
parameter: 'media',
83+
},
84+
{
85+
type: 'at-rule',
86+
name: 'include',
87+
parameter: 'media',
88+
hasBlock: true,
89+
},
90+
],
91+
}));
11192

11293
test('Should sort inside nested rules', () =>
113-
runTest(
114-
'nested-rule',
115-
{
116-
order: ['custom-properties', 'declarations', 'rules'],
117-
},
118-
__dirname,
119-
));
94+
runTest('nested-rule', {
95+
order: ['custom-properties', 'declarations', 'rules'],
96+
}));
12097

12198
test('Should sort inside nested at-rules', () =>
122-
runTest(
123-
'nested-at-rule',
124-
{
125-
order: ['custom-properties', 'declarations', 'at-rules'],
126-
},
127-
__dirname,
128-
));
99+
runTest('nested-at-rule', {
100+
order: ['custom-properties', 'declarations', 'at-rules'],
101+
}));
129102

130103
test('Should move unspecified nodes to the bottom', () =>
131-
runTest(
132-
'unspecified-nodes',
133-
{
134-
order: ['custom-properties', 'declarations'],
135-
},
136-
__dirname,
137-
));
104+
runTest('unspecified-nodes', {
105+
order: ['custom-properties', 'declarations'],
106+
}));
138107

139108
test('Should preserve indentation', () =>
140-
runTest(
141-
'indent',
142-
{
143-
order: ['declarations', 'rules', 'at-rules'],
144-
},
145-
__dirname,
146-
));
109+
runTest('indent', {
110+
order: ['declarations', 'rules', 'at-rules'],
111+
}));
147112

148113
groupTest([
149114
{
@@ -610,19 +575,11 @@ groupTest([
610575
]);
611576

612577
test('Should sort by keywords (styled)', () =>
613-
runTest(
614-
'keywords.js',
615-
{
616-
order: ['declarations', 'rules', 'at-rules'],
617-
},
618-
__dirname,
619-
));
578+
runTest('keywords.js', {
579+
order: ['declarations', 'rules', 'at-rules'],
580+
}));
620581

621582
test('Ignore nodes with template literals (styled)', () =>
622-
runTest(
623-
'ignore-template-literals.js',
624-
{
625-
order: ['declarations', 'rules', 'at-rules'],
626-
},
627-
__dirname,
628-
));
583+
runTest('ignore-template-literals.js', {
584+
order: ['declarations', 'rules', 'at-rules'],
585+
}));

0 commit comments

Comments
 (0)