Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epidemian
GitHub Repository: epidemian/eslint-plugin-import
Path: blob/main/resolvers/node/test/paths.js
829 views
1
const expect = require('chai').expect;
2
3
const path = require('path');
4
const node = require('../index.js');
5
6
describe('paths', function () {
7
it('handles base path relative to CWD', function () {
8
expect(node.resolve('../', './test/file.js'))
9
.to.have.property('path')
10
.equal(path.resolve(__dirname, '../index.js'));
11
});
12
});
13
14
15
describe('core', function () {
16
it('returns found, but null path, for core Node modules', function () {
17
const resolved = node.resolve('fs', './test/file.js');
18
expect(resolved).has.property('found', true);
19
expect(resolved).has.property('path', null);
20
});
21
});
22
23
24
describe('default options', function () {
25
26
it('finds .json files', function () {
27
expect(node.resolve('./data', './test/file.js'))
28
.to.have.property('path')
29
.equal(path.resolve(__dirname, './data.json'));
30
});
31
32
it("ignores .json files if 'extensions' is redefined", function () {
33
expect(node.resolve('./data', './test/file.js', { extensions: ['.js'] }))
34
.to.have.property('found', false);
35
});
36
37
it('finds mjs modules, with precedence over .js', function () {
38
expect(node.resolve('./native', './test/file.js'))
39
.to.have.property('path')
40
.equal(path.resolve(__dirname, './native.mjs'));
41
});
42
43
it('finds .node modules, with lowest precedence', function () {
44
expect(node.resolve('./native.node', './test/file.js'))
45
.to.have.property('path')
46
.equal(path.resolve(__dirname, './native.node'));
47
});
48
49
it('finds .node modules', function () {
50
expect(node.resolve('./dot-node', './test/file.js'))
51
.to.have.property('path')
52
.equal(path.resolve(__dirname, './dot-node.node'));
53
});
54
55
it('still finds .js if explicit', function () {
56
expect(node.resolve('./native.js', './test/file.js'))
57
.to.have.property('path')
58
.equal(path.resolve(__dirname, './native.js'));
59
});
60
});
61
62