Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Node Upgrade] Revert packages using v8 coverage back to babel #5370

Merged
merged 1 commit into from
Sep 11, 2024
Merged
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 apps/admin/backend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
lines: 100,
},
},
coverageProvider: 'v8',
coverageProvider: 'babel',
collectCoverageFrom: [
'**/*.{ts,tsx}',
'!**/*.d.ts',
Expand Down
11 changes: 4 additions & 7 deletions apps/admin/backend/src/adjudication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function adjudicateVote(

const scannedIsVote = contestVotes
? contestVotes.includes(voteAdjudication.optionId)
: /* c8 ignore next 1 */
: /* istanbul ignore next */
false;

// if the vote is already the target status, do nothing
Expand Down Expand Up @@ -63,10 +63,9 @@ async function logWriteInAdjudication({
return `a vote for an official candidate (${initialWriteInRecord.candidateId})`;
case 'write-in-candidate':
return `a vote for a write-in candidate (${initialWriteInRecord.candidateId})`;
/* c8 ignore start */
/* istanbul ignore next */
default:
throwIllegalValue(initialWriteInRecord, 'adjudicationType');
/* c8 ignore stop */
}
})();

Expand All @@ -80,10 +79,9 @@ async function logWriteInAdjudication({
return `a vote for a write-in candidate (${adjudicationAction.candidateId})`;
case 'reset':
return `unadjudicated`;
/* c8 ignore start */
/* istanbul ignore next */
default:
throwIllegalValue(adjudicationAction, 'type');
/* c8 ignore stop */
}
})();

Expand Down Expand Up @@ -169,10 +167,9 @@ export async function adjudicateWriteIn(
// ensure the vote appears as it originally was in tallies
store.deleteVoteAdjudication(initialWriteInRecord);
break;
/* c8 ignore start */
/* istanbul ignore next */
default:
throwIllegalValue(adjudicationAction, 'type');
/* c8 ignore stop */
}

// if we are switching away from a write-in candidate, we may have to clean
Expand Down
17 changes: 17 additions & 0 deletions apps/admin/backend/src/app.tally_report_data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
} from '@votingworks/utils';
import { assert, find } from '@votingworks/basics';
import { Tabulation } from '@votingworks/types';
import { initializeGetWorkspaceDiskSpaceSummary } from '@votingworks/backend';
import { mockOf } from '@votingworks/test-utils';
import {
buildTestEnvironment,
configureMachine,
Expand All @@ -27,6 +29,14 @@ jest.mock('@votingworks/utils', () => {
};
});

jest.mock(
'@votingworks/backend',
(): typeof import('@votingworks/backend') => ({
...jest.requireActual('@votingworks/backend'),
initializeGetWorkspaceDiskSpaceSummary: jest.fn(),
})
);

