Skip to content

Ensure test setup and teardown does not count towards test coverage #1267

Open
@bickelj

Description

@bickelj

During #1262, while working in the /changemakers integration tests, I figured that beforeEach calls (and transitive calls from within that) would not be marked as "covered", likewise for blocks/statements marked with /* istanbul ignore next */. However, even after peppering test setups with /* istanbul ignore next */, the coverage is identical to before such peppering, and I see a lot of unrelated/untested code being marked as "covered" inaccurately.

Example coverage report when running only the changemakers integration tests with coverage, both before and after adding ignore next statements:

-------------------------------------------|---------|----------|---------|---------|-------------------
File                                       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------------------------------------|---------|----------|---------|---------|-------------------
All files                                  |   59.36 |    21.17 |   30.41 |   58.53 |                   
 src                                       |    60.6 |    13.63 |   33.33 |   58.33 |                   
  ajv.ts                                   |   88.88 |      100 |       0 |   88.88 | 13                
  app.ts                                   |     100 |      100 |     100 |     100 |                   
  config.ts                                |    90.9 |        0 |     100 |   88.88 | 13                
  fieldValidation.ts                       |   57.89 |        0 |       0 |   58.82 | 33-45             
  index.ts                                 |       0 |        0 |       0 |       0 | 1-38              
  jobQueue.ts                              |   51.51 |    28.57 |      25 |   46.42 | 14-28,33-44,55,66 
  logger.ts                                |     100 |       50 |     100 |     100 | 9                 
  s3Client.ts                              |     100 |      100 |     100 |     100 |                   
 src/auth                                  |     100 |      100 |     100 |     100 |                   
  jwtOptions.ts                            |     100 |      100 |     100 |     100 |                   
 src/database                              |     100 |        0 |     100 |     100 |                   
  db.ts                                    |     100 |      100 |     100 |     100 |                   
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  migrate.ts                               |     100 |        0 |     100 |     100 | 9                 
 src/database/operations                   |     100 |      100 |     100 |     100 |                   
  index.ts                                 |     100 |      100 |     100 |     100 |                   
 ...abase/operations/applicationFormFields |   64.28 |        0 |      25 |      64 |                   
  createApplicationFormField.ts            |   88.88 |        0 |     100 |   88.88 | 23                
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  loadApplicationFormField.ts              |   44.44 |        0 |       0 |    37.5 | 8-21              
  loadApplicationFormFieldBundle.ts        |   42.85 |      100 |       0 |      40 | 13-23             
 src/database/operations/applicationForms  |   64.28 |        0 |      25 |    62.5 |                   
  createApplicationForm.ts                 |   88.88 |        0 |     100 |    87.5 | 20                
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  loadApplicationForm.ts                   |   44.44 |        0 |       0 |    37.5 | 8-21              
  loadApplicationFormBundle.ts             |   42.85 |      100 |       0 |      40 | 8-17              
 ...abase/operations/baseFieldLocalization |   47.36 |        0 |       0 |   47.05 |                   
  createOrUpdateBaseFieldLocalizations.ts  |      40 |        0 |       0 |   33.33 | 12-32             
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  ...ldLocalizationsBundleByBaseFieldId.ts |   42.85 |      100 |       0 |      50 | 13-24             
 src/database/operations/baseFields        |   62.16 |       25 |      20 |   57.57 |                   
  createBaseField.ts                       |   88.88 |       50 |     100 |    87.5 | 25                
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  loadBaseField.ts                         |   44.44 |        0 |       0 |    37.5 | 6-19              
  loadBaseFields.ts                        |      60 |      100 |       0 |      50 | 5-6               
  updateBaseField.ts                       |      40 |        0 |       0 |   33.33 | 13-32             
 src/database/operations/bulkUploads       |   42.85 |        0 |       0 |   37.83 |                   
  createBulkUpload.ts                      |   33.33 |        0 |       0 |      25 | 11-29             
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  loadBulkUpload.ts                        |   44.44 |        0 |       0 |    37.5 | 6-19              
  loadBulkUploadBundle.ts                  |   33.33 |      100 |       0 |   28.57 | 16-31             
  updateBulkUpload.ts                      |   36.36 |        0 |       0 |      30 | 13-36             
 ...tabase/operations/changemakerProposals |   72.22 |        0 |   33.33 |   73.33 |                   
  createChangemakerProposal.ts             |   88.88 |        0 |     100 |    87.5 | 21                
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  loadChangemakerProposalBundle.ts         |   42.85 |      100 |       0 |      40 | 14-25             
 src/database/operations/changemakers      |   85.71 |    44.44 |      80 |   83.78 |                   
  createChangemaker.ts                     |   88.88 |    33.33 |     100 |    87.5 | 21                
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  loadChangemaker.ts                       |     100 |      100 |     100 |     100 |                   
  loadChangemakerBundle.ts                 |     100 |      100 |     100 |     100 |                   
  loadChangemakerByTaxId.ts                |   44.44 |        0 |       0 |    37.5 | 8-23              
 src/database/operations/dataProviders     |   60.52 |    11.11 |      20 |   62.16 |                   
  createOrUpdateDataProvider.ts            |   88.88 |    33.33 |     100 |   88.88 | 21                
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  loadDataProvider.ts                      |   44.44 |        0 |       0 |   44.44 | 8-21              
  loadDataProviderBundle.ts                |   42.85 |      100 |       0 |      50 | 8-17              
  loadSystemDataProvider.ts                |   44.44 |        0 |       0 |   44.44 | 6-17              
 src/database/operations/funders           |   64.28 |    16.66 |      25 |   65.38 |                   
  createOrUpdateFunder.ts                  |   88.88 |    33.33 |     100 |   88.88 | 21                
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  loadFunder.ts                            |   44.44 |        0 |       0 |    37.5 | 6-19              
  loadFunderBundle.ts                      |   42.85 |      100 |       0 |      50 | 8-17              
 src/database/operations/generic           |   90.47 |        0 |     100 |   89.47 |                   
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  loadBundle.ts                            |     100 |      100 |     100 |     100 |                   
  loadTableMetrics.ts                      |   83.33 |        0 |     100 |   81.81 | 17,23             
 src/database/operations/opportunities     |   64.28 |    16.66 |      25 |   65.38 |                   
  createOpportunity.ts                     |   88.88 |    33.33 |     100 |    87.5 | 21                
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  loadOpportunity.ts                       |   44.44 |        0 |       0 |   44.44 | 6-19              
  loadOpportunityBundle.ts                 |   42.85 |      100 |       0 |      50 | 8-17              
 ...atabase/operations/proposalFieldValues |      90 |       50 |     100 |      90 |                   
  createProposalFieldValue.ts              |   88.88 |       50 |     100 |   88.88 | 31                
  index.ts                                 |     100 |      100 |     100 |     100 |                   
 src/database/operations/proposalVersions  |      90 |       50 |     100 |      90 |                   
  createProposalVersion.ts                 |   88.88 |       50 |     100 |   88.88 | 24                
  index.ts                                 |     100 |      100 |     100 |     100 |                   
 src/database/operations/proposals         |    57.5 |        0 |      20 |   54.28 |                   
  assertProposalAuthorization.ts           |   44.44 |        0 |       0 |    37.5 | 9-19              
  createProposal.ts                        |   88.88 |        0 |     100 |    87.5 | 19                
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  loadProposal.ts                          |   44.44 |        0 |       0 |    37.5 | 6-16              
  loadProposalBundle.ts                    |   33.33 |      100 |       0 |   28.57 | 18-35             
 src/database/operations/sources           |   71.42 |    58.33 |   33.33 |   71.11 |                   
  assertSourceExists.ts                    |   57.14 |        0 |       0 |      50 | 6-11              
  createSource.ts                          |   91.66 |    77.77 |     100 |    90.9 | 28                
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  loadSource.ts                            |   44.44 |        0 |       0 |    37.5 | 6-16              
  loadSourceBundle.ts                      |   42.85 |      100 |       0 |      50 | 8-17              
  loadSystemSource.ts                      |   88.88 |        0 |     100 |   88.88 | 12                
 src/database/operations/users             |   78.04 |    28.57 |      60 |   78.37 |                   
  createUser.ts                            |   88.88 |    33.33 |     100 |    87.5 | 11                
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  loadSystemUser.ts                        |   88.88 |        0 |     100 |   88.88 | 12                
  loadUserBundle.ts                        |   33.33 |      100 |       0 |   28.57 | 16-31             
  loadUserByKeycloakUserId.ts              |      90 |    33.33 |     100 |   88.88 | 17                
 src/database/parameters                   |    90.9 |        0 |     100 |      90 |                   
  getLimitValues.ts                        |      90 |        0 |     100 |   88.88 | 14                
  index.ts                                 |     100 |      100 |     100 |     100 |                   
 src/errors                                |   86.66 |      100 |      75 |   86.66 |                   
  DatabaseError.ts                         |     100 |      100 |     100 |     100 |                   
  FailedMiddlewareError.ts                 |     100 |      100 |     100 |     100 |                   
  InputConflictError.ts                    |      25 |      100 |       0 |      25 | 12-14             
  InputValidationError.ts                  |     100 |      100 |     100 |     100 |                   
  InternalValidationError.ts               |     100 |      100 |     100 |     100 |                   
  JobQueueStateError.ts                    |       0 |      100 |     100 |       0 | 1                 
  NotFoundError.ts                         |     100 |      100 |     100 |     100 |                   
  UnauthorizedError.ts                     |     100 |      100 |     100 |     100 |                   
  ValidationError.ts                       |     100 |      100 |     100 |     100 |                   
  index.ts                                 |     100 |      100 |     100 |     100 |                   
 src/handlers                              |   25.29 |     5.96 |    7.43 |   25.29 |                   
  applicationFormsHandlers.ts              |    18.6 |        0 |       0 |    18.6 | ...3,42-56,65-107 
  baseFieldsHandlers.ts                    |   13.75 |        0 |       0 |   13.75 | ...10-144,153-216 
  bulkUploadsHandlers.ts                   |   20.45 |        0 |       0 |   20.45 | 33-87,96-117      
  changemakerProposalsHandlers.ts          |   25.92 |        0 |       0 |   25.92 | 23-44,53-72       
  changemakersHandlers.ts                  |   81.57 |    69.23 |   88.88 |   81.57 | 43,61-65,86-87    
  dataProvidersHandlers.ts                 |   18.36 |        0 |       0 |   18.36 | ...1,50-66,75-108 
  fundersHandlers.ts                       |   18.36 |        0 |       0 |   18.36 | 22-37,42-58,63-96 
  opportunitiesHandlers.ts                 |   22.85 |        0 |       0 |   22.85 | 21-32,41-55,64-82 
  platformProviderResponsesHandlers.ts     |   35.48 |        0 |       0 |   35.48 | 30-61,90-121      
  presignedPostRequestsHandlers.ts         |      50 |        0 |       0 |      50 | 16,31-52          
  proposalVersionsHandlers.ts              |   13.55 |        0 |       0 |   13.55 | ...79-111,119-211 
  proposalsHandlers.ts                     |      25 |        0 |   11.11 |      25 | ...8,63-81,90-120 
  sourcesHandlers.ts                       |   19.04 |        0 |       0 |   19.04 | 22-48,53-68,73-87 
  usersHandlers.ts                         |      35 |        0 |       0 |      35 | 11-28             
 src/middleware                            |   76.81 |    42.85 |   82.35 |   76.64 |                   
  addRoleContext.ts                        |     100 |      100 |     100 |     100 |                   
  addUserContext.ts                        |   78.26 |       50 |      75 |   78.26 | 17-18,38-44,53    
  errorHandler.ts                          |   75.38 |    48.27 |     100 |      75 | ...,90,98,104,121 
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  processJwt.ts                            |      80 |        0 |   66.66 |      80 | 18-20             
  requireAdministratorRole.ts              |      50 |        0 |       0 |      50 | 11-17             
  requireAuthentication.ts                 |   71.42 |    33.33 |     100 |   71.42 | 16-21,24-25       
 src/queryParameters                       |      80 |    28.57 |   66.66 |   78.94 |                   
  extractChangemakerParameters.ts          |      90 |    66.66 |     100 |      90 | 41                
  extractCreatedByParameters.ts            |   58.33 |        0 |       0 |   58.33 | 48-59             
  extractKeycloakUserIdParameters.ts       |   63.63 |        0 |       0 |   63.63 | 29-36             
  extractPaginationParameters.ts           |    87.5 |    57.14 |     100 |   85.71 | 11                
  extractProposalParameters.ts             |      90 |        0 |     100 |      90 | 31                
  extractSearchParameters.ts               |     100 |      100 |     100 |     100 |                   
  index.ts                                 |     100 |      100 |     100 |     100 |                   
 src/routers                               |     100 |      100 |     100 |     100 |                   
  applicationFormsRouter.ts                |     100 |      100 |     100 |     100 |                   
  baseFieldsRouter.ts                      |     100 |      100 |     100 |     100 |                   
  bulkUploadsRouter.ts                     |     100 |      100 |     100 |     100 |                   
  changemakerProposalsRouter.ts            |     100 |      100 |     100 |     100 |                   
  changemakersRouter.ts                    |     100 |      100 |     100 |     100 |                   
  dataProviderRouter.ts                    |     100 |      100 |     100 |     100 |                   
  documentationRouter.ts                   |     100 |      100 |     100 |     100 |                   
  fundersRouter.ts                         |     100 |      100 |     100 |     100 |                   
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  opportunitiesRouter.ts                   |     100 |      100 |     100 |     100 |                   
  platformProviderResponsesRouter.ts       |     100 |      100 |     100 |     100 |                   
  presignedPostRequestsRouter.ts           |     100 |      100 |     100 |     100 |                   
  proposalVersionsRouter.ts                |     100 |      100 |     100 |     100 |                   
  proposalsRouter.ts                       |     100 |      100 |     100 |     100 |                   
  sourcesRouter.ts                         |     100 |      100 |     100 |     100 |                   
  usersRouter.ts                           |     100 |      100 |     100 |     100 |                   
 src/scripts                               |       0 |        0 |       0 |       0 |                   
  migrate.ts                               |       0 |        0 |       0 |       0 | 1-18              
 src/tasks                                 |   17.72 |        0 |       0 |   17.19 |                   
  index.ts                                 |     100 |      100 |     100 |     100 |                   
  processBulkUpload.ts                     |   17.19 |        0 |       0 |   16.66 | ...01-211,218-382 
 src/test                                  |   88.31 |    77.77 |   77.77 |   89.55 |                   
  harnessFunctions.ts                      |   93.54 |        0 |     100 |   92.85 | 7,12              
  mockGraphileWorker.ts                    |       0 |      100 |       0 |       0 | 1-5               
  mockJwt.ts                               |     100 |      100 |     100 |     100 |                   
  utils.ts                                 |   86.36 |      100 |      50 |    87.5 | 21-22             
 src/types                                 |   99.46 |    72.72 |     100 |   99.45 |                   
  ApplicationForm.ts                       |     100 |      100 |     100 |     100 |                   
  ApplicationFormField.ts                  |     100 |      100 |     100 |     100 |                   
  AuthContext.ts                           |     100 |      100 |     100 |     100 |                   
  BaseField.ts                             |     100 |      100 |     100 |     100 |                   
  BaseFieldLocalization.ts                 |     100 |      100 |     100 |     100 |                   
  BulkUpload.ts                            |     100 |      100 |     100 |     100 |                   
  Changemaker.ts                           |     100 |      100 |     100 |     100 |                   
  ChangemakerProposal.ts                   |     100 |      100 |     100 |     100 |                   
  DataProvider.ts                          |     100 |      100 |     100 |     100 |                   
  Funder.ts                                |     100 |      100 |     100 |     100 |                   
  Id.ts                                    |     100 |      100 |     100 |     100 |                   
  JsonObject.ts                            |     100 |      100 |     100 |     100 |                   
  KeycloakUserId.ts                        |   94.11 |        0 |     100 |   94.11 | 19                
  Language.ts                              |     100 |      100 |     100 |     100 |                   
  Opportunity.ts                           |     100 |      100 |     100 |     100 |                   
  PaginationParameters.ts                  |     100 |      100 |     100 |     100 |                   
  PaginationParametersQuery.ts             |     100 |      100 |     100 |     100 |                   
  PostgresErrorCode.ts                     |     100 |      100 |     100 |     100 |                   
  PresignedPostRequest.ts                  |     100 |      100 |     100 |     100 |                   
  ProcessBulkUploadJobPayload.ts           |     100 |      100 |     100 |     100 |                   
  Proposal.ts                              |     100 |      100 |     100 |     100 |                   
  ProposalFieldValue.ts                    |     100 |      100 |     100 |     100 |                   
  ProposalVersion.ts                       |     100 |      100 |     100 |     100 |                   
  ShortCode.ts                             |     100 |      100 |     100 |     100 |                   
  Source.ts                                |     100 |      100 |     100 |     100 |                   
  TableMetrics.ts                          |     100 |      100 |     100 |     100 |                   
  TinyPgErrorWithQueryContext.ts           |     100 |      100 |     100 |     100 |                   
  User.ts                                  |     100 |      100 |     100 |     100 |                   
  Uuid.ts                                  |     100 |      100 |     100 |     100 |                   
  index.ts                                 |     100 |      100 |     100 |     100 |                   
 src/types/express                         |     100 |      100 |     100 |     100 |                   
  AuthenticatedRequest.ts                  |     100 |      100 |     100 |     100 |                   
-------------------------------------------|---------|----------|---------|---------|-------------------

Test Suites: 1 passed, 1 total
Tests:       20 passed, 20 total

The expected behavior would be to omit coverage from create... methods, and really all untested code, except when it is actually under test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions