-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.cjs
More file actions
58 lines (48 loc) · 2.16 KB
/
index.test.cjs
File metadata and controls
58 lines (48 loc) · 2.16 KB
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
// index.test.js: CJS API tests
const pathCjs = require('./index.cjs');
const { path: namedPathCjs, getCurrentFilename: getFilenameCjs, getCurrentDirname: getDirnameCjs, pathUrl } = pathCjs;
describe('CJS API', () => {
test('getCurrentFilename (CJS) returns index.cjs path (undefined)', () => {
const filename = getFilenameCjs();
expect(filename.endsWith('index.cjs')).toBe(true);
});
test('getCurrentFilename (CJS) returns index.cjs path (__dirname)', () => {
const filename = getFilenameCjs(__dirname);
expect(filename).toBe(__dirname);
});
test('getCurrentDirname (CJS) returns correct dirname (undefined)', () => {
const dirname = getDirnameCjs();
const expected = require('path').dirname(getFilenameCjs());
expect(dirname).toBe(expected);
});
test('getCurrentDirname (CJS) returns correct dirname (__dirname)', () => {
const dirname = getDirnameCjs(__dirname);
expect(dirname).toBe(__dirname);
});
test('path (CJS) joins single segment correctly (default export)', () => {
const p = pathCjs(__dirname, 'index.cjs');
const expected = require('path').join(__dirname, 'index.cjs');
expect(p).toBe(expected);
});
test('path (CJS) joins single segment correctly (named export)', () => {
const p = namedPathCjs(__dirname, 'index.cjs');
const expected = require('path').join(__dirname, 'index.cjs');
expect(p).toBe(expected);
});
test('path (CJS) returns dirname when no segments (default export)', () => {
expect(pathCjs(__dirname)).toBe(__dirname);
});
test('path (CJS) returns dirname when no segments (named export)', () => {
expect(namedPathCjs(__dirname)).toBe(__dirname);
});
test('pathUrl returns file URL href for __dirname and segment', () => {
const href = pathUrl(__dirname, 'index.cjs');
expect(href.startsWith('file:')).toBe(true);
expect(href.endsWith('/index.cjs')).toBe(true);
});
test('pathUrl returns file URL href for __dirname only', () => {
const href = pathUrl(__dirname);
expect(href.startsWith('file:')).toBe(true);
expect(href.endsWith(__dirname.replace(/\\/g, '/'))).toBe(true);
});
});