mirror of
https://github.com/penpot/penpot.git
synced 2026-11-20 00:50:34 +00:00
The composable interpreter treated a step as done after a 60 ms gap
with no commits, and treated its 2 s timeout as done too. Slow sync or
reflow work could finish after the step, so a case could assert on a
half-synced file.
Each event step now waits, as the plugin waitForLayoutUpdate does,
until every pending work tracked by the reflow registry has drained:
the watcher's sync wait, the sync it starts, and layout and text
reflow. A step that does not drain within 2 s fails the test and names
the work still pending, and the next variant starts with nothing
pending.
The tests cover an edit with a deliberately slow sync, undo and redo
steps that must wait for the watcher's touch-component, translation
and derived commits, a sync that never finishes, and a restart of the
edit watchers, which must keep the undo entries of an edit the same.
Also in this commit:
- Keep page-less changes from adding a nil page. Applying a commit locally
rebuilds the object indices of every page its changes name. Changes that touch
no page, such as :mod-component, name none, and their nil page id was rebuilt
too: the file data in the store gained a page under a nil key holding
{:objects nil}. Every component touch after an edit to a main added it, and
undo never removed it.
- Check undo and redo of every step in the composable cases. The composable
cases tested undo only where a case asked for it, so a change generator with a
wrong inverse, or a step that splits into several undo entries, went
unnoticed.
- Add operations and cases to the composable component suites. The composable
runners could edit, add, remove and move children, swap and switch, but not
run the other component operations.
- Test component validation, repair and library asset sync.
- Add a component sync benchmark with a recorded baseline. The coming refactors
and fixes change sync code, and a slowdown must be seen and explained in the
commit that causes it.
- Tidy the composable suite and make its cases stricter.
- Test the component sync paths no test reached. A coverage run found sync paths
that no test ran.
- Test variant events, token sync and switch overrides. The variant events had
almost no frontend tests, and several switch, paste, token and restore paths
never ran.
- Test the file and container helpers and the library events. The component
helpers of types/file and types/container and the library events of the
workspace had the lowest coverage left.
58 lines
2.1 KiB
TypeScript
58 lines
2.1 KiB
TypeScript
/**
|
|
* Signals a failed test assertion. Thrown by assertion helpers and caught by the
|
|
* test runner, which turns it into a failed result.
|
|
*/
|
|
export class AssertionError extends Error {
|
|
constructor(message: string) {
|
|
super(message);
|
|
this.name = "AssertionError";
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Provides assertion helpers for use inside a test's assertion phase. Each helper
|
|
* throws an `AssertionError` on failure; the runner catches it.
|
|
*/
|
|
export class Assert {
|
|
/** Asserts that `condition` holds, failing with `message` otherwise. */
|
|
static that(condition: boolean, message: string): void {
|
|
if (!condition) {
|
|
throw new AssertionError(message);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Asserts that `actual` equals `expected` using `equals`, failing with a
|
|
* message that includes both values (rendered via `render`).
|
|
*/
|
|
static equal<T>(actual: T, expected: T, equals: (a: T, b: T) => boolean, render: (v: T) => string = String): void {
|
|
if (!equals(actual, expected)) {
|
|
throw new AssertionError(`expected ${render(expected)} but was ${render(actual)}`);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Asserts a strict expected failure for `bug` (its row in the component
|
|
* stabilization plan's suspected bugs): `expected` is the value that should
|
|
* hold, but while the bug is open `actual` must be exactly `pinned`, the
|
|
* wrong value the bug gives. Any other value fails, `expected` included, so
|
|
* the pin goes only with the fix.
|
|
*/
|
|
static knownFailure<T>(
|
|
bug: string,
|
|
expected: T,
|
|
pinned: T,
|
|
actual: T,
|
|
equals: (a: T, b: T) => boolean,
|
|
render: (v: T) => string = String
|
|
): void {
|
|
if (!equals(actual, pinned)) {
|
|
const fixed = equals(actual, expected) ? ". The expected value now holds: drop the pin in the fix" : "";
|
|
throw new AssertionError(
|
|
`known failure ${bug}: expected ${render(expected)}, pinned to the bug's ` +
|
|
`${render(pinned)}, but was ${render(actual)}${fixed}`
|
|
);
|
|
}
|
|
}
|
|
}
|