-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrequireUp.test.js
59 lines (51 loc) · 1.71 KB
/
requireUp.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
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, it, expect } from 'vitest';
import { requireUp } from './requireUp';
import { DEFAULT_EXTENSIONS } from './constants';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Path to the 'fixtures' directory
const fixturesDir = path.resolve(__dirname, './fixtures');
describe('requireUp', () => {
it('should find the file at eslint-local-rules.js', () => {
const file = requireUp(
'eslint-local-rules',
DEFAULT_EXTENSIONS,
path.join(fixturesDir, './projectWithResolution/a')
);
expect(file).toBeDefined();
});
it('should find the file at eslint-local-rules.cjs', () => {
const file = requireUp(
'eslint-local-rules',
DEFAULT_EXTENSIONS,
path.join(fixturesDir, './projectWithResolutionCjs/a')
);
expect(file).toBeDefined();
});
it('should find the file at eslint-local-rules/index.js', () => {
const file = requireUp(
'eslint-local-rules',
DEFAULT_EXTENSIONS,
path.join(fixturesDir, './projectWithResolutionIndex/a')
);
expect(file).toBeDefined();
});
it('should fail to find a file that does not exist', () => {
const file = requireUp(
'some-file-that-will-not-resolve',
DEFAULT_EXTENSIONS,
path.join(fixturesDir, './projectWithNoResolution/a')
);
expect(file).not.toBeDefined();
});
it('should throw MODULE_NOT_FOUND errors for modules other than the target', () => {
expect(() => {
requireUp(
'eslint-local-rules',
DEFAULT_EXTENSIONS,
path.join(fixturesDir, './projectWithBadImport/a')
);
}).toThrowError(`Cannot find module './does-not-exist'`);
});
});