Skip to content

Commit

Permalink
Add tests for currentFile and callerFile
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 12, 2024
1 parent cc47497 commit 94f07cf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/path.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fsPromises from 'node:fs/promises';
import path from 'node:path';
import url from 'node:url';
import {callerTest, callerTestTwo, callerTestThree} from './support/caller.js';
import Path from '../lib/path.js';
import t from 'tap';

Expand Down Expand Up @@ -404,4 +405,16 @@ t.test('Path', async t => {
t.same(temp5.existsSync(), false);
t.same(temp6.existsSync(), false);
});

await t.test('callerFile', async t => {
t.same((await callerTest().realpath()).toString(), (await Path.currentFile().realpath()).toString());
t.same(
(await callerTestTwo().realpath()).toString(),
(await Path.currentFile().dirname().child('support', 'caller.js').realpath()).toString()
);
t.same(
(await callerTestThree().realpath()).toString(),
(await Path.currentFile().dirname().child('support', 'caller.js').realpath()).toString()
);
});
});
13 changes: 13 additions & 0 deletions test/support/caller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Path from '../../lib/path.js';

export function callerTest() {
return Path.callerFile();
}

export function callerTestTwo() {
return callerTest();
}

export function callerTestThree() {
return Path.currentFile();
}

0 comments on commit 94f07cf

Please sign in to comment.