beforeEach(() => {
jest.restoreAllMocks();
featureFlagMock.enableFeatureFlag(
Expand All @@ -35,6 +45,13 @@ beforeEach(() => {
featureFlagMock.enableFeatureFlag(
BooleanEnvironmentVariableName.SKIP_CAST_VOTE_RECORDS_AUTHENTICATION
);
mockOf(initializeGetWorkspaceDiskSpaceSummary).mockReturnValue(() =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated, but this test kept flaking locally, so copied this pattern from other tests that depend on this function to de-flake

Promise.resolve({
total: 10 * 1_000_000,
used: 1 * 1_000_000,
available: 9 * 1_000_000,
})
);
});

afterEach(() => {
Expand Down
10 changes: 4 additions & 6 deletions apps/admin/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function getCurrentElectionRecord(
workspace: Workspace
): Optional<ElectionRecord> {
const electionId = workspace.store.getCurrentElectionId();
/* c8 ignore next 3 */
/* istanbul ignore next */
if (!electionId) {
return undefined;
}
Expand Down Expand Up @@ -249,7 +249,7 @@ function buildApi({
return printer.status();
},

/* c8 ignore start */
/* istanbul ignore next */
generateSignedHashValidationQrCodeValue() {
const { machineId } = getMachineConfig();
const electionRecord = getCurrentElectionRecord(workspace);
Expand All @@ -258,7 +258,6 @@ function buildApi({
ballotHash: electionRecord?.electionDefinition?.ballotHash,
});
},
/* c8 ignore stop */

async getUsbDriveStatus(): Promise<UsbDriveStatus> {
return usbDrive.status();
Expand Down Expand Up @@ -327,12 +326,11 @@ function buildApi({
signatureFile.fileName,
signatureFile.fileContents
);
/* c8 ignore start: Tricky to make this second export err but the first export succeed
/* istanbul ignore next: Tricky to make this second export err but the first export succeed
without significant mocking */
if (exportSignatureFileResult.isErr()) {
return exportSignatureFileResult;
}
/* c8 ignore stop */
} finally {
await fs.rm(tempDirectory, { recursive: true });
}
Expand Down Expand Up @@ -433,7 +431,7 @@ function buildApi({
await zipPromise.promise;
const fileContents = Buffer.concat(chunks);
const result = await readElectionPackageFromBuffer(fileContents);
/* c8 ignore next */
/* istanbul ignore next */
return result.isErr() ? result : ok({ ...result.ok(), fileContents });
}
return await readElectionPackageFromFile(input.electionFilePath);
Expand Down
11 changes: 6 additions & 5 deletions apps/admin/backend/src/cast_vote_records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,14 @@ export async function listCastVoteRecordExportsOnUsbDrive(
case 'not-directory': {
return err('found-file-instead-of-directory');
}
/* c8 ignore start: Hard to trigger without significant mocking */
/* istanbul ignore next: Hard to trigger without significant mocking */
case 'permission-denied': {
return err('permission-denied');
}
/* c8 ignore stop */
/* c8 ignore start: Compile-time check for completeness */
/* istanbul ignore next: Compile-time check for completeness */
default: {
throwIllegalValue(errorType);
}
/* c8 ignore stop */
}
}

Expand Down Expand Up @@ -180,7 +178,10 @@ export async function listCastVoteRecordExportsOnUsbDrive(

return ok(
[...castVoteRecordExportSummaries].sort(
(a, b) => b.exportTimestamp.getTime() - a.exportTimestamp.getTime()
/* istanbul ignore next */
(a, b) => {
return b.exportTimestamp.getTime() - a.exportTimestamp.getTime();
}
)
);
}
Expand Down
4 changes: 2 additions & 2 deletions apps/admin/backend/src/exports/csv_ballot_count_report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function buildRow({
const values: string[] = [...metadataValues];

const counts: number[] = [];
/* c8 ignore next - trivial fallthrough case */
/* istanbul ignore next - trivial fallthrough case */
const manual = cardCounts.manual ?? 0;
const { bmd } = cardCounts;
const total = getBallotCount(cardCounts);
Expand All @@ -81,7 +81,7 @@ function buildRow({

if (maxSheetsPerBallot) {
for (let i = 0; i < maxSheetsPerBallot; i += 1) {
/* c8 ignore next - trivial fallthrough case */
/* istanbul ignore next - trivial fallthrough case */
const currentSheetCount = cardCounts.hmpb[i] ?? 0;
counts.push(currentSheetCount);
}
Expand Down
7 changes: 4 additions & 3 deletions apps/admin/backend/src/reports/readiness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ async function getReadinessReport({
{};

return AdminReadinessReport({
/* c8 ignore start */
batteryInfo: (await getBatteryInfo()) ?? undefined,
/* c8 ignore stop */
batteryInfo:
(await getBatteryInfo()) ??
/* istanbul ignore next */
undefined,
diskSpaceSummary: await workspace.getDiskSpaceSummary(),
printerStatus: await printer.status(),
mostRecentPrinterDiagnostic:
Expand Down
2 changes: 1 addition & 1 deletion apps/admin/backend/src/reports/titles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export function generateTitleForReport({
return ok(`Undervoted ${reportType} Report`);
case 'hasWriteIn':
return ok(`Write-In ${reportType} Report`);
/* c8 ignore next 2 */
/* istanbul ignore next */
default:
throwIllegalValue(adjudicationFlag);
}
Expand Down
6 changes: 2 additions & 4 deletions apps/admin/backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function start({
debug('starting server...');
detectDevices({ logger: baseLogger });
let resolvedWorkspace = workspace;
/* c8 ignore start */
/* istanbul ignore next */
if (!resolvedWorkspace) {
const workspacePath = ADMIN_WORKSPACE;
if (!workspacePath) {
Expand All @@ -64,11 +64,10 @@ export async function start({
}
resolvedWorkspace = createWorkspace(workspacePath, baseLogger);
}
/* c8 ignore stop */

let resolvedApp = app;

/* c8 ignore start */
/* istanbul ignore next */
if (!resolvedApp) {
const auth = new DippedSmartCardAuth({
card:
Expand Down Expand Up @@ -97,7 +96,6 @@ export async function start({
workspace: resolvedWorkspace,
});
}
/* c8 ignore stop */

const server = resolvedApp.listen(port, async () => {
await baseLogger.log(LogEventId.ApplicationStartup, 'system', {
Expand Down
25 changes: 15 additions & 10 deletions apps/admin/backend/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1400,8 +1400,8 @@ export class Store {
) as CastVoteRecordVoteAdjudication[];

for (const adjudication of adjudications) {
const currentContestVotes =
votes[adjudication.contestId] ?? /* c8 ignore next 1 */ [];
/* istanbul ignore next */
const currentContestVotes = votes[adjudication.contestId] ?? [];
if (adjudication.isVote) {
votes[adjudication.contestId] = [
...currentContestVotes,
Expand Down Expand Up @@ -1463,7 +1463,7 @@ export class Store {
from vote_adjudications
group by cvr_id
) aggregated_adjudications
on
on
cvrs.election_id = aggregated_adjudications.election_id and
cvrs.id = aggregated_adjudications.cvr_id
where ${whereParts.join(' and ')}
Expand Down Expand Up @@ -1569,8 +1569,11 @@ export class Store {
ballotStyleId: groupBy.groupByBallotStyle
? row.ballotStyleId
: undefined,
/* c8 ignore next - edge case coverage needed for bad party grouping in general election */
partyId: groupBy.groupByParty ? row.partyId ?? undefined : undefined,
/* istanbul ignore next - edge case coverage needed for bad party grouping in general election */
partyId: groupBy.groupByParty
? /* istanbul ignore next */
row.partyId ?? undefined
: undefined,
batchId: groupBy.groupByBatch ? row.batchId : undefined,
scannerId: groupBy.groupByScanner ? row.scannerId : undefined,
precinctId: groupBy.groupByPrecinct ? row.precinctId : undefined,
Expand Down Expand Up @@ -1928,8 +1931,11 @@ export class Store {
ballotStyleId: groupBy.groupByBallotStyle
? row.ballotStyleId
: undefined,
/* c8 ignore next - edge case coverage needed for bad party grouping in general election */
partyId: groupBy.groupByParty ? row.partyId ?? undefined : undefined,
/* istanbul ignore next - edge case coverage needed for bad party grouping in general election */
partyId: groupBy.groupByParty
? /* istanbul ignore next */
row.partyId ?? undefined
: undefined,
batchId: groupBy.groupByBatch ? row.batchId : undefined,
scannerId: groupBy.groupByScanner ? row.scannerId : undefined,
precinctId: groupBy.groupByPrecinct ? row.precinctId : undefined,
Expand Down Expand Up @@ -2188,7 +2194,7 @@ export class Store {
this.client.run(
`
delete from vote_adjudications
where
where
election_id = ? and
cvr_id = ? and
contest_id = ? and
Expand Down Expand Up @@ -2595,7 +2601,7 @@ export class Store {
updateMaximumUsableDiskSpace(this.client, space);
}

/* c8 ignore start */
/* istanbul ignore next */
getDebugSummary(): Map<string, number> {
const tableNameRows = this.client.all(
`select name from sqlite_schema where type='table' order by name;`
Expand All @@ -2615,5 +2621,4 @@ export class Store {
)
);
}
/* c8 ignore stop */
}
2 changes: 1 addition & 1 deletion apps/admin/backend/src/tabulation/card_counts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ function addCardTallyToCardCounts({
// eslint-disable-next-line no-param-reassign
cardCounts.bmd += tally;
} else {
/* istanbul ignore next - trivial fallback case */
// eslint-disable-next-line no-param-reassign
cardCounts.hmpb[card.sheetNumber - 1] =
/* c8 ignore next - trivial fallback case */
(cardCounts.hmpb[card.sheetNumber - 1] ?? 0) + tally;
}

Expand Down
5 changes: 3 additions & 2 deletions apps/admin/backend/src/tabulation/full_results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export async function tabulateElectionResults({
});

// ignore manual results if the tabulation is not successful
/* istanbul ignore else */
if (queryResult.isOk()) {
debug('merging manual results into CVR results');
const groupedManualResults = queryResult.ok();
Expand Down Expand Up @@ -180,8 +181,8 @@ export async function tabulateElectionResults({
});
}
);
/* c8 ignore next 3 - debug only */
} else {
} /* istanbul ignore next - debug only */ else {
/* istanbul ignore next */
debug('filter or group by is not compatible with manual results');
}
}
Expand Down
8 changes: 3 additions & 5 deletions apps/admin/backend/src/tabulation/manual_results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ function getManualResultsGroupSpecifier(
* Aggregates an iterable list of manual results records into one or many
* combined manual results based on the specified grouping.
*/
export function aggregateManualResults({
election,
manualResultsRecords,
groupBy = {},
}: {
export function aggregateManualResults(params: {
election: Election;
manualResultsRecords: Iterable<ManualResultsRecord>;
groupBy?: Tabulation.GroupBy;
}): Tabulation.ManualResultsGroupMap {
/* istanbul ignore next */
const { election, manualResultsRecords, groupBy = {} } = params;
const manualResultsGroupMap: Tabulation.ManualResultsGroupMap = {};

const ballotStyleIdPartyIdLookup = getBallotStyleIdPartyIdLookup(election);
Expand Down
9 changes: 3 additions & 6 deletions apps/admin/backend/src/tabulation/tally_reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,14 @@ function addContestIdsToReports<U>({
* adjusted with write-in adjudication data (but combining all unofficial write-ins)
* and manual results separately.
*/
export async function tabulateTallyReportResults({
electionId,
store,
filter = {},
groupBy = {},
}: {
export async function tabulateTallyReportResults(params: {
electionId: Id;
store: Store;
filter?: Tabulation.Filter;
groupBy?: Tabulation.GroupBy;
}): Promise<Tabulation.GroupList<Admin.TallyReportResults>> {
/* istanbul ignore next - type-checked defaults */
const { electionId, store, filter = {}, groupBy = {} } = params;
const {
electionDefinition: { election },
} = assertDefined(store.getElection(electionId));
Expand Down
2 changes: 1 addition & 1 deletion apps/admin/backend/src/tabulation/write_ins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function addWriteInTallyToElectionWriteInSummary({
isWriteIn: true,
};
break;
/* c8 ignore next 2 */
/* istanbul ignore next */
default:
throwIllegalValue(writeInTally);
}
Expand Down
Loading