Files
bun.sh/test/cli/run/run-eval.test.ts
Colin McDonnell 31814934f3 CLI flags (#6395)
* WIP

* WIP

* Improve helptext

* WIP

* WIP

* WIP

* WIP

* Clean up, implement warn_on_unrecognized_flag

* Fix struct

* Tweaks

* Fix bunx test

* Address reviews

* Init and create

* Updates

* bunx

* Tweaks

* Lockfile

* tweak

* tweak

* tweak

* tweak

* Remove comments

* Add back origin and port

* Remove logging

* Updates

* fmt

* fix rebasing mistakes

* bruh

* expose node builtins for -e

* add tests and fix it on windows

* a

* lol

* okay

* finish things up

* Update src/deps/zig-clap/clap/streaming.zig

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>

---------

Co-authored-by: dave caruso <me@paperdave.net>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2023-11-15 18:15:10 -08:00

43 lines
1.4 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { mkdirSync, realpathSync } from "fs";
import { bunEnv, bunExe } from "harness";
import { tmpdir } from "os";
import { join } from "path";
describe("bun -e", () => {
test("it works", async () => {
let { stdout } = Bun.spawnSync({
cmd: [bunExe(), "-e", 'console.log("hello world")'],
env: bunEnv,
});
expect(stdout.toString("utf8")).toEqual("hello world\n");
});
test("import, tsx, require in esm, import.meta", async () => {
const ref = await import("react");
let { stdout } = Bun.spawnSync({
cmd: [
bunExe(),
"-e",
'import {version} from "react"; console.log(JSON.stringify({version,file:import.meta.path,require:require("react").version})); console.log(<hello>world</hello>);',
],
env: bunEnv,
});
const json = {
version: ref.version,
file: join(process.cwd(), "[eval]"),
require: ref.version,
};
expect(stdout.toString("utf8")).toEqual(JSON.stringify(json) + "\n<hello>world</hello>\n");
});
test("error has source map info 1", async () => {
let { stdout, stderr } = Bun.spawnSync({
cmd: [bunExe(), "-e", '(throw new Error("hi" as 2))'],
env: bunEnv,
});
expect(stderr.toString("utf8")).toInclude('"hi" as 2');
expect(stderr.toString("utf8")).toInclude("Unexpected throw");
});
});