ci(test): type-check Jest spec programs and gate it in CI (#1705)

* build(test): make spec tsconfigs resolve what Jest resolves

Lib spec tsconfigs used module: commonjs with node10 resolution, which cannot
see Angular's exports-only secondary entry points, and dropped global.d.ts, so
tsc reported thousands of resolution errors and no window.electron typing.
Switch them to module: preserve with bundler resolution (ts-jest still forces
CommonJS emit outside ESM mode), add global.d.ts to every spec program, type
jest.unstable_mockModule for the ESM workspace, include the ui-epg and
ui-playback specs that jest.web-esm.workspace.ts runs under the web spec
config, and drop the snack-bar stub that shadowed the real Material types.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* ci(test): gate spec type-checking with typecheck:spec

Add tools/typecheck/spec-typecheck.mjs, which runs tsc --noEmit over every
tsconfig.spec.json with a small pool and fails on any diagnostic, wire it into
the unit-and-typecheck job after typecheck:ci, and document the gate and the
spec tsconfig conventions in the validation map. Also bring the non-Tier-A
spec configs (remote-control-web, ui-remote-control, stalker-mock-server) to
the same conventions so the gate covers the whole workspace.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* test: fix the spec type errors surfaced by typecheck:spec

With the spec programs resolving modules and ambient typings correctly,
tsc reported 432 genuine errors across the Tier A projects: read-only
capability flags assigned on Partial<> doubles, signal-store values used as
types, fixtures missing required fields, index-signature property access,
partial bridge doubles cast through incompatible shapes, and deferred
resolvers narrowed to never. Type the doubles instead of casting to any:
writable mapped types for capability flags, InstanceType<typeof StalkerStore>,
typed jest.fn signatures, protectedState: false on test signal stores, and
completed fixtures. Production changes are limited to bracket access for
index-signature properties under the libs' noPropertyAccessFromIndexSignature
setting and two narrowing guards in the global favorites loader.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* test(playback): use the ESM setup's jest global in the controls fixtures

The fixture imported jest from @jest/globals, which is not a direct
dependency. Jest provides that module at runtime, so tests passed, but on a
clean pnpm install tsc cannot resolve it and typecheck:spec failed in CI.
The ESM test setup already installs import.meta.jest as the global, typed
by @types/jest, as the other ESM specs use it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: type the parental lock doubles merged since the gate was written

The parental lock feature (#1601) and the Stalker actor route landed on master
with spec doubles declared as zero-argument jest.fn()s that the tests then
drive with the real arguments, plus a copy of the ResizableDirective override
imported from a library that does not export it. Give the doubles the lock
service's real signatures, drop the dead override as in the sibling layout
specs, use bracket access for the actor route's personId param, and keep the
Stalker layout spec within the 1200-line limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: 4gray <fourgray@proton.me>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-09-27 20:54:27 +02:00
1 parent 69056487bc
commit 650da4a1d3
158 files changed
+1517 -632

No files matched your search

@@ -254,8 +254,9 @@ export class GlobalFavoritesService {
} catch {
continue;
}
if (!playlist) continue;
const favorites = Array.isArray(playlist?.favorites)
const favorites = Array.isArray(playlist.favorites)
? playlist.favorites.filter(isStalkerFavoriteItem)
: [];
@@ -271,6 +272,7 @@ export class GlobalFavoritesService {
if (!isLive) continue;
const streamId = fav.stream_id ?? fav.id;
if (streamId === undefined) continue;
results.push({
uid: buildFavoriteUid('stalker', meta._id, streamId),
name:
@@ -12,8 +12,16 @@ describe('WorkspaceCategoryLockActionService', () => {
requestUnlock: jest.fn(async () => true),
lockedXtreamIds: jest.fn(() => [7]),
lockedStalkerIds: jest.fn(() => ['9']),
setXtreamLocks: jest.fn(async () => true),
setStalkerLocks: jest.fn(async () => true),
setXtreamLocks: jest.fn(
async (
..._args: Parameters<ParentalLockService['setXtreamLocks']>
) => true
),
setStalkerLocks: jest.fn(
async (
..._args: Parameters<ParentalLockService['setStalkerLocks']>
) => true
),
};
let service: WorkspaceCategoryLockActionService;
@@ -57,7 +57,9 @@ function getCategoryLabels(
fixture: ComponentFixture<WorkspaceContextPanelComponent>
): string[] {
return Array.from(
fixture.nativeElement.querySelectorAll('.category-item .nav-item-label')
(fixture.nativeElement as HTMLElement).querySelectorAll(
'.category-item .nav-item-label'
)
).map((element: Element) => element.textContent?.trim() ?? '');
}
@@ -266,7 +268,9 @@ describe('WorkspaceContextPanelComponent', () => {
fixture.detectChanges();
const countTexts = Array.from(
fixture.nativeElement.querySelectorAll('.item-count')
(fixture.nativeElement as HTMLElement).querySelectorAll(
'.item-count'
)
).map((element: Element) => element.textContent?.trim());
const categoryButtons = Array.from(
fixture.nativeElement.querySelectorAll('.category-item')
@@ -1,16 +1,30 @@
import { TestBed } from '@angular/core/testing';
import { MatDialog } from '@angular/material/dialog';
import { Subject } from 'rxjs';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { Observable, Subject } from 'rxjs';
import { RuntimeCapabilitiesService } from '@iptvnator/services';
import { WorkspaceKeyboardShortcutsDialogData } from './workspace-keyboard-shortcuts-dialog.component';
import { WorkspaceKeyboardShortcutsService } from './workspace-keyboard-shortcuts.service';
import { WorkspaceShellContextDrawerService } from '@iptvnator/workspace/shell/util';
describe('WorkspaceKeyboardShortcutsService', () => {
let afterClosed$: Subject<void>;
let dialog: { open: jest.Mock };
let dialog: {
open: jest.Mock<
{ afterClosed: () => Observable<void> },
[unknown, MatDialogConfig<WorkspaceKeyboardShortcutsDialogData>]
>;
};
let runtime: { isElectron: boolean };
let service: WorkspaceKeyboardShortcutsService;
function openedDialogData(): WorkspaceKeyboardShortcutsDialogData {
const data = dialog.open.mock.calls[0][1].data;
if (!data) {
throw new Error('Expected the shortcuts dialog to receive data');
}
return data;
}
beforeEach(() => {
afterClosed$ = new Subject<void>();
dialog = {
@@ -309,7 +323,7 @@ describe('WorkspaceKeyboardShortcutsService', () => {
service.openShortcutsDialog();
const dialogData = dialog.open.mock.calls[0][1].data;
const dialogData = openedDialogData();
const commandPaletteShortcut = dialogData.groups
.flatMap((group) => group.items)
.find((item) => item.id === 'open-command-palette');
@@ -323,7 +337,7 @@ describe('WorkspaceKeyboardShortcutsService', () => {
it('includes Electron-only shortcuts when runtime supports Electron', () => {
service.openShortcutsDialog();
const dialogData = dialog.open.mock.calls[0][1].data;
const dialogData = openedDialogData();
const itemIds = dialogData.groups.flatMap((group) =>
group.items.map((item) => item.id)
);
@@ -336,7 +350,7 @@ describe('WorkspaceKeyboardShortcutsService', () => {
service.openShortcutsDialog();
const dialogData = dialog.open.mock.calls[0][1].data;
const dialogData = openedDialogData();
const itemIds = dialogData.groups.flatMap((group) =>
group.items.map((item) => item.id)
);
@@ -2,7 +2,7 @@ import { signal } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { MatSnackBar } from '@angular/material/snack-bar';
import { TranslateService } from '@ngx-translate/core';
import { of } from 'rxjs';
import { Observable, of } from 'rxjs';
import {
WorkspaceCommandContribution,
WorkspaceViewCommandService,
@@ -58,7 +58,7 @@ describe('WorkspacePlayerCommandsContributor', () => {
>;
}
| undefined;
let translate: { instant: jest.Mock; onLangChange: ReturnType<typeof of> };
let translate: { instant: jest.Mock; onLangChange: Observable<null> };
function bootstrap(options: {
supportsManagedExternalPlayers: boolean;
@@ -279,7 +279,9 @@ describe('WorkspaceShellContextSidebarComponent', () => {
fixture.detectChanges();
liveSidebarService.expand('portal');
fixture.detectChanges();
await new Promise((resolve) => queueMicrotask(resolve));
await new Promise<void>((resolve) =>
queueMicrotask(() => resolve())
);
// The panel offered no control (categories not loaded), so the
// rail itself takes focus.
@@ -296,7 +298,9 @@ describe('WorkspaceShellContextSidebarComponent', () => {
fixture.detectChanges();
liveSidebarService.expand('portal');
fixture.detectChanges();
await new Promise((resolve) => queueMicrotask(resolve));
await new Promise<void>((resolve) =>
queueMicrotask(() => resolve())
);
expect(document.activeElement).toBe(control);
});
@@ -253,7 +253,9 @@ describe('WorkspaceShellHeaderComponent', () => {
fixture.detectChanges();
const chips = Array.from(
fixture.nativeElement.querySelectorAll('.search-chip')
(fixture.nativeElement as HTMLElement).querySelectorAll(
'.search-chip'
)
).map((element: Element) => element.textContent?.trim());
expect(chips).toEqual(['Movies / All Items', 'Loaded channels only']);
@@ -4,7 +4,7 @@ import { MatDialog } from '@angular/material/dialog';
import { NavigationEnd, Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import { of } from 'rxjs';
import { Observable, of } from 'rxjs';
import {
PlaylistRefreshActionService,
type XtreamRefreshPreparationState,
@@ -105,6 +105,13 @@ describe('WorkspaceShellFacade', () => {
serverUrl?: string;
macAddress?: string;
};
const createPlaylistMeta = (_id: string, title: string): PlaylistMeta => ({
_id,
title,
count: 0,
importDate: '2026-01-01T00:00:00.000Z',
autoRefresh: false,
});
let facade: WorkspaceShellFacade;
let searchSync: WorkspaceShellSearchSyncService;
@@ -123,7 +130,7 @@ describe('WorkspaceShellFacade', () => {
let navigationTrigger: 'imperative' | 'popstate';
let router: {
url: string;
events: ReturnType<typeof of>;
events: Observable<NavigationEnd>;
navigate: jest.Mock;
navigateByUrl: jest.Mock;
parseUrl: jest.Mock;
@@ -173,15 +180,29 @@ describe('WorkspaceShellFacade', () => {
supportsDownloads: true,
};
activePlaylistSignal = signal({
_id: 'pl-1',
activePlaylistSignal = signal<PlaylistSignalMeta | null>({
...createPlaylistMeta('pl-1', 'Playlist A'),
serverUrl: 'http://example.com',
title: 'Playlist A',
recentlyViewed: ['recent-1'],
recentlyViewed: [
{
source: 'm3u',
id: 'recent-1',
url: 'https://example.com/recent-1.m3u8',
title: 'Recent 1',
category_id: 'live',
added_at: '2026-01-01T00:00:00.000Z',
},
],
});
playlistsSignal = signal([
{ _id: 'pl-1', serverUrl: 'http://example.com' },
{ _id: 'pl-2', macAddress: '00:11:22:33' },
playlistsSignal = signal<PlaylistSignalMeta[]>([
{
...createPlaylistMeta('pl-1', 'Playlist A'),
serverUrl: 'http://example.com',
},
{
...createPlaylistMeta('pl-2', 'Playlist B'),
macAddress: '00:11:22:33',
},
]);
downloadsActiveCountSignal = signal(0);
refreshPreparationSignal = signal<XtreamRefreshPreparationState | null>(
@@ -345,7 +366,7 @@ describe('WorkspaceShellFacade', () => {
'WORKSPACE.SHELL.XTREAM_IMPORT_PROGRESS' &&
params
) {
return `${params.type} imported: ${params.current} / ${params.total}`;
return `${params['type']} imported: ${params['current']} / ${params['total']}`;
}
if (
@@ -353,7 +374,7 @@ describe('WorkspaceShellFacade', () => {
'WORKSPACE.SHELL.XTREAM_REFRESH_PROGRESS' &&
params
) {
return `Local records processed: ${params.current} / ${params.total}`;
return `Local records processed: ${params['current']} / ${params['total']}`;
}
return key;
@@ -3,12 +3,12 @@
"compilerOptions": {
"emitDecoratorMetadata": false,
"outDir": "../../../../dist/out-tsc",
"module": "commonjs",
"module": "preserve",
"target": "es2016",
"types": ["jest", "node"],
"moduleResolution": "node10"
"moduleResolution": "bundler"
},
"files": ["src/test-setup.ts"],
"files": ["src/test-setup.ts", "../../../../global.d.ts"],
"include": [
"jest.config.ts",
"src/**/*.test.ts",