snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Code scanning - action / CodeQL-Build (push) Failing after 2s
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Code scanning - action / CodeQL-Build (push) Failing after 2s
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
This commit is contained in:
106
packages/message-parser/tests/table.test.ts
Normal file
106
packages/message-parser/tests/table.test.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
import type { Table } from '../src';
|
||||
import { parse } from '../src';
|
||||
import { bold, link, plain, table, tableCell, tableRow } from './helpers';
|
||||
|
||||
// `fallback` is the [start, end] offset span of the table in the source; since
|
||||
// each input is exactly the table, that span is [0, input.length].
|
||||
test.each([
|
||||
// basic table, no alignment
|
||||
[
|
||||
`
|
||||
| Header 1 | Header 2 |
|
||||
| -------- | -------- |
|
||||
| Cell 1 | Cell 2 |
|
||||
`.trim(),
|
||||
[tableCell([plain('Header 1')]), tableCell([plain('Header 2')])],
|
||||
[tableRow([tableCell([plain('Cell 1')]), tableCell([plain('Cell 2')])])],
|
||||
],
|
||||
// alignment markers
|
||||
[
|
||||
`
|
||||
| Left | Center | Right |
|
||||
| :--- | :----: | ----: |
|
||||
| a | b | c |
|
||||
`.trim(),
|
||||
[tableCell([plain('Left')], 'left'), tableCell([plain('Center')], 'center'), tableCell([plain('Right')], 'right')],
|
||||
[tableRow([tableCell([plain('a')], 'left'), tableCell([plain('b')], 'center'), tableCell([plain('c')], 'right')])],
|
||||
],
|
||||
// multiple body rows
|
||||
[
|
||||
`
|
||||
| h |
|
||||
| - |
|
||||
| 1 |
|
||||
| 2 |
|
||||
`.trim(),
|
||||
[tableCell([plain('h')])],
|
||||
[tableRow([tableCell([plain('1')])]), tableRow([tableCell([plain('2')])])],
|
||||
],
|
||||
// header only (no body rows)
|
||||
[
|
||||
`
|
||||
| a | b |
|
||||
| - | - |
|
||||
`.trim(),
|
||||
[tableCell([plain('a')]), tableCell([plain('b')])],
|
||||
[],
|
||||
],
|
||||
// inline markup inside cells
|
||||
[
|
||||
`
|
||||
| Name | Link |
|
||||
| ---- | ---- |
|
||||
| **bold** | [rc](https://rocket.chat) |
|
||||
`.trim(),
|
||||
[tableCell([plain('Name')]), tableCell([plain('Link')])],
|
||||
[tableRow([tableCell([bold([plain('bold')])]), tableCell([link('https://rocket.chat', [plain('rc')])])])],
|
||||
],
|
||||
// escaped pipe inside a cell stays literal
|
||||
[
|
||||
`
|
||||
| a | b |
|
||||
| - | - |
|
||||
| x \\| y | z |
|
||||
`.trim(),
|
||||
[tableCell([plain('a')]), tableCell([plain('b')])],
|
||||
[tableRow([tableCell([plain('x | y')]), tableCell([plain('z')])])],
|
||||
],
|
||||
])('parses %p', (input, header, rows) => {
|
||||
expect(parse(input)).toEqual([table(header, rows, [0, input.length])]);
|
||||
});
|
||||
|
||||
test('normalizes ragged body rows to the header column count', () => {
|
||||
const input = ['| a | b |', '| - | - |', '| 1 |', '| 1 | 2 | 3 |'].join('\n');
|
||||
const [node] = parse(input) as [Table];
|
||||
|
||||
// every row has exactly 2 cells (header count): short row padded, long row truncated
|
||||
expect(node.value.rows.map((row) => row.value.length)).toEqual([2, 2]);
|
||||
expect(node.value.rows[0].value[1].value).toEqual([]); // padded empty cell
|
||||
expect(node.value.rows[1].value.map((cell) => cell.value)).toEqual([[plain('1')], [plain('2')]]); // extra 3rd cell dropped
|
||||
});
|
||||
|
||||
test('exposes the source offsets as fallback for renderers without table support', () => {
|
||||
const input = '| a | b |\n| - | - |\n| 1 | 2 |';
|
||||
const [node] = parse(input) as [ReturnType<typeof table>];
|
||||
expect(node.fallback).toEqual([0, input.length]);
|
||||
// the offsets slice back to the original markup
|
||||
expect(input.slice(node.fallback![0], node.fallback![1])).toBe(input);
|
||||
});
|
||||
|
||||
test.each([
|
||||
// no delimiter row -> not a table, plain paragraph
|
||||
['| just | text |', [{ type: 'PARAGRAPH', value: [plain('| just | text |')] }]],
|
||||
// missing trailing pipe -> not a table (v1 requires surrounding pipes)
|
||||
[
|
||||
`
|
||||
| a | b
|
||||
| - | -
|
||||
`.trim(),
|
||||
[
|
||||
{ type: 'PARAGRAPH', value: [plain('| a | b')] },
|
||||
{ type: 'PARAGRAPH', value: [plain('| - | -')] },
|
||||
],
|
||||
],
|
||||
])('does not parse %p as table', (input, output) => {
|
||||
expect(parse(input)).toEqual(output);
|
||||
});
|
||||
Reference in New Issue
Block a user