diff options
Diffstat (limited to '')
-rw-r--r-- | test/cli/run/run-process-env.test.ts | 19 | ||||
-rw-r--r-- | test/harness.ts | 9 |
2 files changed, 25 insertions, 3 deletions
diff --git a/test/cli/run/run-process-env.test.ts b/test/cli/run/run-process-env.test.ts index 8d8eb0b07..1d7cb2c56 100644 --- a/test/cli/run/run-process-env.test.ts +++ b/test/cli/run/run-process-env.test.ts @@ -1,16 +1,31 @@ import { describe, expect, test } from "bun:test"; -import { bunRunAsScript, tempDirWithFiles } from "harness"; +import { bunExe, bunRunAsScript, tempDirWithFiles } from "harness"; describe("process.env", () => { test("npm_lifecycle_event", () => { const scriptName = "start:dev"; const dir = tempDirWithFiles("processenv", { - "package.json": `{'scripts': {'${scriptName}': 'bun run index.ts'}}`, + "package.json": `{'scripts': {'${scriptName}': '${bunExe()} run index.ts'}}`, "index.ts": "console.log(process.env.npm_lifecycle_event);", }); const { stdout } = bunRunAsScript(dir, scriptName); expect(stdout).toBe(scriptName); }); + + // https://github.com/oven-sh/bun/issues/3589 + test('npm_lifecycle_event should have the value of the last call', () => { + const dir = tempDirWithFiles("processenv_ls_call", { + "package.json": `{"scripts": { "first": "${bunExe()} run --cwd lsc second" } }`, + "lsc": { + "package.json": `{"scripts": { "second": "${bunExe()} run index.ts" } }`, + "index.ts": "console.log(process.env.npm_lifecycle_event);", + } + }); + + + const { stdout } = bunRunAsScript(dir, "first"); + expect(stdout).toBe("second"); + }); }); diff --git a/test/harness.ts b/test/harness.ts index 8b850bbfc..ab3ae5ca2 100644 --- a/test/harness.ts +++ b/test/harness.ts @@ -84,9 +84,16 @@ export function hideFromStackTrace(block: CallableFunction) { }); } -export function tempDirWithFiles(basename: string, files: Record<string, string>) { +export function tempDirWithFiles(basename: string, files: Record<string, string | Record<string, string>>) { const dir = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), basename + "_")); for (const [name, contents] of Object.entries(files)) { + if (typeof contents === "object") { + fs.mkdirSync(path.join(dir, name)); + for (const [_name, _contents] of Object.entries(contents)) { + fs.writeFileSync(path.join(dir, name, _name), _contents); + } + continue; + } fs.writeFileSync(path.join(dir, name), contents); } return dir; |