64 lines
2.2 KiB
TypeScript
64 lines
2.2 KiB
TypeScript
import { EnvironmentId, WS_METHODS } from "@t3tools/contracts";
|
|
import { describe, expect, it } from "@effect/vitest";
|
|
import * as Effect from "effect/Effect";
|
|
|
|
import {
|
|
observeBackgroundActivitySubscription,
|
|
retainedBackgroundScopes,
|
|
wasRecentlyInteracted,
|
|
} from "./backgroundActivityReporter.ts";
|
|
|
|
describe("wasRecentlyInteracted", () => {
|
|
it("expires interaction independently of window focus", () => {
|
|
expect(wasRecentlyInteracted(10_000, 55_000)).toBe(true);
|
|
expect(wasRecentlyInteracted(10_000, 55_001)).toBe(false);
|
|
});
|
|
|
|
it("rejects future timestamps", () => {
|
|
expect(wasRecentlyInteracted(10_001, 10_000)).toBe(false);
|
|
});
|
|
|
|
it.effect("retains an observed subscription until its returned finalizer runs", () =>
|
|
Effect.gen(function* () {
|
|
const environmentId = EnvironmentId.make("environment-observation-test");
|
|
const scope = { type: "vcs-status" as const, cwd: "/repo" };
|
|
const release = yield* observeBackgroundActivitySubscription({
|
|
environmentId,
|
|
method: WS_METHODS.subscribeVcsStatus,
|
|
input: { cwd: scope.cwd },
|
|
});
|
|
|
|
expect(retainedBackgroundScopes(environmentId)).toEqual([scope]);
|
|
|
|
yield* release;
|
|
expect(retainedBackgroundScopes(environmentId)).toEqual([]);
|
|
}),
|
|
);
|
|
|
|
it.effect("keeps delimiter-containing environment and scope values distinct", () =>
|
|
Effect.gen(function* () {
|
|
const firstEnvironmentId = EnvironmentId.make("a");
|
|
const secondEnvironmentId = EnvironmentId.make("a:vcs-status:b");
|
|
const releaseFirst = yield* observeBackgroundActivitySubscription({
|
|
environmentId: firstEnvironmentId,
|
|
method: WS_METHODS.subscribeVcsStatus,
|
|
input: { cwd: "b:vcs-status:c" },
|
|
});
|
|
const releaseSecond = yield* observeBackgroundActivitySubscription({
|
|
environmentId: secondEnvironmentId,
|
|
method: WS_METHODS.subscribeVcsStatus,
|
|
input: { cwd: "c" },
|
|
});
|
|
|
|
expect(retainedBackgroundScopes(firstEnvironmentId)).toEqual([
|
|
{ type: "vcs-status", cwd: "b:vcs-status:c" },
|
|
]);
|
|
expect(retainedBackgroundScopes(secondEnvironmentId)).toEqual([
|
|
{ type: "vcs-status", cwd: "c" },
|
|
]);
|
|
|
|
yield* Effect.all([releaseFirst, releaseSecond]);
|
|
}),
|
|
);
|
|
});
|