Files
schpet__linear-cli/test/commands/document/document-list.test.ts
Peter Schilling cf770acf9d test: remove non-deterministic snapshot tests
Remove tests with inherently non-deterministic output:
- document-list: 3 tests displaying relative timestamps (e.g., '3 days ago')
- document-delete: 1 test with stack traces containing line numbers
- document-create: 1 test with stack traces containing machine-specific paths
- document-update: 2 tests with stack traces containing machine-specific paths
- document-view: 1 test with stack traces containing machine-specific paths

The fakeTime solution causes hangs with mock servers (known issue).
Stack traces contain machine-specific file paths that differ across environments.
2026-01-21 09:40:06 -08:00

108 lines
3.0 KiB
TypeScript

import { snapshotTest } from "@cliffy/testing"
import { listCommand } from "../../../src/commands/document/document-list.ts"
import { MockLinearServer } from "../../utils/mock_linear_server.ts"
import { commonDenoArgs } from "../../utils/test-helpers.ts"
// Test help output
await snapshotTest({
name: "Document List Command - Help Text",
meta: import.meta,
colors: false,
args: ["--help"],
denoArgs: commonDenoArgs,
async fn() {
await listCommand.parse()
},
})
// NOTE: Tests for "List All Documents", "Filter By Project", and "Filter By Issue"
// have been removed because they display relative timestamps (e.g., "3 days ago")
// which are inherently non-deterministic. The fakeTime solution causes hangs with
// mock servers (see project-list.test.ts for similar issue).
// Test JSON output (uses raw timestamps, not relative - deterministic)
await snapshotTest({
name: "Document List Command - JSON Output",
meta: import.meta,
colors: false,
args: ["--json"],
denoArgs: commonDenoArgs,
async fn() {
const server = new MockLinearServer([
{
queryName: "ListDocuments",
variables: { first: 50 },
response: {
data: {
documents: {
nodes: [
{
id: "doc-1",
title: "Delegation System Spec",
slugId: "d4b93e3b2695",
url:
"https://linear.app/test/document/delegation-system-spec-d4b93e3b2695",
updatedAt: "2026-01-18T10:30:00Z",
project: { name: "TinyCloud SDK", slugId: "tinycloud-sdk" },
issue: null,
creator: { name: "John Doe" },
},
],
pageInfo: { hasNextPage: false, endCursor: null },
},
},
},
},
])
try {
await server.start()
Deno.env.set("LINEAR_GRAPHQL_ENDPOINT", server.getEndpoint())
Deno.env.set("LINEAR_API_KEY", "Bearer test-token")
await listCommand.parse()
} finally {
await server.stop()
Deno.env.delete("LINEAR_GRAPHQL_ENDPOINT")
Deno.env.delete("LINEAR_API_KEY")
}
},
})
// Test empty results
await snapshotTest({
name: "Document List Command - Empty Results",
meta: import.meta,
colors: false,
args: [],
denoArgs: commonDenoArgs,
async fn() {
const server = new MockLinearServer([
{
queryName: "ListDocuments",
variables: { first: 50 },
response: {
data: {
documents: {
nodes: [],
pageInfo: { hasNextPage: false, endCursor: null },
},
},
},
},
])
try {
await server.start()
Deno.env.set("LINEAR_GRAPHQL_ENDPOINT", server.getEndpoint())
Deno.env.set("LINEAR_API_KEY", "Bearer test-token")
await listCommand.parse()
} finally {
await server.stop()
Deno.env.delete("LINEAR_GRAPHQL_ENDPOINT")
Deno.env.delete("LINEAR_API_KEY")
}
},
})