diff options
author | 2023-09-28 23:07:51 -0300 | |
---|---|---|
committer | 2023-09-28 19:07:51 -0700 | |
commit | e1117c6ae53f880e2f4c1fc01c305e78da5f234a (patch) | |
tree | 73dca517e5754d259f369664eace08dcd5e0fcf5 /test | |
parent | 4bdec01619ee7db408b21477e1f7860d9bfdf789 (diff) | |
download | bun-e1117c6ae53f880e2f4c1fc01c305e78da5f234a.tar.gz bun-e1117c6ae53f880e2f4c1fc01c305e78da5f234a.tar.zst bun-e1117c6ae53f880e2f4c1fc01c305e78da5f234a.zip |
Add local tarball install #5812 (#6118)
* check if the value passed for add command is a local tarball and install it, test for local tarball
* use bunExe()
* use absolute path to copy tarball
* fmt ts
Diffstat (limited to 'test')
-rw-r--r-- | test/cli/install/bun-add.test.ts | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/test/cli/install/bun-add.test.ts b/test/cli/install/bun-add.test.ts index eff7fa843..3e3e919c3 100644 --- a/test/cli/install/bun-add.test.ts +++ b/test/cli/install/bun-add.test.ts @@ -1,7 +1,7 @@ import { file, spawn } from "bun"; import { afterAll, afterEach, beforeAll, beforeEach, expect, it } from "bun:test"; import { bunExe, bunEnv as env } from "harness"; -import { access, mkdir, mkdtemp, readlink, realpath, rm, writeFile } from "fs/promises"; +import { access, mkdir, mkdtemp, readlink, realpath, rm, writeFile, copyFile } from "fs/promises"; import { join, relative } from "path"; import { tmpdir } from "os"; import { @@ -1627,3 +1627,48 @@ it("should add dependency alongside peerDependencies", async () => { }); await access(join(package_dir, "bun.lockb")); }); + +it("should add local tarball dependency", async () => { + const urls: string[] = []; + setHandler(dummyRegistry(urls)); + await writeFile( + join(package_dir, "package.json"), + JSON.stringify({ + name: "foo", + version: "0.0.1", + }), + ); + const tarball = "baz-0.0.3.tgz"; + const absolutePath = join(__dirname, tarball); + await copyFile(absolutePath, join(package_dir, tarball)); + const { stdout, stderr, exited } = spawn({ + cmd: [bunExe(), "add", tarball], + cwd: package_dir, + stdout: null, + stdin: "pipe", + stderr: "pipe", + env, + }); + expect(stderr).toBeDefined(); + const err = await new Response(stderr).text(); + expect(err).toContain("Saved lockfile"); + expect(stdout).toBeDefined(); + const out = await new Response(stdout).text(); + expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ + "", + " installed baz@baz-0.0.3.tgz with binaries:", + " - baz-run", + "", + "", + " 1 packages installed", + ]); + expect(await exited).toBe(0); + expect(urls.sort()).toBeEmpty(); + expect(requested).toBe(0); + expect(await readdirSorted(join(package_dir, "node_modules", "baz"))).toEqual(["index.js", "package.json"]); + const package_json = await file(join(package_dir, "node_modules", "baz", "package.json")).json(); + expect(package_json.name).toBe("baz"); + expect(package_json.version).toBe("0.0.3"); + expect(await file(join(package_dir, "package.json")).text()).toInclude('"baz-0.0.3.tgz"'), + await access(join(package_dir, "bun.lockb")); +}); |