Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
25 changes: 25 additions & 0 deletions .github/workflows/ci-superdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,28 @@ jobs:
- name: Run UMD smoke test
working-directory: packages/superdoc/tests/umd-smoke
run: pnpm test

cli-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
cache: pnpm

- uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.8

- name: Install dependencies
run: pnpm install

- name: Build superdoc (CLI runtime dependency)
run: pnpm run build:superdoc

- name: Run CLI tests
run: pnpm run test:cli
23 changes: 3 additions & 20 deletions apps/cli/src/__tests__/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:tes
import { access, copyFile, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { run } from '../index';
import { resolveListDocFixture, resolveSourceDocFixture } from './fixtures';

type RunResult = {
code: number;
Expand Down Expand Up @@ -43,27 +44,9 @@ type ErrorEnvelope = {

const TEST_DIR = join(import.meta.dir, 'fixtures-cli');
const STATE_DIR = join(TEST_DIR, 'state');
const SOURCE_DOC = join(import.meta.dir, '../../../../e2e-tests/test-data/basic-documents/advanced-text.docx');
const LIST_SOURCE_DOC_CANDIDATES = [
join(import.meta.dir, '../../../../devtools/document-api-tests/fixtures/matrix-list.input.docx'),
join(import.meta.dir, '../../../../e2e-tests/test-data/basic-documents/lists-complex-items.docx'),
];
const SAMPLE_DOC = join(TEST_DIR, 'sample.docx');
const LIST_SAMPLE_DOC = join(TEST_DIR, 'lists-sample.docx');

async function resolveListSourceDoc(): Promise<string> {
for (const candidate of LIST_SOURCE_DOC_CANDIDATES) {
try {
await access(candidate);
return candidate;
} catch {
// try next candidate
}
}

throw new Error(`No list fixture found. Tried: ${LIST_SOURCE_DOC_CANDIDATES.join(', ')}`);
}

async function runCli(args: string[], stdinBytes?: Uint8Array): Promise<RunResult> {
let stdout = '';
let stderr = '';
Expand Down Expand Up @@ -164,8 +147,8 @@ describe('superdoc CLI', () => {
beforeAll(async () => {
process.env.SUPERDOC_CLI_STATE_DIR = STATE_DIR;
await mkdir(TEST_DIR, { recursive: true });
await copyFile(SOURCE_DOC, SAMPLE_DOC);
await copyFile(await resolveListSourceDoc(), LIST_SAMPLE_DOC);
await copyFile(await resolveSourceDocFixture(), SAMPLE_DOC);
await copyFile(await resolveListDocFixture(), LIST_SAMPLE_DOC);
});

beforeEach(async () => {
Expand Down
32 changes: 4 additions & 28 deletions apps/cli/src/__tests__/conformance/harness.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { access, copyFile, mkdtemp, mkdir, rm } from 'node:fs/promises';
import { copyFile, mkdtemp, mkdir, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { run } from '../../index';
import { resolveListDocFixture, resolveSourceDocFixture } from '../fixtures';

type RunResult = {
code: number;
Expand Down Expand Up @@ -47,31 +48,6 @@ export type ListItemAddress = {
nodeId: string;
};

const REPO_ROOT = path.resolve(import.meta.dir, '../../../../../');
const SOURCE_DOC = path.join(REPO_ROOT, 'e2e-tests/test-data/basic-documents/advanced-text.docx');
const LIST_SOURCE_DOC_CANDIDATES = [
path.join(REPO_ROOT, 'devtools/document-api-tests/fixtures/matrix-list.input.docx'),
path.join(REPO_ROOT, 'e2e-tests/test-data/basic-documents/lists-complex-items.docx'),
];

let resolvedListSourceDoc: string | null = null;

async function resolveListSourceDoc(): Promise<string> {
if (resolvedListSourceDoc != null) return resolvedListSourceDoc;

for (const candidate of LIST_SOURCE_DOC_CANDIDATES) {
try {
await access(candidate);
resolvedListSourceDoc = candidate;
return candidate;
} catch {
// try next candidate
}
}

throw new Error(`No list fixture found. Tried: ${LIST_SOURCE_DOC_CANDIDATES.join(', ')}`);
}

function parseEnvelope(raw: RunResult): CommandEnvelope {
const source = raw.stdout.trim() || raw.stderr.trim();
if (!source) {
Expand Down Expand Up @@ -133,13 +109,13 @@ export class ConformanceHarness {

async copyFixtureDoc(label: string): Promise<string> {
const filePath = path.join(this.docsDir, `${this.nextId()}-${label}.docx`);
await copyFile(SOURCE_DOC, filePath);
await copyFile(await resolveSourceDocFixture(), filePath);
return filePath;
}

async copyListFixtureDoc(label: string): Promise<string> {
const filePath = path.join(this.docsDir, `${this.nextId()}-${label}.docx`);
await copyFile(await resolveListSourceDoc(), filePath);
await copyFile(await resolveListDocFixture(), filePath);
return filePath;
}

Expand Down
44 changes: 44 additions & 0 deletions apps/cli/src/__tests__/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { access } from 'node:fs/promises';
import path from 'node:path';

const REPO_ROOT = path.resolve(import.meta.dir, '../../../..');

const SOURCE_DOC_CANDIDATES = [
path.join(REPO_ROOT, 'packages/super-editor/src/tests/data/advanced-text.docx'),
path.join(REPO_ROOT, 'e2e-tests/test-data/basic-documents/advanced-text.docx'),
];

const LIST_SOURCE_DOC_CANDIDATES = [
path.join(REPO_ROOT, 'packages/super-editor/src/tests/data/basic-list.docx'),
path.join(REPO_ROOT, 'packages/super-editor/src/tests/data/list_with_indents.docx'),
path.join(REPO_ROOT, 'devtools/document-api-tests/fixtures/matrix-list.input.docx'),
path.join(REPO_ROOT, 'e2e-tests/test-data/basic-documents/lists-complex-items.docx'),
];

let resolvedSourceDoc: string | null = null;
let resolvedListSourceDoc: string | null = null;

async function resolveFixture(candidates: string[], fixtureLabel: string): Promise<string> {
for (const candidate of candidates) {
try {
await access(candidate);
return candidate;
} catch {
// Try next candidate.
}
}

throw new Error(`No ${fixtureLabel} fixture found. Tried: ${candidates.join(', ')}`);
}

export async function resolveSourceDocFixture(): Promise<string> {
if (resolvedSourceDoc != null) return resolvedSourceDoc;
resolvedSourceDoc = await resolveFixture(SOURCE_DOC_CANDIDATES, 'source document');
return resolvedSourceDoc;
}

export async function resolveListDocFixture(): Promise<string> {
if (resolvedListSourceDoc != null) return resolvedListSourceDoc;
resolvedListSourceDoc = await resolveFixture(LIST_SOURCE_DOC_CANDIDATES, 'list');
return resolvedListSourceDoc;
}
4 changes: 2 additions & 2 deletions apps/cli/src/__tests__/host.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { tmpdir } from 'node:os';
import path from 'node:path';
import type { CliOperationId } from '../cli';
import { validateOperationResponseData } from '../lib/operation-args';
import { resolveSourceDocFixture } from './fixtures';

const REPO_ROOT = path.resolve(import.meta.dir, '../../../..');
const CLI_BIN = path.join(REPO_ROOT, 'apps/cli/src/index.ts');
const SOURCE_DOC = path.join(REPO_ROOT, 'e2e-tests/test-data/basic-documents/advanced-text.docx');

type JsonRpcMessage = {
jsonrpc: '2.0';
Expand Down Expand Up @@ -230,7 +230,7 @@ describe('CLI host mode', () => {
await mkdir(stateDir, { recursive: true });

const docPath = path.join(stateDir, 'host-conformance.docx');
await copyFile(SOURCE_DOC, docPath);
await copyFile(await resolveSourceDocFixture(), docPath);

const host = launchHost(stateDir);

Expand Down
6 changes: 3 additions & 3 deletions apps/cli/src/__tests__/legacy-compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { beforeAll, beforeEach, describe, expect, test } from 'bun:test';
import { copyFile, mkdir } from 'node:fs/promises';
import { join } from 'node:path';
import { run } from '../index';
import { resolveSourceDocFixture } from './fixtures';

type RunResult = {
code: number;
Expand All @@ -10,7 +11,6 @@ type RunResult = {
};

const TEST_DIR = join(import.meta.dir, 'fixtures-cli-legacy');
const SOURCE_DOC = join(import.meta.dir, '../../../../e2e-tests/test-data/basic-documents/advanced-text.docx');
const SAMPLE_DOC = join(TEST_DIR, 'sample.docx');
const REPLACE_DOC = join(TEST_DIR, 'replace-test.docx');

Expand All @@ -36,7 +36,7 @@ async function runCli(args: string[]): Promise<RunResult> {
describe('legacy command compatibility', () => {
beforeAll(async () => {
await mkdir(TEST_DIR, { recursive: true });
await copyFile(SOURCE_DOC, SAMPLE_DOC);
await copyFile(await resolveSourceDocFixture(), SAMPLE_DOC);
});

test('search supports legacy pretty output by default', async () => {
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('legacy command compatibility', () => {

describe('replace-legacy', () => {
beforeEach(async () => {
await copyFile(SOURCE_DOC, REPLACE_DOC);
await copyFile(await resolveSourceDocFixture(), REPLACE_DOC);
});

test('replace-legacy supports legacy pretty output by default', async () => {
Expand Down
19 changes: 0 additions & 19 deletions e2e-tests/Dockerfile

This file was deleted.

Loading
Loading