|
1 | | -import { execFileSync } from "node:child_process"; |
2 | | -import { mkdirSync, rmSync, writeFileSync } from "node:fs"; |
3 | | -import { join } from "node:path"; |
4 | 1 |
|
5 | 2 | describe("stack_path", () => { |
6 | 3 | describe("extractCallerPath", () => { |
@@ -144,37 +141,12 @@ describe("stack_path", () => { |
144 | 141 | }); |
145 | 142 |
|
146 | 143 | 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); |
178 | 150 | }); |
179 | 151 | }); |
180 | 152 | }); |
0 commit comments