From 94f07cf04b24b0a853893b0f8c366bbd75a02827 Mon Sep 17 00:00:00 2001 From: Sebastian Riedel Date: Sat, 12 Oct 2024 15:30:05 +0200 Subject: [PATCH] Add tests for currentFile and callerFile --- test/path.js | 13 +++++++++++++ test/support/caller.js | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/support/caller.js diff --git a/test/path.js b/test/path.js index f788ff8..0f272e9 100644 --- a/test/path.js +++ b/test/path.js @@ -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'; @@ -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() + ); + }); }); diff --git a/test/support/caller.js b/test/support/caller.js new file mode 100644 index 0000000..86f38d1 --- /dev/null +++ b/test/support/caller.js @@ -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(); +}