/
extends.test.js
104 lines (86 loc) · 2.63 KB
/
extends.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'use strict';
const configExtendingAnotherExtend = require('./fixtures/config-extending-another-extend.json');
const configExtendingOne = require('./fixtures/config-extending-one');
const configExtendingThreeWithOverride = require('./fixtures/config-extending-three-with-override');
const path = require('path');
const standalone = require('../standalone');
const fixturesPath = path.join(__dirname, 'fixtures');
it('basic extending', async () => {
const linted = await standalone({
code: 'a {}',
config: configExtendingOne,
configBasedir: path.join(__dirname, 'fixtures'),
});
expect(typeof linted.output).toBe('string');
expect(linted.results).toHaveLength(1);
expect(linted.results[0].warnings).toHaveLength(1);
expect(linted.results[0].warnings[0].rule).toBe('block-no-empty');
});
it('recursive extending', async () => {
const linted = await standalone({
code: 'a {}',
config: configExtendingAnotherExtend,
configBasedir: path.join(__dirname, 'fixtures'),
});
expect(typeof linted.output).toBe('string');
expect(linted.results).toHaveLength(1);
expect(linted.results[0].warnings).toHaveLength(1);
expect(linted.results[0].warnings[0].rule).toBe('block-no-empty');
});
it('extending with overrides', async () => {
const linted = await standalone({
code: 'a {}',
config: configExtendingThreeWithOverride,
configBasedir: path.join(__dirname, 'fixtures'),
});
expect(linted.results[0].warnings).toHaveLength(0);
});
it('extending configuration and no configBasedir', () => {
return expect(
standalone({
code: 'a {}',
config: configExtendingOne,
}),
).rejects.toHaveProperty('code', 78);
});
it('extending a config that is overridden', async () => {
const linted = await standalone({
code: 'a { b: "c" }',
config: {
extends: [`${fixturesPath}/config-string-quotes-single`],
rules: { 'string-quotes': 'double' },
},
});
expect(linted.results[0].warnings).toHaveLength(0);
});
describe('extending a config from process.cwd', () => {
let actualCwd;
beforeAll(() => {
actualCwd = process.cwd();
process.chdir(__dirname);
});
afterAll(() => {
process.chdir(actualCwd);
});
it('works', async () => {
const linted = await standalone({
code: 'a { b: "c" }',
config: {
extends: ['./fixtures/config-string-quotes-single'],
},
});
expect(linted.results[0].warnings).toHaveLength(1);
});
});
describe('extending a config from options.cwd', () => {
it('works', async () => {
const linted = await standalone({
code: 'a { b: "c" }',
config: {
extends: ['./fixtures/config-string-quotes-single'],
},
cwd: __dirname,
});
expect(linted.results[0].warnings).toHaveLength(1);
});
});