Skip to content

Commit

Permalink
test: switch back to babel-based coverage
Browse files Browse the repository at this point in the history
c8/v8 coverage is buggy post v20.9.0: nodejs/node#51251
  • Loading branch information
eventualbuddha committed Jul 29, 2024
1 parent f96c09e commit bdbeee7
Show file tree
Hide file tree
Showing 54 changed files with 432 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.14.0
20.16.0
10 changes: 5 additions & 5 deletions apps/admin/backend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ module.exports = {
],
coverageThreshold: {
global: {
statements: 100,
branches: 100,
functions: 100,
lines: 100,
statements: 99,
branches: 98,
lines: 99,
functions: 98,
},
},
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
8 changes: 3 additions & 5 deletions apps/admin/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,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 @@ -244,7 +244,7 @@ function buildApi({
return printer.status();
},

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

async getUsbDriveStatus(): Promise<UsbDriveStatus> {
return usbDrive.status();
Expand Down Expand Up @@ -322,12 +321,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
6 changes: 2 additions & 4 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
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
3 changes: 1 addition & 2 deletions apps/admin/backend/src/reports/readiness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ async function getReadinessReport({
: undefined;

return AdminReadinessReport({
/* c8 ignore start */
/* istanbul ignore next */
batteryInfo: (await getBatteryInfo()) ?? undefined,
/* c8 ignore stop */
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 @@ -68,11 +68,10 @@ export async function start({
}
resolvedWorkspace = createWorkspace(workspacePath);
}
/* c8 ignore stop */

let resolvedApp = app;

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

const server = resolvedApp.listen(port, async () => {
await baseLogger.log(LogEventId.ApplicationStartup, 'system', {
Expand Down
9 changes: 4 additions & 5 deletions apps/admin/backend/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ export class Store {

for (const adjudication of adjudications) {
const currentContestVotes =
votes[adjudication.contestId] ?? /* c8 ignore next 1 */ [];
votes[adjudication.contestId] ?? /* istanbul ignore next */ [];
if (adjudication.isVote) {
votes[adjudication.contestId] = [
...currentContestVotes,
Expand Down Expand Up @@ -1521,7 +1521,7 @@ export class Store {
ballotStyleId: groupBy.groupByBallotStyle
? row.ballotStyleId
: undefined,
/* c8 ignore next - edge case coverage needed for bad party grouping in general election */
/* istanbul ignore next - edge case coverage needed for bad party grouping in general election */
partyId: groupBy.groupByParty ? row.partyId ?? undefined : undefined,
batchId: groupBy.groupByBatch ? row.batchId : undefined,
scannerId: groupBy.groupByScanner ? row.scannerId : undefined,
Expand Down Expand Up @@ -1880,7 +1880,7 @@ export class Store {
ballotStyleId: groupBy.groupByBallotStyle
? row.ballotStyleId
: undefined,
/* c8 ignore next - edge case coverage needed for bad party grouping in general election */
/* istanbul ignore next - edge case coverage needed for bad party grouping in general election */
partyId: groupBy.groupByParty ? row.partyId ?? undefined : undefined,
batchId: groupBy.groupByBatch ? row.batchId : undefined,
scannerId: groupBy.groupByScanner ? row.scannerId : undefined,
Expand Down Expand Up @@ -2547,7 +2547,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 @@ -2567,5 +2567,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 @@ -33,7 +33,7 @@ function addCardTallyToCardCounts({
} else {
// eslint-disable-next-line no-param-reassign
cardCounts.hmpb[card.sheetNumber - 1] =
/* c8 ignore next - trivial fallback case */
/* istanbul ignore next - trivial fallback case */
(cardCounts.hmpb[card.sheetNumber - 1] ?? 0) + tally;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/admin/backend/src/tabulation/full_results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export async function tabulateElectionResults({
});
}
);
/* c8 ignore next 3 - debug only */
/* istanbul ignore next - debug only */
} else {
debug('filter or group by is not compatible with manual results');
}
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
4 changes: 2 additions & 2 deletions apps/admin/backend/src/util/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function constructAuthMachineState(
return record;
})();

/* c8 ignore next 3 - covered by integration testing */
/* istanbul ignore next - covered by integration testing */
const jurisdiction = isIntegrationTest()
? TEST_JURISDICTION
: process.env.VX_MACHINE_JURISDICTION ?? DEV_JURISDICTION;
Expand Down Expand Up @@ -64,6 +64,6 @@ export async function getUserRole(
if (authStatus.status === 'logged_in') {
return authStatus.user.role;
}
/* c8 ignore next 2 - trivial fallback case */
/* istanbul ignore next - trivial fallback case */
return 'unknown';
}
2 changes: 1 addition & 1 deletion apps/admin/backend/src/util/cdf_results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function buildOfficialCandidates(
return candidates.map((candidate) => ({
'@type': 'ElectionResults.Candidate',
'@id': candidate.id,
/* c8 ignore next 1 -- trivial fallthrough case */
/* istanbul ignore next -- trivial fallthrough case */
PartyId: candidate.partyIds?.[0],
BallotName: asInternationalizedText(candidate.name),
}));
Expand Down
3 changes: 1 addition & 2 deletions apps/admin/backend/src/util/export_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function exportFile({
const exporter = new Exporter({
allowedExportPatterns: ADMIN_ALLOWED_EXPORT_PATTERNS,
/* We're not using `exportDataToUsbDrive` here, so a mock `usbDrive` is OK */
/* c8 ignore start */
/* istanbul ignore next */
usbDrive: {
status: () =>
Promise.resolve({
Expand All @@ -30,7 +30,6 @@ export function exportFile({
eject: () => Promise.resolve(),
format: () => Promise.resolve(),
},
/* c8 ignore stop */
});

debug('exporting data to file %s', path);
Expand Down
6 changes: 3 additions & 3 deletions apps/admin/backend/src/util/write_ins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function getWriteInImageView({
const contestLayout = layout.contests.find(
(contest) => contest.contestId === contestId
);
/* c8 ignore next 3 - TODO: revisit our layout assumptions based on our new ballots */
/* istanbul ignore next - TODO: revisit our layout assumptions based on our new ballots */
if (!contestLayout) {
throw new Error('unable to find a layout for the specified contest');
}
Expand All @@ -52,13 +52,13 @@ export async function getWriteInImageView({
const writeInOptionIndex = safeParseNumber(
optionId.slice('write-in-'.length)
);
/* c8 ignore next 3 - TODO: revisit our layout assumptions based on our new ballots */
/* istanbul ignore next - TODO: revisit our layout assumptions based on our new ballots */
if (writeInOptionIndex.isErr() || writeInOptions === undefined) {
throw new Error('unable to interpret layout write-in options');
}

const writeInLayout = writeInOptions[writeInOptionIndex.ok()];
/* c8 ignore next 3 - TODO: revisit our layout assumptions based on our new ballots */
/* istanbul ignore next - TODO: revisit our layout assumptions based on our new ballots */
if (writeInLayout === undefined) {
throw new Error('unexpected write-in option index');
}
Expand Down
2 changes: 1 addition & 1 deletion apps/admin/backend/src/util/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function addFileToZipStream(
): Promise<void> {
return new Promise<void>((resolve, reject) => {
zipStream.entry(file.contents, { name: file.path }, (error) => {
/* c8 ignore next 2 - trivial error case */
/* istanbul ignore next - trivial error case */
if (error) {
reject(error);
} else {
Expand Down
8 changes: 4 additions & 4 deletions apps/central-scan/backend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
roots: ['<rootDir>/src'],
setupFiles: ['<rootDir>/test/set_env_vars.ts'],
setupFilesAfterEnv: ['<rootDir>/test/setup_custom_matchers.ts'],
coverageProvider: 'v8',
coverageProvider: 'babel',
collectCoverageFrom: [
'**/*.{ts,tsx}',
'!**/node_modules/**',
Expand All @@ -23,10 +23,10 @@ module.exports = {
],
coverageThreshold: {
global: {
statements: 94,
branches: 86,
statements: 91,
branches: 77,
functions: 91,
lines: 94,
lines: 91,
},
},
};
3 changes: 1 addition & 2 deletions apps/central-scan/backend/src/readiness_report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ export async function saveReadinessReport({
const generatedAtTime = new Date(getCurrentTime());
const electionDefinition = store.getElectionDefinition();
const report = CentralScanReadinessReport({
/* c8 ignore start */
/* istanbul ignore next */
batteryInfo: (await getBatteryInfo()) ?? undefined,
/* c8 ignore stop */
diskSpaceSummary: await workspace.getDiskSpaceSummary(),
isScannerAttached,
mostRecentScannerDiagnostic:
Expand Down
Loading

0 comments on commit bdbeee7

Please sign in to comment.