Skip to content

Commit d18d598

Browse files
committed
refactor(tests): streamline getCallerDirname integration test and remove unnecessary file operations
1 parent af3f238 commit d18d598

File tree

1 file changed

+6
-34
lines changed

1 file changed

+6
-34
lines changed

test/stack_path.test.ts

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { execFileSync } from "node:child_process";
2-
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
3-
import { join } from "node:path";
41

52
describe("stack_path", () => {
63
describe("extractCallerPath", () => {
@@ -144,37 +141,12 @@ describe("stack_path", () => {
144141
});
145142

146143
describe("getCallerDirname integration", () => {
147-
const fixturesDir = join(
148-
__dirname,
149-
"stack-path-fixtures-" + Math.random().toString(36).slice(2),
150-
);
151-
const callerScript = join(fixturesDir, "caller.js");
152-
const testScript = join(fixturesDir, "test-get-caller.js");
153-
154-
beforeAll(() => {
155-
mkdirSync(fixturesDir, { recursive: true });
156-
157-
// Create a script that calls getCallerDirname from the actual module
158-
writeFileSync(
159-
testScript,
160-
`const { getCallerDirname } = require('${join(__dirname, "../dist/stack_path.js").replace(/\\/g, "\\\\")}')
161-
process.stdout.write(getCallerDirname());`,
162-
);
163-
164-
// Create a caller script that requires the test script
165-
writeFileSync(callerScript, `require('./test-get-caller');`);
166-
});
167-
168-
afterAll(() => {
169-
rmSync(fixturesDir, { recursive: true, force: true });
170-
});
171-
172-
it("returns the directory of the calling script", () => {
173-
const result = execFileSync("node", [callerScript], {
174-
encoding: "utf8",
175-
cwd: fixturesDir,
176-
});
177-
expect(result).toBe(fixturesDir);
144+
it("returns the correct directory when called from a module", async () => {
145+
// Import and test the actual function
146+
const { getCallerDirname } = await import("../src/stack_path");
147+
const result = getCallerDirname();
148+
// Should return the directory of this test file
149+
expect(result).toBe(__dirname);
178150
});
179151
});
180152
});

0 commit comments

Comments
 (0)