mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 09:54:14 +00:00
fix(ci): repair mobile tests and lint diagnostics
Restore the saved-list filter import and test the actual sheet backdrop. Remove unsafe fixture assertions and apply formatting reported by CI. Reuse the current lint results and compare base files in sequence so warning diagnostics can finish without exhausting the heap.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
"@typescript-eslint/no-explicit-any": 113,
|
||||
"trek/no-swallowed-catch": 124,
|
||||
"max-params": 31,
|
||||
"trek/store-without-selector": 65,
|
||||
"trek/store-without-selector": 64,
|
||||
"react-hooks/refs": 380,
|
||||
"react-hooks/set-state-in-effect": 188,
|
||||
"@typescript-eslint/no-floating-promises": 156,
|
||||
|
||||
@@ -172,48 +172,49 @@ function ofRule(results, rule, area) {
|
||||
* this names the file that tipped it. Null when `ref` is not at hand (a clone
|
||||
* without it), and the report then keeps to the files holding the most.
|
||||
*/
|
||||
export async function newWarningsOf({ root, rule, area, keys, lintText, ref = baseRef(), git = gitIn }) {
|
||||
export async function newWarningsOf({ root, rule, area, keys, lintText, current = null, ref = baseRef(), git = gitIn }) {
|
||||
const changed = git(root, ['diff', '--name-only', '--relative', ref, '--', '.']);
|
||||
if (changed === null) return null;
|
||||
const differs = new Set(changed.split('\n').filter(Boolean));
|
||||
const found = await Promise.all(
|
||||
keys
|
||||
.filter((key) => differs.has(key))
|
||||
.map(async (key) => {
|
||||
const path = join(root, key);
|
||||
// A typed rule can trip over a text that is not the file on disk (the
|
||||
// base version); then the file's own warnings are told, marked so.
|
||||
const lint = async (text) => {
|
||||
try {
|
||||
return { messages: ofRule(await lintText(text, path), rule, area) };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
const now = await lint(readText(path));
|
||||
if (!now) return [];
|
||||
const before = git(root, ['show', `${ref}:./${key}`]);
|
||||
const was = before === null ? { messages: [] } : await lint(before);
|
||||
if (was && now.messages.length <= was.messages.length) return [];
|
||||
const note = was ? '' : ' (the base version could not be linted)';
|
||||
return now.messages.map((m) => `${key}:${m.line ?? 0} ${m.message}${note}`);
|
||||
})
|
||||
);
|
||||
return found.flat();
|
||||
const found = [];
|
||||
// Run typed linting for base versions in sequence. Linting many alternate
|
||||
// versions in parallel can exhaust the CI runner's heap.
|
||||
for (const key of keys.filter((key) => differs.has(key))) {
|
||||
const path = join(root, key);
|
||||
const lint = async (text) => {
|
||||
try {
|
||||
return ofRule(await lintText(text, path), rule, area);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
const now = current ? ofRule([current.get(key)], rule, area) : await lint(readText(path));
|
||||
if (!now?.length) continue;
|
||||
const before = git(root, ['show', `${ref}:./${key}`]);
|
||||
const was = before === null ? [] : await lint(before);
|
||||
if (was && now.length <= was.length) continue;
|
||||
const note = was ? '' : ' (the base version could not be linted)';
|
||||
for (const message of now) found.push(`${key}:${message.line ?? 0} ${message.message}${note}`);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/** Prints, under the grown counts, the files and lines behind each one (see newWarningsOf). */
|
||||
async function reportNew(grown, { root, files, lintText, error }) {
|
||||
async function reportNew(grown, { root, files, lintText, error, results }) {
|
||||
if (!grown.length || !lintText) return;
|
||||
const found = await Promise.all(
|
||||
grown.map(({ area, rule }) => newWarningsOf({ root, rule, area, keys: Object.keys(files[area][rule]), lintText }))
|
||||
);
|
||||
grown.forEach(({ area, rule }, i) => {
|
||||
const lines = found[i];
|
||||
if (!lines?.length) return;
|
||||
const current = new Map(results.map((result) => [toKey(root, result.filePath), result]));
|
||||
const previous = new Map();
|
||||
const lintOnce = (text, path) => {
|
||||
if (!previous.has(path)) previous.set(path, lintText(text, path));
|
||||
return previous.get(path);
|
||||
};
|
||||
for (const { area, rule } of grown) {
|
||||
const keys = Object.keys(files[area][rule]);
|
||||
const lines = await newWarningsOf({ root, rule, area, keys, lintText: lintOnce, current });
|
||||
if (!lines?.length) continue;
|
||||
error(`New ${rule} warning(s) in ${area}, against ${baseRef()}:`);
|
||||
for (const line of lines) error(` ${line}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** Lints one file's text with the client's own config, for newWarningsOf. */
|
||||
@@ -238,7 +239,8 @@ export async function check({
|
||||
error = console.error,
|
||||
}) {
|
||||
let baseline = readBaseline(baselinePath, areaCounts);
|
||||
const { counts, files, errors } = tally(await lint(root), root);
|
||||
const results = await lint(root);
|
||||
const { counts, files, errors } = tally(results, root);
|
||||
|
||||
if (update) {
|
||||
baseline = Object.fromEntries(AREAS.map((area) => [area, lowerCounts(baseline[area], counts[area])]));
|
||||
@@ -268,7 +270,7 @@ export async function check({
|
||||
});
|
||||
stale += fallen.length;
|
||||
}
|
||||
await reportNew(grown, { root, files, lintText: lintText && lintText(root), error });
|
||||
await reportNew(grown, { root, files, lintText: lintText && lintText(root), error, results });
|
||||
if (grown.length) {
|
||||
error(
|
||||
'Fix the new warning rather than silencing it: an eslint-disable comment is counted under "suppressed". ' +
|
||||
|
||||
@@ -178,7 +178,8 @@ describe('IcsSubscribeModal on the phone', () => {
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Close' }));
|
||||
expect(onClose).toHaveBeenCalledTimes(1);
|
||||
|
||||
const backdrop = document.querySelector('[data-m-scrim]')!.parentElement!;
|
||||
const backdrop = screen.getByRole('dialog', { name: defaultProps.title }).closest('[role="presentation"]');
|
||||
if (!backdrop) throw new Error('Expected the sheet backdrop');
|
||||
fireEvent.click(backdrop);
|
||||
expect(onClose).toHaveBeenCalledTimes(2);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { useCollections } from '../../../pages/collections/useCollections';
|
||||
import MListRow from '../../components/MListRow';
|
||||
import { CollFilterSection, CollFiltersSheet, DropRow } from './MCollFilterKit';
|
||||
import { categoryMeta, STATUS_SPEC } from './collectionsMobileModel';
|
||||
import { savedListFilterCount } from './savedListFilterCount';
|
||||
|
||||
type Collections = ReturnType<typeof useCollections>;
|
||||
type Group = 'status' | 'category' | 'tags' | 'rating' | 'sort';
|
||||
|
||||
@@ -19,14 +19,15 @@ import { useSettingsStore } from '../../../store/settingsStore';
|
||||
import MSheet from '../../components/MSheet';
|
||||
import MSkeleton from '../../components/MSkeleton';
|
||||
import MConfirmSheet from '../settings/MConfirmSheet';
|
||||
import { formOptionClass } from '../trip/sheets/formOptionClass';
|
||||
import {
|
||||
FIELD_CLS,
|
||||
FORM_LABEL_CLS,
|
||||
FormSheetBody,
|
||||
FormSheetFooter,
|
||||
FormSheetHeader,
|
||||
FormSheetSection } from '../trip/sheets/PlSheetChrome';
|
||||
import { formOptionClass } from '../trip/sheets/formOptionClass';
|
||||
FormSheetSection,
|
||||
} from '../trip/sheets/PlSheetChrome';
|
||||
|
||||
/** A kept tour's measures as the small pills of the phone's rows. */
|
||||
function MeasurePills({ tour }: { tour: CollectionTourItem }) {
|
||||
|
||||
@@ -9,7 +9,8 @@ import {
|
||||
FormSheetBody,
|
||||
FormSheetFooter,
|
||||
FormSheetHeader,
|
||||
FormSheetSection } from '../trip/sheets/PlSheetChrome';
|
||||
FormSheetSection,
|
||||
} from '../trip/sheets/PlSheetChrome';
|
||||
import { formOptionClass } from '../trip/sheets/formOptionClass';
|
||||
|
||||
export default function MJourneyInviteFrame({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export function formOptionClass(active: boolean) {
|
||||
return `flex min-h-10 items-center gap-1.5 rounded-full border px-3 py-1.5 text-start text-caption font-semibold ${
|
||||
active ? 'border-transparent bg-m-act text-m-actfg' : 'border-m-rowbr bg-m-sheetop text-m-ink'
|
||||
}`
|
||||
}`;
|
||||
}
|
||||
|
||||
@@ -958,7 +958,9 @@ describe('MCostsTab', () => {
|
||||
expect(screen.getByText('costs.byCategory')).not.toBeVisible()
|
||||
fireEvent.click(budgetSummary())
|
||||
expect(screen.getByText('costs.byCategory')).toBeVisible()
|
||||
expect(within(budgetSummary().parentElement!).getAllByText('$185.00')).toHaveLength(1)
|
||||
const summary = budgetSummary().parentElement
|
||||
if (!summary) throw new Error('Expected the budget summary')
|
||||
expect(within(summary).getAllByText('$185.00')).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('FE-MOB-COSTT-055: in Arabic a signed balance and an amount read as one left-to-right run, and a payment names who paid whom in reading order', async () => {
|
||||
|
||||
@@ -360,7 +360,9 @@ describe('MPackingListTab', () => {
|
||||
|
||||
const input = screen.getByPlaceholderText('packing.newCategoryPlaceholder')
|
||||
fireEvent.change(input, { target: { value: 'Documents' } })
|
||||
await act(async () => { fireEvent.submit((input as HTMLInputElement).form!) })
|
||||
const form = input.closest('form')
|
||||
if (!form) throw new Error('Expected the new list form')
|
||||
await act(async () => { fireEvent.submit(form) })
|
||||
|
||||
expect(planner.tripActions.addPackingItem).toHaveBeenCalledWith(3, { name: '...', category: `Documents${ZERO_WIDTH}`, visibility: 'common' })
|
||||
})
|
||||
@@ -383,7 +385,9 @@ describe('MPackingListTab', () => {
|
||||
fireEvent.click(screen.getByRole('button', { name: 'packing.addCategory' }))
|
||||
const field = screen.getByPlaceholderText('packing.newCategoryPlaceholder')
|
||||
fireEvent.change(field, { target: { value: 'Gear' } })
|
||||
await act(async () => { fireEvent.submit((field as HTMLInputElement).form!) })
|
||||
const form = field.closest('form')
|
||||
if (!form) throw new Error('Expected the new list form')
|
||||
await act(async () => { fireEvent.submit(form) })
|
||||
expect(planner.toast.error).toHaveBeenCalledWith('packing.toast.addError')
|
||||
|
||||
fireEvent.keyDown(screen.getByPlaceholderText('packing.newCategoryPlaceholder'), { key: 'Escape' })
|
||||
|
||||
@@ -135,7 +135,9 @@ describe('prepareForOffline — selected trip', () => {
|
||||
expect(list).not.toHaveBeenCalled();
|
||||
expect(await offlineDb.trips.get(other.id)).toBeDefined();
|
||||
expect(await offlineDb.trips.get(trip.id)).toBeDefined();
|
||||
expect(await offlineDb.blobCache.get(bundle.files[0]!.url!)).toBeDefined();
|
||||
const fileUrl = bundle.files[0]?.url;
|
||||
if (!fileUrl) throw new Error('Expected a file URL in the trip bundle');
|
||||
expect(await offlineDb.blobCache.get(fileUrl)).toBeDefined();
|
||||
expect(getOfflinePrefs().pinnedTripIds).toEqual([trip.id]);
|
||||
expect(getOfflinePrefs().disabledTripIds).not.toContain(trip.id);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user