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 25, 2024
1 parent d4a1140 commit 04a98a5
Show file tree
Hide file tree
Showing 42 changed files with 390 additions and 80 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
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
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion 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
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
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: 3 additions & 3 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
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
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
2 changes: 1 addition & 1 deletion 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 Down
6 changes: 3 additions & 3 deletions apps/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 @@ -24,8 +24,8 @@ module.exports = {
coverageThreshold: {
global: {
statements: -180,
branches: -47,
functions: -15,
branches: -60,
functions: -16,
lines: -180,
},
},
Expand Down
2 changes: 1 addition & 1 deletion apps/scan/backend/src/scanners/custom/state_machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ export function createPrecinctScannerStateMachine({
type: interpretation.type,
reasons: interpretation.reasons,
};
/* c8 ignore next 2 */
/* istanbul ignore next */
default:
throwIllegalValue(interpretation, 'type');
}
Expand Down
6 changes: 3 additions & 3 deletions apps/scan/backend/src/scanners/pdi/state_machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ function setupLogging(
);
})
.onChange(async (context, previousContext) => {
/* c8 ignore next */
/* istanbul ignore next */
if (!previousContext) return;
const changed = Object.entries(context).filter(
([key, value]) => previousContext[key as keyof Context] !== value
Expand Down Expand Up @@ -1129,7 +1129,7 @@ export function createPrecinctScannerStateMachine({
return 'calibrating_double_feed_detection.done';
case state.matches('shoeshineModeRescanningBallot'):
return 'accepted';
/* c8 ignore next 2 */
/* istanbul ignore next */
default:
throw new Error(`Unexpected state: ${state.value}`);
}
Expand All @@ -1153,7 +1153,7 @@ export function createPrecinctScannerStateMachine({
type: interpretation.type,
reasons: interpretation.reasons,
};
/* c8 ignore next 2 */
/* istanbul ignore next */
default:
return throwIllegalValue(interpretation, 'type');
}
Expand Down
6 changes: 3 additions & 3 deletions libs/backend/src/election_package/election_package_io.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ test('readElectionPackageFromFile errors when given an invalid election', async
expect(await readElectionPackageFromFile(file)).toEqual(
err({
type: 'invalid-election',
message: 'Unexpected token o in JSON at position 1',
message: `Unexpected token 'o', "not a valid election" is not valid JSON`,
})
);
});
Expand All @@ -351,7 +351,7 @@ test('readElectionPackageFromFile errors when given invalid system settings', as
expect(await readElectionPackageFromFile(file)).toEqual(
err({
type: 'invalid-system-settings',
message: 'Unexpected token o in JSON at position 1',
message: `Unexpected token 'o', "not a valid"... is not valid JSON`,
})
);
});
Expand All @@ -368,7 +368,7 @@ test('readElectionPackageFromFile errors when given invalid metadata', async ()
expect(await readElectionPackageFromFile(file)).toEqual(
err({
type: 'invalid-metadata',
message: 'Unexpected token a in JSON at position 0',
message: `Unexpected token 'a', "asdf" is not valid JSON`,
})
);
});
Expand Down
2 changes: 1 addition & 1 deletion libs/custom-scanner/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ module.exports = {
'!src/mocks/**/*.ts',
'!src/types/**/*.ts',
],
coverageProvider: 'v8',
coverageProvider: 'babel',
};
4 changes: 2 additions & 2 deletions libs/custom-scanner/src/custom_a4_scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ export class CustomA4Scanner implements CustomScanner {
scan(
scanParameters: ScanParameters,
{
/* c8 ignore next */
/* istanbul ignore next */
maxTimeoutNoMoveNoScan = 5_000,
/* c8 ignore next */
/* istanbul ignore next */
maxRetries = 3,
}: { maxTimeoutNoMoveNoScan?: number; maxRetries?: number } = {}
): Promise<Result<SheetOf<ImageFromScanner>, ErrorCode>> {
Expand Down
2 changes: 1 addition & 1 deletion libs/custom-scanner/src/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function convertToMultiSheetDetectionSensorLevelInternal(
return MultiSheetDetectionSensorLevelInternal.Level3;
case DoubleSheetDetectOpt.Level4:
return MultiSheetDetectionSensorLevelInternal.Level4;
/* c8 ignore next 2 */
/* istanbul ignore next */
default:
throwIllegalValue(option);
}
Expand Down
6 changes: 3 additions & 3 deletions libs/custom-scanner/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ class GetImageDataRequestScanSideCoder extends BaseCoder<ScanSide> {
case GetImageDataRequestScanSideCoder.SideB:
return { value: ScanSide.B, bitOffset: decoded.bitOffset };

/* c8 ignore next 2 */
/* istanbul ignore next */
default:
return err('InvalidValue');
}
Expand Down Expand Up @@ -819,7 +819,7 @@ export function checkAnswer(data: Buffer): CheckAnswerResult {
case ResponseErrorCode.INVALID_JOB_ID:
return { type: 'error', errorCode: ErrorCode.JobNotValid };

/* c8 ignore next 2 */
/* istanbul ignore next */
default:
throwIllegalValue(errorCode);
}
Expand Down Expand Up @@ -856,7 +856,7 @@ function mapCoderError<T>(result: Result<T, CoderError>): Result<T, ErrorCode> {
case 'UnsupportedOffset':
throw new Error(`BUG: unsupported offset`);

/* c8 ignore next 2 */
/* istanbul ignore next */
default:
throwIllegalValue(coderError);
}
Expand Down
2 changes: 1 addition & 1 deletion libs/pdi-scanner/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ module.exports = {
'!src/ts/index.ts',
'!src/ts/demo.ts',
],
coverageProvider: 'v8',
coverageProvider: 'babel',
};
2 changes: 1 addition & 1 deletion libs/pdi-scanner/src/ts/scanner_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export function createPdiScannerClient() {
});

pdictl.stderr.on('data', (data) => {
/* c8 ignore next */
/* istanbul ignore next */
debug('pdictl stderr:', data.toString('utf-8'));
});

Expand Down
8 changes: 3 additions & 5 deletions libs/ui/src/reports/precinct_scanner_tally_reports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@votingworks/types';
import {
combineElectionResults,
getContestsForPrecinct,
getContestsForPrecinctSelection,
getEmptyElectionResults,
} from '@votingworks/utils';
import { PrecinctScannerTallyReport } from './precinct_scanner_tally_report';
Expand Down Expand Up @@ -50,11 +50,9 @@ export function PrecinctScannerTallyReports({
});
const partyIds =
getPartyIdsForPrecinctScannerTallyReports(electionDefinition);
const allContests = getContestsForPrecinct(
const allContests = getContestsForPrecinctSelection(
electionDefinition,
precinctSelection.kind === 'SinglePrecinct'
? precinctSelection.precinctId
: undefined
precinctSelection
);

return partyIds.map((partyId) => {
Expand Down
6 changes: 3 additions & 3 deletions libs/utils/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ module.exports = {
...shared,
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'],
coverageProvider: 'v8',
coverageProvider: 'babel',
coverageThreshold: {
global: {
branches: -30,
lines: -123,
branches: -35,
lines: -124,
},
},
collectCoverageFrom: [
Expand Down
Loading

0 comments on commit 04a98a5

Please sign in to comment.