Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Those comparisons, and the kit's own build, which carries the documentation onto

`npm test` runs every test past the others' failures: the nativeElement assertions check, the browser APIs check, the OnPush strategies check, the poll and test limits check, the part glyphs check, on Linux x64 only the Kit bundles, the Kit copies, the Kit manifest and Angular's newest, the kit's Node.js tests, `src/noldova.ui.components.angular/tests/node/*.test.ts`, with `node --test`, of the symbols entry, the stylesheets that load the symbol font and the browser APIs check, which no browser loads, and the kit's Angular specs, which must each report a result, with no test identity, the spec file and the titles of its suites and test, repeated, then, on Linux only, builds the docs site and tests it, as `npm run docs:build` and `npm run docs:test` do, as the static site it serves is the same on every platform.
With `NOLDOVA_SEPARATE_TEST=docs`, as the CI targets' tests set it, `npm test` leaves the docs site out, and the CI run's "Separate test" job checks it once, with `npm run build` and `npm run test:docs`.
The kit's Angular specs run in two runs of Angular's test builder, each in a browser of its own: first every test but those in a `describe(LayoutTraceFixture.suite, ...)`, then, from the spec files that hold one, only those. A layout trace records every tab of its browser, so in the first browser, under the whole suite, one could take over 10 seconds to end and keep another spec's trace from starting ([#198](https://github.com/noldova-com/ui-components/issues/198)); in the second only the tracing tests run. Both runs use the Angular `part` configuration, and the script adds up their coverage as `npm run test:merge` does below, gating it on a whole run. The suite's title is in `src/noldova.ui.components.angular/tests/fixtures/layout-trace-suite.ts`, which the fixture and the script both read. After both runs, the script fails unless each test in either run's report passed or failed in exactly one of them, and the second run ran at least one test, so a traced test that both filters skip, or that both run, fails the run.
The kit's Angular specs run in two runs of Angular's test builder, each in a browser of its own: first every test but those in a `describe(LayoutTraceFixture.suite, ...)`, then, from the spec files that hold one, only those. A layout trace records every tab of its browser, so in the first browser, under the whole suite, one could take over 10 seconds to end and keep another spec's trace from starting ([#198](https://github.com/noldova-com/ui-components/issues/198)); in the second only the tracing tests run. The spec files that run alone, as [Tests that run alone](#tests-that-run-alone) lists, take a third run of their own, with the builder's `isolate` option on, and the first two leave them out. Every run uses the Angular `part` configuration, and the script adds up their coverage as `npm run test:merge` does below, gating it on a whole run. The suite's title is in `src/noldova.ui.components.angular/tests/fixtures/layout-trace-suite.ts`, which the fixture and the script both read. After the runs, the script fails unless each test in any run's report passed or failed in exactly one of them, and each run after the first ran at least one test, so a traced test that both filters skip, or that both run, fails the run.
`npm test -- --shard=<part>/<parts>`, with 2 to 8 parts, runs only every `<parts>`-th spec file of the kit's sorted list, from the `<part>`-th, with the Angular `part` configuration, which keeps the coverage report in `_build/angular-coverage` without gating it, and runs the checks and the Node.js tests before the specs only in part 1.
`npm run test:merge -- <folder> <parts>`, with Node.js alone, first checks itself on small reports in a temporary folder, then adds up the coverage of the parts, each in a subfolder of `<folder>`, by where each function, statement and branch sits in its file, from only the parts that loaded the file, since a part that never loaded it maps it from its source and can map it otherwise, and fails as `npm test` does below the requirement in [Coverage](#coverage), naming what no part reached; it also fails when fewer subfolders than `<parts>` came, or when one holds no report or one that isn't JSON.
`npm test -- <filter>...` runs only the spec files and Node.js tests whose path from the repository root holds a filter, without the coverage gates, the nativeElement assertions check, the browser APIs check, the OnPush strategies check, the poll and test limits check, the part glyphs check, the Kit bundles, the Kit copies, the Kit manifest, Angular's newest and the docs site, and fails when nothing matches.
Expand Down Expand Up @@ -232,8 +232,8 @@ Every spec here, the kit's and the docs site's, is a component spec, since each
`npm run test:timing` is the timing check, apart from `npm test` since its pass condition is a time.
It runs the kit's specs three times without coverage, and on Linux the docs site's too, as their tests run only there.
In the kit's folder, `npm run test:timing -- <file name> ...`, such as `npm run test:timing -- code-block-run.component.spec.ts`, times only the kit's spec files so named, in the same parts, and fails naming any name no spec file has or two spec files share, which a path from the kit's folder, such as `tests/styles/theme.spec.ts`, tells apart; from the repository's root the docs site's check refuses names and fails, since it times its whole suite; the test machines take only such runs of the specs a change touches, never the whole suite.
Each of the kit's runs is two runs of Angular's test builder, as `npm test`'s are, so the tests in a `describe(LayoutTraceFixture.suite, ...)` trace in a browser of their own; in one browser under the whole suite, a trace could hold it past the next trace's wait ([#198](https://github.com/noldova-com/ui-components/issues/198)).
A run fails, and the check times nothing, unless each test in the two reports passed or failed in exactly one of them and the second ran at least one test.
Each of the kit's runs is two runs of Angular's test builder, and a third for the spec files that run alone, as `npm test`'s are, so the tests in a `describe(LayoutTraceFixture.suite, ...)` trace in a browser of their own; in one browser under the whole suite, a trace could hold it past the next trace's wait ([#198](https://github.com/noldova-com/ui-components/issues/198)).
A run fails, and the check times nothing, unless each test in the reports passed or failed in exactly one of them and each report after the first ran at least one test.
It takes each test's median over the runs, with `TestTimingCheck.median` from `@noldova/context.testing`, so one slow run decides nothing, and fails a spec file whose tests' median is over 100 ms plus a margin of 20%.
It also prints each test whose median is over 1 second, which the list below holds.
Its code is `src/noldova.ui.components.angular/scripts/angular/angular-test-timing.ts`, run by `scripts/angular/angular-timing-script.ts`, which each package's `scripts/test-timing.ts` or `scripts/test-docs-timing.ts` starts.
Expand Down Expand Up @@ -536,10 +536,29 @@ Before each spec file, it also sets the emulated media to no reduced motion and
`src/noldova.ui.components.angular/tests/typescript-grammar.setup.ts` keeps one property of its own on the page's `window`, `nolTypeScriptWarming`, the page's one TypeScript warming, which Time per file explains: a setup file and the modules it imports load again for each spec file, while the files on one page share its window.
Specs emulate media only through `src/noldova.ui.components.angular/tests/fixtures/emulated-media.fixture.ts`, which the motion and forced-colors fixtures use: each emulation call replaces the whole emulated set, so the fixture sends every feature each time.
A spy's own `mockRestore()` leaves its restore in Vitest's registry, where a later spec file's `vi.restoreAllMocks()` runs it again, so a test that spies on a faked timer global restores it with `vi.restoreAllMocks()`.
One spec fakes a timer global in the shared page, by the maintainer's decision: `src/noldova.ui.components.angular/tests/testing/services/kit-stylesheet-fixture.spec.ts` fakes `setTimeout` to reach `KitStylesheetFixture`'s 30 s load deadline and the 5 s limit on its diagnostic fetch of a font that failed.
No event can stand in for a load or an answer that never comes, and the fixture is a public helper with no injected time source; the spec restores the timers in its `afterEach`.
A spec that needs its own resize observers, to hold, count or call their callbacks, provides them through `ResizeTokens.observers` in `src/noldova.ui.components.angular/src/app/models/resize-tokens.ts`, whose default starts the browser's own, with one of the fake sources in `src/noldova.ui.components.angular/tests/fixtures`, such as `CountingResizeObserversFixture`; no spec replaces the global `ResizeObserver`, since the specs that run after it on the page would see the replacement.
No test needs a resource that the operating system can't isolate per process, so none runs alone.
By the maintainer's decision, `src/noldova.ui.components.angular/tests/testing/services/kit-stylesheet-fixture.spec.ts` fakes `setTimeout` to reach `KitStylesheetFixture`'s 30 s load deadline and the 5 s limit on its diagnostic fetch of a font that failed.
No event can stand in for a load or an answer that never comes, and the fixture is a public helper with no injected time source; the spec restores the timers in its `afterEach`, and it runs alone, as the table below says.
A spec that needs its own resize observers, to hold, count or call their callbacks, provides them through `ResizeTokens.observers` in `src/noldova.ui.components.angular/src/app/models/resize-tokens.ts`, whose default starts the browser's own, with one of the fake sources in `src/noldova.ui.components.angular/tests/fixtures`, such as `CountingResizeObserversFixture`.
A spec that reads media queries provides them through `MediaTokens.queries` in `src/noldova.ui.components.angular/src/app/models/media-tokens.ts`, whose default reads the browser's own.
A spec that waits on frames provides a time source through `ClockTokens.timeSource`, a spec of `SystemTimeSource` gives it idle callbacks of its own, and a spec under Vitest's fake timers counts the frames still waiting with `vi.getTimerCount()`.
Comment thread
rostislavrotaru marked this conversation as resolved.
Resolved

No spec replaces a global in the shared page, a property of its window such as `ResizeObserver`, `matchMedia` or `console`, since the specs that run after it on the page would see the replacement.
Comment thread
rostislavrotaru marked this conversation as resolved.
Resolved
A spec file that has to, to check how the kit behaves where a browser feature is missing or broken, or to read what reaches only the console, is listed in `src/noldova.ui.components.angular/tests/fixtures/isolated-specs.ts` and runs alone.
`npm test` leaves the listed files out of the shared page's run and runs them in a run of their own, with the Angular test builder's `isolate` option on, which loads each file in a page of its own, with its own window; it merges that run's coverage with the others' before the coverage gate, and fails when the list names a file that doesn't exist.

| File, in `src/noldova.ui.components.angular/tests` | Why it runs alone |
|---|---|
| `app/components/code-block/code-block-server.component.spec.ts`, `app/components/site-card/site-card.component.spec.ts`, `app/components/site-hero/site-hero.component.spec.ts`, `app/components/site-theme-switch/site-theme-switch.component.spec.ts` | Each sets Angular's own `ngServerMode` global, which decides whether render hooks run, to render as a server does. |
| `app/components/code-block/code-block-spans.component.spec.ts`, `app/components/diff-view/diff-view.component.spec.ts`, `app/services/code-highlights.spec.ts`, `app/services/diff-highlights.spec.ts`, `fixtures/code-highlights.fixture.spec.ts` | Each removes the CSS Custom Highlight API, `Highlight` and `CSS.highlights`, through `CodeHighlightsFixture.withoutHighlightApiAsync`, to check a browser without it; `code-highlights.spec.ts` also replaces `matchMedia` to follow a forced-colors query. |
| `app/models/link-reference-color.spec.ts` | Removes `CSS`, as when the package loads in Node.js. |
| `app/models/markdown-link.spec.ts` | Replaces `URL` with one that parses a drive path as Windows does, and `decodeURIComponent` with one that throws an error other than a broken encoding. |
| `app/models/mention-value.spec.ts` | Replaces `decodeURIComponent` with one that throws an error other than a broken encoding. |
| `app/services/overlay-bounds.service.spec.ts` | Spies on the window's `addEventListener` to check that the service listens for nothing outside a browser, where it measures nothing, so no listener's effect shows. |
| `testing/services/kit-stylesheet-fixture.spec.ts` | Replaces `fetch` to answer the fixture's diagnostic fetch of a font; `KitStylesheetFixture` is a public helper with no injected fetch. |
| `app/components/mention-field/mention-field-chips.spec.ts` | Spies on `console.warn` for the field's warning, in development, that its parent isn't positioned. |
| `app/components/message/message.component.spec.ts` | Spies on `console.warn` for Angular's warning of an output emitted after its component is destroyed. |
| `app/services/code-highlighter-lifetime.spec.ts` | Spies on `console.warn` for Shiki's warning that too many highlighters were made. |
| `fixtures/timer-globals.fixture.spec.ts` | Spies on the faked `setInterval` to check the shared page's own check of timer globals. |

### Newest context

Expand Down
Loading
Loading