Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

browser.test.ts

30 lines1.3 KB

1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { expect, it } from "@effect/vitest";
3import * as HostProcess from "@t3tools/shared/HostProcess";
4import * as Effect from "effect/Effect";
5import * as FileSystem from "effect/FileSystem";
6import * as Layer from "effect/Layer";
7import * as TestConsole from "effect/testing/TestConsole";
8import { Command } from "effect/cli";
9​
10import { browserCommand } from "./browser.ts";
11​
12it.effect("setup in a root shell warns that the server cannot run as root", () =>
13 Effect.gen(function* () {
14 // Every file read fails, so setup finds nothing to install and changes nothing.
15 yield* Command.runWith(browserCommand, { version: "0.0.0" })([
16 "setup",
17 "--base-dir",
18 "/nonexistent",
19 ]).pipe(
20 Effect.provide(FileSystem.layerNoop({})),
21 Effect.provideService(HostProcess.Platform, "linux"),
22 Effect.provideService(HostProcess.UserId, 0),
23 // A root user who follows the old advice runs setup through sudo.
24 Effect.provideService(HostProcess.Environment, { SUDO_USER: "root" }),
25 );
26 const output = (yield* TestConsole.logLines).join("\n");
27 expect(output).toContain("Chrome will not start its sandbox as root");
28 expect(output).not.toContain("ready");
29 }).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, TestConsole.layer))),
30);