Files
bun.sh/test/bun.js/log-test.test.ts
Colin McDonnell f7f1b60444 Add bun-types, add typechecking, add child_process types (#1475)
* Add bun-types to packages

* Improve typing

* Fix types in tests

* Fix dts tests

* Run formatter

* Fix all type errors

* Add strict mode, fix type errors

* Add ffi changes

* Move workflows to root

* Add workflows

* Remove labeler

* Add child_process types

* Fix synthetic defaults issue

* Remove docs

* Move scripts

* Run prettier

* Include examples in typechecking

* captureStackTrace types

* moved captureStackTrace types to globals

* Address reviews

Co-authored-by: Colin McDonnell <colinmcd@alum.mit.edu>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
2022-11-09 15:40:40 -08:00

51 lines
1.2 KiB
TypeScript

import { it, expect } from "bun:test";
import { basename, dirname, join } from "path";
import * as fs from "fs";
import { readableStreamToText, spawnSync } from "bun";
it("should not log .env when quiet", async () => {
writeDirectoryTree("/tmp/log-test-silent", {
".env": "FOO=bar",
"bunfig.toml": `logLevel = "error"`,
"index.ts": "export default console.log('Here');",
});
const { stderr } = spawnSync({
cmd: ["bun", "index.ts"],
cwd: "/tmp/log-test-silent",
});
expect(stderr!.toString()).toBe("");
});
it("should log .env by default", async () => {
writeDirectoryTree("/tmp/log-test-silent", {
".env": "FOO=bar",
"bunfig.toml": ``,
"index.ts": "export default console.log('Here');",
});
const { stderr } = spawnSync({
cmd: ["bun", "index.ts"],
cwd: "/tmp/log-test-silent",
});
expect(stderr?.toString().includes(".env")).toBe(true);
});
function writeDirectoryTree(base, paths) {
for (const path of Object.keys(paths)) {
const content = paths[path];
const joined = join(base, path);
try {
fs.unlinkSync(joined);
} catch (e) {}
try {
fs.mkdirSync(join(base, dirname(path)), { recursive: true });
} catch (e) {}
fs.writeFileSync(joined, content);
}
}