Skip to content
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "NODE_OPTIONS='--experimental-strip-types' vp fmt resources/ && NODE_OPTIONS='--experimental-strip-types' vp lint --fix",
"test:lint": "NODE_OPTIONS='--experimental-strip-types' vp fmt --check resources/ && NODE_OPTIONS='--experimental-strip-types' vp lint",
"test:types": "tsc --noEmit && tsc --noEmit --project tests/tsconfig.json",
"test:unit": "node --experimental-strip-types --test tests/Unit/*.test.ts"
"test:unit": "vp test run --config tests/unit.config.ts"
},
"dependencies": {
"@headlessui/react": "^2.2.10",
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/CommitImages.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="node" />
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { test } from 'vite-plus/test';
import type { ReactElement, SyntheticEvent } from 'react';
import { CommitImages } from '../../resources/js/components/commit-images';
import type { Commit } from '../../resources/js/types/commit';
Expand Down Expand Up @@ -56,11 +56,11 @@ function renderedImage() {
}>;
}

void test('keeps the uploaded image until it fails to load', () => {
test('keeps the uploaded image until it fails to load', () => {
assert.equal(renderedImage().props.src, '/images/missing.webp');
});

void test('replaces a failed image with the site logo without retrying the fallback', () => {
test('replaces a failed image with the site logo without retrying the fallback', () => {
let replacements = 0;
let source = '/images/missing.webp';
const target = {
Expand Down Expand Up @@ -88,6 +88,6 @@ void test('replaces a failed image with the site logo without retrying the fallb
assert.equal(replacements, 1);
});

void test('renders nothing when there are no uploaded images', () => {
test('renders nothing when there are no uploaded images', () => {
assert.equal(CommitImages({ commit: { ...commit, images: [] } }), null);
});
14 changes: 7 additions & 7 deletions tests/Unit/CommitMutationOptions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="node" />
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { test } from 'vite-plus/test';
import {
restoreFeedCommit,
updateQuotedCommits,
Expand All @@ -24,7 +24,7 @@ const tombstone: DeletedCommit = {
deleted_at: '2026-10-16T12:00:00Z',
};

void test('replaces every loaded quote embed with a tombstone without changing row order or unrelated rows', () => {
test('replaces every loaded quote embed with a tombstone without changing row order or unrelated rows', () => {
const rows = [...quotes, { ...quotes[1], id: 'second-quote' }];
const updated = updateQuotedCommits(rows, tombstone);
assert.deepEqual(
Expand All @@ -39,7 +39,7 @@ void test('replaces every loaded quote embed with a tombstone without changing r
assert.strictEqual(rows[1].quoted_commit, target);
});

void test('restores embedded reply content even when the target is absent from the loaded feed', () => {
test('restores embedded reply content even when the target is absent from the loaded feed', () => {
const deleted = updateQuotedCommits(quotes, tombstone);
const restored = { ...target, body: 'Restored body' };
const updated = updateQuotedCommits(deleted, restored);
Expand All @@ -49,13 +49,13 @@ void test('restores embedded reply content even when the target is absent from t
assert.strictEqual(updated[2], quotes[2]);
});

void test('keeps the same rows when no loaded commit quotes the changed target', () => {
test('keeps the same rows when no loaded commit quotes the changed target', () => {
const updated = updateQuotedCommits(quotes, { ...target, id: 'other' });
assert.deepEqual(updated, quotes);
updated.forEach((row, index) => assert.strictEqual(row, quotes[index]));
});

void test('restores a ranked row by score without reordering already loaded rows', () => {
test('restores a ranked row by score without reordering already loaded rows', () => {
const rows = [
{ id: 'top', hot_score: 50, created_at: '2026-10-14' },
{ id: 'middle', hot_score: 10, created_at: '2026-10-16' },
Expand All @@ -77,7 +77,7 @@ void test('restores a ranked row by score without reordering already loaded rows
assert.deepEqual(restoreFeedCommit(updated, restored, 'ranked'), updated);
});

void test('restores a latest row by creation time and a saved row by bookmark order', () => {
test('restores a latest row by creation time and a saved row by bookmark order', () => {
const rows = [
{ id: 'newest', created_at: '2026-10-16', saved_order: 4 },
{ id: 'oldest', created_at: '2026-10-14', saved_order: 2 },
Expand All @@ -97,7 +97,7 @@ void test('restores a latest row by creation time and a saved row by bookmark or
);
});

void test('restoring a target also refreshes its embeds while preserving the loaded rows', () => {
test('restoring a target also refreshes its embeds while preserving the loaded rows', () => {
const restored = { ...target, hot_score: 5, created_at: '2026-10-16' };
const rows = restoreFeedCommit(quotes, restored, 'ranked');
assert.strictEqual(
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/CommitQuoteButton.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="node" />

import assert from 'node:assert/strict';
import { test } from 'node:test';
import { test } from 'vite-plus/test';
import { createInertiaApp } from '@inertiajs/react';
import { renderToString } from 'react-dom/server';
import { CommitQuoteButton } from '../../resources/js/components/commit-quote-button';
Expand All @@ -14,7 +14,7 @@ const commit = {
} as Commit;

for (const user of [null, { id: 'viewer' }]) {
void test(`renders the quote control for ${user === null ? 'guests' : 'signed-in readers'}`, async () => {
test(`renders the quote control for ${user === null ? 'guests' : 'signed-in readers'}`, async () => {
const result = await createInertiaApp<{
auth: { user: { id: string } | null };
}>({
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/CommitStarButton.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="node" />

import assert from 'node:assert/strict';
import { test } from 'node:test';
import { test } from 'vite-plus/test';
import { createInertiaApp } from '@inertiajs/react';
import { renderToString } from 'react-dom/server';
import { CommitStarButton } from '../../resources/js/components/commit-star-button';
Expand Down Expand Up @@ -49,7 +49,7 @@ async function render(
}

for (const status of ['approved', 'pending', 'rejected'] as const) {
void test(`authors see only their ${status} commit's star count`, async () => {
test(`authors see only their ${status} commit's star count`, async () => {
const body = await render({ id: 'author' }, { status });

assert.match(body, /data-test="star-count-readonly"/);
Expand All @@ -58,15 +58,15 @@ for (const status of ['approved', 'pending', 'rejected'] as const) {
});
}

void test('authors see an accessible empty star count', async () => {
test('authors see an accessible empty star count', async () => {
const body = await render({ id: 'author' }, { stars_count: 0 });

assert.match(body, /aria-label="No stars yet"/);
assert.doesNotMatch(body, /<button\b/);
});

for (const user of [null, { id: 'viewer' }]) {
void test(`approved commits keep the star control for ${user === null ? 'guests' : 'other readers'}`, async () => {
test(`approved commits keep the star control for ${user === null ? 'guests' : 'other readers'}`, async () => {
const body = await render(user);

assert.match(body, /data-test="star-commit-button"/);
Expand All @@ -77,7 +77,7 @@ for (const user of [null, { id: 'viewer' }]) {
}

for (const status of ['pending', 'rejected'] as const) {
void test(`other readers cannot star a ${status} commit`, async () => {
test(`other readers cannot star a ${status} commit`, async () => {
const body = await render({ id: 'viewer' }, { status });

assert.doesNotMatch(
Expand All @@ -88,7 +88,7 @@ for (const status of ['pending', 'rejected'] as const) {
}

for (const status of ['approved', 'pending', 'rejected'] as const) {
void test(`authors see their ${status} reply's read-only star count`, async () => {
test(`authors see their ${status} reply's read-only star count`, async () => {
const body = await render(
{ id: 'author' },
{ status, parent_id: 'parent' },
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/CommitStarMutations.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { test } from 'vite-plus/test';
import { createCommitStarMutations } from '../../resources/js/lib/commit-star-mutations.ts';

const stars = { id: 'commit', starred: false, stars_count: 2 };

void test('applies a poll when no star mutation has started', () => {
test('applies a poll when no star mutation has started', () => {
const mutations = createCommitStarMutations();
const received: (typeof stars)[] = [];
const update = mutations.prepare(stars.id, (state) => received.push(state));
Expand All @@ -14,7 +14,7 @@ void test('applies a poll when no star mutation has started', () => {
assert.deepEqual(received, [stars]);
});

void test('a click on either copy rejects every older poll, even after completion', () => {
test('a click on either copy rejects every older poll, even after completion', () => {
const mutations = createCommitStarMutations();
const received: (typeof stars)[] = [];
const update = (state: typeof stars) => received.push(state);
Expand All @@ -31,7 +31,7 @@ void test('a click on either copy rejects every older poll, even after completio
assert.deepEqual(received, []);
});

void test('duplicate controls cannot mutate or poll a commit while its mutation is pending', () => {
test('duplicate controls cannot mutate or poll a commit while its mutation is pending', () => {
const mutations = createCommitStarMutations();
const finish = mutations.begin(stars.id);

Expand All @@ -45,7 +45,7 @@ void test('duplicate controls cannot mutate or poll a commit while its mutation
assert.ok(mutations.begin(stars.id));
});

void test('polling resumes after a mutation finishes or rolls back', () => {
test('polling resumes after a mutation finishes or rolls back', () => {
const mutations = createCommitStarMutations();
const finish = mutations.begin(stars.id);
const received: (typeof stars)[] = [];
Expand All @@ -58,7 +58,7 @@ void test('polling resumes after a mutation finishes or rolls back', () => {
assert.deepEqual(received, [stars]);
});

void test('a mutation leaves polls for other commits and other layouts independent', () => {
test('a mutation leaves polls for other commits and other layouts independent', () => {
const mutations = createCommitStarMutations();
const otherLayout = createCommitStarMutations();
const received: (typeof stars)[] = [];
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/CommitThread.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="node" />

import assert from 'node:assert/strict';
import { test } from 'node:test';
import { test } from 'vite-plus/test';
import { createInertiaApp } from '@inertiajs/react';
import { renderToString } from 'react-dom/server';
import {
Expand All @@ -20,6 +20,7 @@ const reply = (id: string): Commit =>
created_at: new Date().toISOString(),
status: 'approved',
body_segments: [{ type: 'text', text: `Visible reply ${id}` }],
preview_segments: null,
replies_count: 0,
user: { id: 'author', name: 'Author', username: 'author', lane: 1 },
}) as Commit;
Expand Down Expand Up @@ -69,7 +70,7 @@ async function renderThread(count: number) {
}

for (const count of [0, 1, 2, 5]) {
void test(`shows ${Math.min(count, 1)} replies immediately out of ${count}`, async () => {
test(`shows ${Math.min(count, 1)} replies immediately out of ${count}`, async () => {
const html = await renderThread(count);
assert.equal(
(html.match(/Visible reply /g) ?? []).length,
Expand Down
24 changes: 12 additions & 12 deletions tests/Unit/ComposerPreview.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="node" />
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { test } from 'vite-plus/test';
import { App } from '@inertiajs/react';
import type { ComponentProps, KeyboardEvent, ReactElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
Expand Down Expand Up @@ -66,7 +66,7 @@ function previewFor(options: {

for (const modifier of ['ctrlKey', 'metaKey'] as const) {
for (const shiftKey of [false, true]) {
void test(`${modifier} + ${shiftKey ? 'Shift + ' : ''}Enter publishes from preview`, () => {
test(`${modifier} + ${shiftKey ? 'Shift + ' : ''}Enter publishes from preview`, () => {
let submitted = 0;
let prevented = 0;
const preview = previewFor({ isSubmittable: true });
Expand All @@ -87,7 +87,7 @@ for (const modifier of ['ctrlKey', 'metaKey'] as const) {
}
}

void test('does not publish an incomplete draft from preview', () => {
test('does not publish an incomplete draft from preview', () => {
previewFor({ isSubmittable: false }).onPreviewKeyDown({
key: 'Enter',
ctrlKey: true,
Expand Down Expand Up @@ -152,7 +152,7 @@ function renderComposer(body: string): string {
}

for (const count of [1, 2, 3, 3850]) {
void test(`counts ${count} emoji as Unicode characters in the preview composer`, () => {
test(`counts ${count} emoji as Unicode characters in the preview composer`, () => {
const markup = renderComposer('🚀'.repeat(count));
const submit = markup.match(
/<button[^>]*data-test="create-commit-button"[^>]*>/,
Expand All @@ -168,7 +168,7 @@ for (const count of [1, 2, 3, 3850]) {
});
}

void test('previews the chosen link card instead of the first link in the body', () => {
test('previews the chosen link card instead of the first link in the body', () => {
const preview = previewFor({
body: 'https://first.example.com https://second.example.com',
isSubmittable: true,
Expand All @@ -187,7 +187,7 @@ void test('previews the chosen link card instead of the first link in the body',
assert.ok(!card.includes('first.example.com'));
});

void test('omits the preview card when the author chooses no card', () => {
test('omits the preview card when the author chooses no card', () => {
const preview = previewFor({
body: 'https://first.example.com',
isSubmittable: true,
Expand All @@ -200,7 +200,7 @@ void test('omits the preview card when the author chooses no card', () => {
assert.ok(!markup.includes('data-test="link-card-preview"'));
});

void test('retains the link card picker and scheduling beside preview', () => {
test('retains the link card picker and scheduling beside preview', () => {
const markup = renderComposer(
'https://first.example.com https://second.example.com',
);
Expand All @@ -219,7 +219,7 @@ void test('retains the link card picker and scheduling beside preview', () => {

const secret = 'ghp_' + 'Ab3dEf6hIj9kLm2nOp5qRs8tUv1wXy4zABCD';

void test('keeps the sensitive text warning beside preview', () => {
test('keeps the sensitive text warning beside preview', () => {
const markup = renderComposer(secret);

assert.equal(
Expand All @@ -231,13 +231,13 @@ void test('keeps the sensitive text warning beside preview', () => {
assert.ok(!markup.includes('Publish possible secrets?'));
});

void test('ordinary drafts retain preview without a sensitive text warning', () => {
test('ordinary drafts retain preview without a sensitive text warning', () => {
const markup = renderComposer('Shipped a small fix');
assert.ok(markup.includes('data-test="preview-toggle"'));
assert.ok(!markup.includes('aria-label="Sensitive text warning"'));
});

void test('previews attached image descriptions without a published photo link', () => {
test('previews attached image descriptions without a published photo link', () => {
const images = [
new File(['first'], 'first.png', { type: 'image/png' }),
new File(['second'], 'second.png', { type: 'image/png' }),
Expand All @@ -264,7 +264,7 @@ void test('previews attached image descriptions without a published photo link',

for (const pasteisMode of [false, true]) {
for (const isStatic of [false, true]) {
void test(`renders pastel words as ${pasteisMode ? 'emoji' : 'text'} in ${isStatic ? 'excerpts' : 'commit previews'}`, () => {
test(`renders pastel words as ${pasteisMode ? 'emoji' : 'text'} in ${isStatic ? 'excerpts' : 'commit previews'}`, () => {
const body =
'pastel, pasteis! (pastéis) PASTEL PASTEIS PASTÉIS :rocket:';
const preview = previewFor({ body, isSubmittable: true });
Expand Down Expand Up @@ -307,7 +307,7 @@ for (const pasteisMode of [false, true]) {
}
});

void test(`preserves code, URLs, usernames and larger words with mode ${pasteisMode ? 'on' : 'off'} in ${isStatic ? 'excerpts' : 'commits'}`, () => {
test(`preserves code, URLs, usernames and larger words with mode ${pasteisMode ? 'on' : 'off'} in ${isStatic ? 'excerpts' : 'commits'}`, () => {
const preview = previewFor({
body: 'pastel https://pasteis.com/pastel @pastel pastels pastelaria épastel pastelé pastel_1\n`pasteis`\n```text\npastéis\n```',
isSubmittable: true,
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/LinkifiedText.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="node" />
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { test } from 'vite-plus/test';
import { renderToStaticMarkup } from 'react-dom/server';
import {
typedLinks,
Expand All @@ -9,7 +9,7 @@ import {

const url = 'https://www.example.com/a-long-path-to-the-release-notes';

void test('finds the full preview URL outside inline and fenced code', () => {
test('finds the full preview URL outside inline and fenced code', () => {
const body = [
'`https://inline.example.com`',
'```text',
Expand All @@ -22,7 +22,7 @@ void test('finds the full preview URL outside inline and fenced code', () => {
assert.deepEqual(typedLinks('`https://inline.example.com`'), []);
});

void test('shortens the displayed preview link while retaining the full URL', () => {
test('shortens the displayed preview link while retaining the full URL', () => {
const markup = renderToStaticMarkup(<LinkifiedText text={url} />);

assert.ok(markup.includes(`href="${url}"`));
Expand All @@ -37,7 +37,7 @@ void test('shortens the displayed preview link while retaining the full URL', ()
);
});

void test('keeps every distinct card URL in order without joining prose across code', () => {
test('keeps every distinct card URL in order without joining prose across code', () => {
assert.deepEqual(
typedLinks(
'https://first.example.com`code`https://second.example.com https://first.example.com',
Expand All @@ -50,7 +50,7 @@ for (const body of [
'before `https://draft.example.com',
'```text\nhttps://draft.example.com',
]) {
void test(`ignores card URLs in unfinished code: ${body}`, () => {
test(`ignores card URLs in unfinished code: ${body}`, () => {
assert.deepEqual(typedLinks(body), []);
});
}
Loading