Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epidemian
GitHub Repository: epidemian/eslint-plugin-import
Path: blob/main/tests/src/core/ignore.js
829 views
1
import { expect } from 'chai';
2
3
import isIgnored, { getFileExtensions, hasValidExtension } from 'eslint-module-utils/ignore';
4
5
import * as utils from '../utils';
6
7
describe('ignore', function () {
8
describe('isIgnored', function () {
9
it('ignores paths with extensions other than .js', function () {
10
const testContext = utils.testContext({});
11
12
expect(isIgnored('../files/foo.js', testContext)).to.equal(false);
13
14
expect(isIgnored('../files/bar.jsx', testContext)).to.equal(true);
15
16
expect(isIgnored('../files/typescript.ts', testContext)).to.equal(true);
17
18
expect(isIgnored('../files/ignore.invalid.extension', testContext)).to.equal(true);
19
});
20
21
it('ignores paths with invalid extensions when configured with import/extensions', function () {
22
const testContext = utils.testContext({ 'import/extensions': [ '.js', '.jsx', '.ts' ] });
23
24
expect(isIgnored('../files/foo.js', testContext)).to.equal(false);
25
26
expect(isIgnored('../files/bar.jsx', testContext)).to.equal(false);
27
28
expect(isIgnored('../files/typescript.ts', testContext)).to.equal(false);
29
30
expect(isIgnored('../files/ignore.invalid.extension', testContext)).to.equal(true);
31
});
32
});
33
34
describe('hasValidExtension', function () {
35
it('assumes only .js as valid by default', function () {
36
const testContext = utils.testContext({});
37
38
expect(hasValidExtension('../files/foo.js', testContext)).to.equal(true);
39
40
expect(hasValidExtension('../files/foo.jsx', testContext)).to.equal(false);
41
42
expect(hasValidExtension('../files/foo.css', testContext)).to.equal(false);
43
44
expect(hasValidExtension('../files/foo.invalid.extension', testContext)).to.equal(false);
45
});
46
47
it('can be configured with import/extensions', function () {
48
const testContext = utils.testContext({ 'import/extensions': [ '.foo', '.bar' ] });
49
50
expect(hasValidExtension('../files/foo.foo', testContext)).to.equal(true);
51
52
expect(hasValidExtension('../files/foo.bar', testContext)).to.equal(true);
53
54
expect(hasValidExtension('../files/foo.js', testContext)).to.equal(false);
55
});
56
});
57
58
describe('getFileExtensions', function () {
59
it('returns a set with the file extension ".js" if "import/extensions" is not configured', function () {
60
const fileExtensions = getFileExtensions({});
61
62
expect(fileExtensions).to.include('.js');
63
});
64
65
it('returns a set with the file extensions configured in "import/extension"', function () {
66
const settings = {
67
'import/extensions': ['.js', '.jsx'],
68
};
69
70
const fileExtensions = getFileExtensions(settings);
71
72
expect(fileExtensions).to.include('.js');
73
expect(fileExtensions).to.include('.jsx');
74
});
75
76
it('returns a set with the file extensions configured in "import/extension" and "import/parsers"', function () {
77
const settings = {
78
'import/parsers': {
79
'typescript-eslint-parser': ['.ts', '.tsx'],
80
},
81
};
82
83
const fileExtensions = getFileExtensions(settings);
84
85
expect(fileExtensions).to.include('.js'); // If "import/extensions" is not configured, this is the default
86
expect(fileExtensions).to.include('.ts');
87
expect(fileExtensions).to.include('.tsx');
88
});
89
});
90
});
91
92