aboutsummaryrefslogtreecommitdiff
path: root/test/cli/run/run-process-env.test.ts
blob: 8303fe19cc240a707379e1551acd1c760531c222 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { describe, expect, test } from "bun:test";
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}': '${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");
  });
});