Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epidemian
GitHub Repository: epidemian/eslint-plugin-import
Path: blob/main/tests/src/package.js
829 views
1
const expect = require('chai').expect;
2
3
const path = require('path');
4
const fs = require('fs');
5
6
function isJSFile(f) {
7
return path.extname(f) === '.js';
8
}
9
10
describe('package', function () {
11
const pkg = path.join(process.cwd(), 'src');
12
let module;
13
14
before('is importable', function () {
15
module = require(pkg);
16
});
17
18
it('exists', function () {
19
expect(module).to.exist;
20
});
21
22
it('has every rule', function (done) {
23
24
fs.readdir(
25
path.join(pkg, 'rules')
26
, function (err, files) {
27
expect(err).not.to.exist;
28
29
files.filter(isJSFile).forEach(function (f) {
30
expect(module.rules).to.have
31
.property(path.basename(f, '.js'));
32
});
33
34
done();
35
});
36
});
37
38
it('exports all configs', function (done) {
39
fs.readdir(path.join(process.cwd(), 'config'), function (err, files) {
40
if (err) { done(err); return; }
41
files.filter(isJSFile).forEach(file => {
42
if (file[0] === '.') return;
43
expect(module.configs).to.have.property(path.basename(file, '.js'));
44
});
45
done();
46
});
47
});
48
49
it('has configs only for rules that exist', function () {
50
for (const configFile in module.configs) {
51
const preamble = 'import/';
52
53
for (const rule in module.configs[configFile].rules) {
54
expect(() => require(getRulePath(rule.slice(preamble.length))))
55
.not.to.throw(Error);
56
}
57
}
58
59
function getRulePath(ruleName) {
60
// 'require' does not work with dynamic paths because of the compilation step by babel
61
// (which resolves paths according to the root folder configuration)
62
// the usage of require.resolve on a static path gets around this
63
return path.resolve(require.resolve('rules/no-unresolved'), '..', ruleName);
64
}
65
});
66
67
it('marks deprecated rules in their metadata', function () {
68
expect(module.rules['imports-first'].meta.deprecated).to.be.true;
69
expect(module.rules['first'].meta.deprecated).not.to.be.true;
70
});
71
72
});
73
74