stack/packages/stack-shared/src/utils/strings.nicify.test.ts
Konsti Wohlwend 3d4c608187
Customizable ports (#962)
<!--
ONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md

-->

<!-- RECURSEML_SUMMARY:START -->

## High-level PR Summary

This PR changes the default development ports for several background
services to avoid conflicts. PostgreSQL moves from port `5432` to
`8128`, Inbucket SMTP from `2500` to `8129`, Inbucket POP3 from `1100`
to `8130`, and the OpenTelemetry collector from `4318` to `8131`. All
references across configuration files, Docker Compose setups,
environment files, CI/CD workflows, test files, and documentation have
been updated to reflect these new port assignments. A knowledge base
document has been added to document the new port mappings.

⏱️ Estimated Review Time: 15-30 minutes

<details>
<summary>💡 Review Order Suggestion</summary>

| Order | File Path |
| --- | --- |
| 1 | `claude/CLAUDE-KNOWLEDGE.md` |
| 2 | `apps/dev-launchpad/public/index.html` |
| 3 | `docker/dependencies/docker.compose.yaml` |
| 4 | `docker/emulator/docker.compose.yaml` |
| 5 | `apps/backend/.env` |
| 6 | `apps/backend/.env.development` |
| 7 | `docker/server/.env.example` |
| 8 | `package.json` |
| 9 | `.devcontainer/devcontainer.json` |
| 10 | `apps/e2e/.env.development` |
| 11 | `.github/workflows/check-prisma-migrations.yaml` |
| 12 | `.github/workflows/docker-server-test.yaml` |
| 13 | `.github/workflows/e2e-api-tests.yaml` |
| 14 | `.github/workflows/e2e-source-of-truth-api-tests.yaml` |
| 15 | `.github/workflows/restart-dev-and-test.yaml` |
| 16 |
`apps/e2e/tests/backend/endpoints/api/v1/internal/email-drafts.test.ts`
|
| 17 | `apps/e2e/tests/backend/endpoints/api/v1/internal/email.test.ts`
|
| 18 | `apps/e2e/tests/backend/endpoints/api/v1/send-email.test.ts` |
| 19 |
`apps/e2e/tests/backend/endpoints/api/v1/unsubscribe-link.test.ts` |
| 20 | `apps/e2e/tests/backend/workflows.test.ts` |
| 21 | `docs/templates/others/self-host.mdx` |

</details>

[![Need help? Join our
Discord](https://img.shields.io/badge/Need%20help%3F%20Join%20our%20Discord-5865F2?style=plastic&logo=discord&logoColor=white)](https://discord.gg/n3SsVDAW6U)

[![Analyze latest
changes](21c3d5c362/?repo_owner=stack-auth&repo_name=stack-auth&pr_number=962)

<!-- RECURSEML_SUMMARY:END -->

<!-- ELLIPSIS_HIDDEN -->


----

> [!IMPORTANT]
> This PR introduces customizable development ports using
`NEXT_PUBLIC_STACK_PORT_PREFIX`, updating configurations, documentation,
and tests accordingly.
> 
>   - **Behavior**:
> - Default development ports for services are now customizable via
`NEXT_PUBLIC_STACK_PORT_PREFIX`.
> - PostgreSQL port changed from `5432` to
`${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}28`.
> - Inbucket SMTP port changed from `2500` to
`${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}29`.
> - Inbucket POP3 port changed from `1100` to
`${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}30`.
> - OpenTelemetry collector port changed from `4318` to
`${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}31`.
>   - **Configuration**:
> - Updated `docker.compose.yaml` to use new port variables for services
like PostgreSQL, Inbucket, and OpenTelemetry.
> - Environment files in `apps/backend`, `apps/dashboard`, and
`apps/e2e` updated to use `NEXT_PUBLIC_STACK_PORT_PREFIX`.
> - `package.json` scripts updated to reflect new port configurations.
>   - **Documentation**:
>     - Added `CLAUDE-KNOWLEDGE.md` to document new port mappings.
>     - Updated `self-host.mdx` to reflect new port configurations.
>   - **Testing**:
> - Updated test files in `apps/e2e/tests` to use new port
configurations.
>     - Added `helpers/ports.ts` for port-related utilities in tests.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup>
for 76ef55f58f. You can
[customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>

----


<!-- ELLIPSIS_HIDDEN -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enable configurable development ports via a
NEXT_PUBLIC_STACK_PORT_PREFIX, allowing parallel local environments with
custom port prefixes.

- **Bug Fixes**
- Updated local service port mappings and CI/workflow settings so
tooling and tests use the new prefixed ports consistently.

- **Documentation**
- Added docs and contributor guidance for running multiple parallel
workspaces with custom port prefixes.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: N2D4 <N2D4@users.noreply.github.com>
2025-10-20 15:24:47 -07:00

254 lines
6.5 KiB
TypeScript

import { describe, expect, test } from "vitest";
import { NicifyOptions, deindent, nicify } from "./strings";
describe("nicify", () => {
describe("primitive values", () => {
test("numbers", () => {
expect(nicify(123)).toBe("123");
expect(nicify(123n)).toBe("123n");
});
test("strings", () => {
expect(nicify("hello")).toBe('"hello"');
});
test("booleans", () => {
expect(nicify(true)).toBe("true");
expect(nicify(false)).toBe("false");
});
test("null and undefined", () => {
expect(nicify(null)).toBe("null");
expect(nicify(undefined)).toBe("undefined");
});
test("symbols", () => {
expect(nicify(Symbol("test"))).toBe("Symbol(test)");
});
});
describe("arrays", () => {
test("empty array", () => {
expect(nicify([])).toBe("[]");
});
test("single-element array", () => {
expect(nicify([1])).toBe("[1]");
});
test("single-element array with long content", () => {
expect(nicify(["123123123123123"])).toBe('["123123123123123"]');
});
test("flat array", () => {
expect(nicify([1, 2, 3])).toBe("[1, 2, 3]");
});
test("longer array", () => {
expect(nicify([10000, 2, 3])).toBe(deindent`
[
10000,
2,
3,
]
`);
});
test("nested array", () => {
expect(nicify([1, [2, 3]])).toBe(deindent`
[
1,
[2, 3],
]
`);
});
});
describe("objects", () => {
test("empty object", () => {
expect(nicify({})).toBe("{}");
});
test("simple object", () => {
expect(nicify({ a: 1 })).toBe('{ "a": 1 }');
});
test("multiline object", () => {
expect(nicify({ a: 1, b: 2 })).toBe(deindent`
{
"a": 1,
"b": 2,
}
`);
});
});
describe("custom classes", () => {
test("class instance", () => {
class TestClass {
constructor(public value: number) {}
}
expect(nicify(new TestClass(42))).toBe('TestClass { "value": 42 }');
});
});
describe("built-in objects", () => {
test("URL", () => {
expect(nicify(new URL("https://example.com"))).toBe('URL("https://example.com/")');
});
test("TypedArrays", () => {
expect(nicify(new Uint8Array([1, 2, 3]))).toBe("Uint8Array([1,2,3])");
expect(nicify(new Int32Array([1, 2, 3]))).toBe("Int32Array([1,2,3])");
});
test("Error objects", () => {
const error = new Error("test error");
const nicifiedError = nicify({ error });
expect(nicifiedError).toMatch(new RegExp(deindent`
^\{
"error": Error: test error
Stack:
at (.|\\n)*
\}$
`));
});
test("Error objects with cause and an extra property", () => {
const error = new Error("test error", { cause: new Error("cause") });
(error as any).extra = "something";
const nicifiedError = nicify(error, { lineIndent: "--" });
expect(nicifiedError).toMatch(new RegExp(deindent`
^Error: test error
--Stack:
----at (.|\\n)+
--Extra properties: \{ "extra": "something" \}
--Cause:
----Error: cause
------Stack:
--------at (.|\\n)+$
`));
});
test("Headers", () => {
const headers = new Headers();
headers.append("Content-Type", "application/json");
headers.append("Accept", "text/plain");
expect(nicify(headers)).toBe(deindent`
Headers {
"accept": "text/plain",
"content-type": "application/json",
}`
);
});
});
describe("multiline strings", () => {
test("basic multiline", () => {
expect(nicify("line1\nline2")).toBe('deindent`\n line1\n line2\n`');
});
test("multiline with trailing newline", () => {
expect(nicify("line1\nline2\n")).toBe('deindent`\n line1\n line2\n` + "\\n"');
});
test("multiline with dollar sign", () => {
expect(nicify("a\n$b\nc")).toBe('deindent`\n a\n $b\n c\n`');
});
test("multiline with dollar sign interpolation", () => {
expect(nicify("a\n${b\nc")).toBe('deindent`\n a\n \\${b\n c\n`');
});
});
describe("circular references", () => {
test("object with self reference", () => {
const circular: any = { a: 1 };
circular.self = circular;
expect(nicify(circular)).toBe(deindent`
{
"a": 1,
"self": Ref<value>,
}`
);
});
});
describe("configuration options", () => {
test("maxDepth", () => {
const deep = { a: { b: { c: { d: { e: 1 } } } } };
expect(nicify(deep, { maxDepth: 2 })).toBe('{ "a": { "b": { ... } } }');
});
test("lineIndent", () => {
expect(nicify({ a: 1, b: 2 }, { lineIndent: " " })).toBe(deindent`
{
"a": 1,
"b": 2,
}
`);
});
test("hideFields", () => {
expect(nicify({ a: 1, b: 2, secret: "hidden" }, { hideFields: ["secret"] })).toBe(deindent`
{
"a": 1,
"b": 2,
<some fields may have been hidden>,
}
`);
});
});
describe("custom overrides", () => {
test("override with custom type", () => {
expect(nicify({ type: "special" }, {
overrides: ((value: unknown) => {
if (typeof value === "object" && value && "type" in value && (value as any).type === "special") {
return "SPECIAL";
}
return null;
}) as NicifyOptions["overrides"]
})).toBe("SPECIAL");
});
});
describe("functions", () => {
test("named function", () => {
expect(nicify(function namedFunction() {})).toBe("function namedFunction(...) { ... }");
});
test("arrow function", () => {
expect(nicify(() => {})).toBe("(...) => { ... }");
});
});
describe("Nicifiable interface", () => {
test("object implementing Nicifiable", () => {
const nicifiable = {
value: 42,
getNicifiableKeys() {
return ["value"];
},
getNicifiedObjectExtraLines() {
return ["// custom comment"];
}
};
expect(nicify(nicifiable)).toBe(deindent`
{
"value": 42,
// custom comment,
}
`);
});
});
describe("unknown types", () => {
test("object without prototype", () => {
const unknownType = Object.create(null);
unknownType.value = "test";
expect(nicify(unknownType)).toBe('{ "value": "test" }');
});
});
});