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

Set up and improve code coverage #943

Merged
merged 35 commits into from
Jun 3, 2021
Merged

Set up and improve code coverage #943

merged 35 commits into from
Jun 3, 2021

Conversation

macbre
Copy link
Owner

@macbre macbre commented May 28, 2021

The current state:

$ npm run unit-test

------------------------------|---------|----------|---------|---------|------------------------------------------------------------------------------------------------
File                          | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                                                                              
------------------------------|---------|----------|---------|---------|------------------------------------------------------------------------------------------------
All files                     |   62.52 |    46.08 |   69.75 |   65.18 |                                                                                              
$ npm t
-------------------------------|---------|----------|---------|---------|------------------------------------------------------------------------------------------------
File                           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                                                                              
-------------------------------|---------|----------|---------|---------|------------------------------------------------------------------------------------------------
All files                      |   76.43 |    60.98 |   82.59 |   77.81 |       

After changes

-------------------------------|---------|----------|---------|---------|-------------------
File                           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------------------------|---------|----------|---------|---------|-------------------
All files                      |   90.11 |    86.07 |   92.68 |   90.24 |                   

Directories with coverage to be improved

$ grep -v '100 |      100 |     100 |     10' /tmp/coverage
-------------------------------|---------|----------|---------|---------|------------------------------------------------------------------------------------------------
File                           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                                                                              
-------------------------------|---------|----------|---------|---------|------------------------------------------------------------------------------------------------
All files                      |   76.24 |    59.24 |   84.15 |   77.68 |                                                                                                
 core                          |   85.71 |    83.33 |   91.67 |   85.71 |                                                                                                
  results.js                   |   85.71 |    83.33 |   91.67 |   85.71 | 24-28,82,98                                                                                    
 core/modules/requestsMonitor  |   95.89 |     90.7 |      90 |   96.55 |                                                                                                
  requestsMonitor.js           |   95.89 |     90.7 |      90 |   96.55 | 39-41,197-198                                                                                  
 core/modules/timeToFirstByte  |    87.5 |       75 |     100 |    87.5 |                                                                                                
  timeToFirstByte.js           |    87.5 |       75 |     100 |    87.5 | 19-20                                                                                          
 extensions/cookies            |   96.77 |     87.5 |     100 |   96.55 |                                                                                                
  cookies.js                   |   96.77 |     87.5 |     100 |   96.55 | 37                                                                                             
 extensions/filmStrip          |     9.3 |       10 |    12.5 |     9.3 |                                                                                                
  filmStrip.js                 |     9.3 |       10 |    12.5 |     9.3 | 26-127                                                                                         
 extensions/har                |   12.66 |      6.9 |   11.11 |   12.99 |                                                                                                
  har.js                       |   12.66 |      6.9 |   11.11 |   12.99 | 19-84,111,139-252                                                                              
 extensions/screenshot         |   96.43 |     87.5 |     100 |   96.43 |                                                                                                
  screenshot.js                |   96.43 |     87.5 |     100 |   96.43 | 21                                                                                             
 lib                           |   54.99 |    26.61 |    67.9 |   57.59 |                                                                                                
  browser.js                   |    93.6 |    80.56 |     100 |   93.44 | 45,52-53,63,78-79,177-181                                                                      
  fast-stats.js                |    19.5 |    11.27 |   26.47 |   20.43 | 15-50,60-62,97-128,135-136,142,155-160,167-215,233-343,352-412,417,425,434-440,453-481,491-598 
  index.js                     |    97.5 |      100 |   88.89 |    97.5 | 87-88                                                                                          
 modules/analyzeCss            |   78.69 |    68.29 |     100 |   78.33 |                                                                                                
  analyzeCss.js                |   78.69 |    68.29 |     100 |   78.33 | 102-127                                                                                        
 modules/blockDomains          |   90.24 |    84.38 |     100 |   90.24 |                                                                                                
  blockDomains.js              |   90.24 |    84.38 |     100 |   90.24 | 33,41,73-74                                                                                    
 modules/cacheHits             |     100 |    92.86 |     100 |     100 |                                                                                                
  cacheHits.js                 |     100 |    92.86 |     100 |     100 | 31                                                                                             
 modules/domains               |     100 |       50 |     100 |     100 |                                                                                                
  domains.js                   |     100 |       50 |     100 |     100 | 19-34                                                                                          
 modules/headers               |     100 |    83.33 |     100 |     100 |                                                                                                
  headers.js                   |     100 |    83.33 |     100 |     100 | 23                                                                                             
 modules/keepAlive             |      75 |    83.33 |     100 |      75 |                                                                                                
  keepAlive.js                 |      75 |    83.33 |     100 |      75 | 28-37                                                                                          
 modules/protocols             |     100 |    95.45 |     100 |     100 |                                                                                                
  protocols.js                 |     100 |    95.45 |     100 |     100 | 18                                                                                             
 modules/requestsStats         |   95.83 |    92.86 |     100 |   95.83 |                                                                                                
  requestsStats.js             |   95.83 |    92.86 |     100 |   95.83 | 81-82                                                                                          
 modules/requestsTo            |   89.29 |       60 |     100 |   89.29 |                                                                                                
  requestsTo.js                |   89.29 |       60 |     100 |   89.29 | 38-40                                                                                          
 modules/staticAssets          |   97.87 |    97.62 |     100 |   97.87 |                                                                                                
  staticAssets.js              |   97.87 |    97.62 |     100 |   97.87 | 35                                                                                             
 modules/timeToFirst           |   94.74 |      100 |      80 |   94.74 |                                                                                                
  timeToFirst.js               |   94.74 |      100 |      80 |   94.74 | 26                                                                                             
 modules/windowPerformance     |   96.67 |       50 |     100 |   96.67 |                                                                                                
  windowPerformance.js         |   96.67 |       50 |     100 |   96.67 | 88                                                                                             
-------------------------------|---------|----------|---------|---------|------------------------------------------------------------------------------------------------
  • results.js
  • requestsMonitor.js
  • timeToFirstByte.js
  • cookies.js
  • filmStrip.js
  • har.js
  • screenshot.js
  • browser.js
  • fast-stats.js -> use https://github.com/bluesmoon/node-faststats package // e323df9
  • index.js
  • analyzeCss.js
  • blockDomains.js
  • cacheHits.js
  • domains.js
  • headers.js
  • keepAlive.js
  • protocols.js
  • requestsStats.js
  • requestsTo.js
  • staticAssets.js
  • timeToFirst.js
  • windowPerformance.js
  • mock.js (can be skipped -> 558f2e1)

@macbre
Copy link
Owner Author

macbre commented May 31, 2021

$ npx jest test/npm-module.test.js --coverage
 FAIL  test/npm-module.test.js
  CommonJS module's promise
    should resolve a promise
      ✕ when provided a valid url (823 ms)
    should reject a promise
      ✓ when not provided with URL
      ✓ when timed out (616 ms)

  ● CommonJS module's promise › should resolve a promise › when provided a valid url

    Evaluation failed: ReferenceError: cov_1ncfgi6eg6 is not defined

      at __puppeteer_evaluation_script__:3:7
      at ExecutionContext._evaluateInternal (node_modules/puppeteer/src/common/ExecutionContext.ts:275:13)
      at ExecutionContext.evaluate (node_modules/puppeteer/src/common/ExecutionContext.ts:140:12)
      at modules/windowPerformance/windowPerformance.js:28:20
          at async Promise.all (index 0)
      at promise (lib/index.js:187:7)

istanbuljs/nyc#514 (comment)

@macbre
Copy link
Owner Author

macbre commented May 31, 2021

  phantomas:extensions:userAgent userAgent set to Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4469.0 Safari/537.36 Phantomas/2.2.0 +0ms
  phantomas:browser Go to URL <http://127.0.0.1:8888/phantomas-scope.html> and wait for "load" +134ms
  phantomas:network Network.requestWillBeSent > GET http://127.0.0.1:8888/phantomas-scope.html [other] +0ms
  phantomas:AwaitEventEmitter:emit request +10ms
  phantomas:AwaitEventEmitter:emit send +0ms
  phantomas:browser Page error: Error: ReferenceError: cov_9njucydc5 is not defined
  phantomas:browser     at <anonymous>:3:9
  phantomas:browser     at <anonymous>:6:9 +22ms
  phantomas:AwaitEventEmitter:emit jserror +20ms
  phantomas:modules:jserrors ReferenceError: cov_9njucydc5 is not defined +0ms
  phantomas:modules:jserrors Backtrace:     at <anonymous>:3:9 /     at <anonymous>:6:9 +0ms

  puppeteer:protocol:RECV ◀ {"method":"Runtime.exceptionThrown","params":{"timestamp":1.622476415502759e+12,"exceptionDetails":{"exceptionId":1,"text":"Uncaught","lineNumber":2,"columnNumber":8,"scriptId":"5","stackTrace":{"callFrames":[{"functionName":"","scriptId":"5","url":"","lineNumber":2,"columnNumber":8},{"functionName":"","scriptId":"5","url":"","lineNumber":5,"columnNumber":8}]},"exception":{"type":"object","subtype":"error","className":"ReferenceError","description":"ReferenceError: cov_9njucydc5 is not defined\n    at <anonymous>:3:9\n    at <anonymous>:6:9","objectId":"3183586473547778731.3.1","preview":{"type":"object","subtype":"error","description":"ReferenceError: cov_9njucydc5 is not defined\n    at <anonymous>:3:9\n    at <anonymous>:6:9","overflow":false,"properties":[{"name":"stack","type":"string","value":"ReferenceError: cov_9njucydc5 is not defined\n    at <anonymous>:3:9\n    at <anonymous>:6:9"},{"name":"message","type":"string","value":"cov_9njucydc5 is not defined"}]}},"executionContextId":3}},"sessionId":"E68119A2919A49448BEBD9AC7AB78070"} +0ms
  phantomas:browser Page error: Error: ReferenceError: cov_9njucydc5 is not defined
  phantomas:browser     at <anonymous>:3:9
  phantomas:browser     at <anonymous>:6:9 +21ms
  phantomas:AwaitEventEmitter:emit jserror +19ms

@macbre macbre marked this pull request as ready for review June 1, 2021 15:44
@macbre
Copy link
Owner Author

macbre commented Jun 1, 2021

Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.

@macbre macbre changed the title Improve code coverage Set up and Improve code coverage Jun 2, 2021
@macbre macbre changed the title Set up and Improve code coverage Set up and improve code coverage Jun 2, 2021
@macbre macbre added this to the v2.3 milestone Jun 2, 2021
@macbre
Copy link
Owner Author

macbre commented Jun 2, 2021

Current state after the above changes:

-------------------------------|---------|----------|---------|---------|------------------------------------------------------------------------------------------------
File                           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                                                                              
-------------------------------|---------|----------|---------|---------|------------------------------------------------------------------------------------------------
All files                      |   76.36 |     59.1 |   83.93 |   77.82 |                                                                                                
  results.js                   |   85.71 |    83.33 |   91.67 |   85.71 | 24-28,82,98                                                                                    
  requestsMonitor.js           |   95.89 |     90.7 |      90 |   96.55 | 39-41,197-198                                                                                  
  timeToFirstByte.js           |    87.5 |       75 |     100 |    87.5 | 19-20                                                                                          
  cookies.js                   |   96.77 |     87.5 |     100 |   96.55 | 37                                                                                             
  filmStrip.js                 |     9.3 |       10 |    12.5 |     9.3 | 26-127                                                                                         
  har.js                       |   12.66 |      6.9 |   11.11 |   12.99 | 19-84,111,139-252                                                                              
  screenshot.js                |   96.43 |     87.5 |     100 |   96.43 | 21                                                                                             
  browser.js                   |     100 |     93.1 |     100 |     100 | 275,336                                                                                        
  fast-stats.js                |    19.5 |    11.27 |   26.47 |   20.43 | 15-50,60-62,97-128,135-136,142,155-160,167-215,233-343,352-412,417,425,434-440,453-481,491-598 
  index.js                     |     100 |      100 |   88.89 |     100 |                                                                                                
  analyzeCss.js                |   78.69 |    68.29 |     100 |   78.33 | 102-127                                                                                        
  blockDomains.js              |   90.24 |    84.38 |     100 |   90.24 | 33,41,73-74                                                                                    
  cacheHits.js                 |     100 |    92.86 |     100 |     100 | 31                                                                                             
  domains.js                   |     100 |       50 |     100 |     100 | 19-34                                                                                          
  headers.js                   |     100 |    83.33 |     100 |     100 | 23                                                                                             
  keepAlive.js                 |      75 |    83.33 |     100 |      75 | 28-37                                                                                          
  protocols.js                 |     100 |    95.45 |     100 |     100 | 18                                                                                             
  requestsStats.js             |   95.83 |    92.86 |     100 |   95.83 | 81-82                                                                                          
  requestsTo.js                |   89.29 |       60 |     100 |   89.29 | 38-40                                                                                          
  staticAssets.js              |   97.87 |    97.62 |     100 |   97.87 | 35                                                                                             
  timeToFirst.js               |   94.74 |      100 |      80 |   94.74 | 26                                                                                             
  windowPerformance.js         |   96.67 |       50 |     100 |   96.67 | 88                                                                                             

@macbre macbre enabled auto-merge June 3, 2021 14:06
@macbre macbre merged commit c97269b into devel Jun 3, 2021
@macbre macbre deleted the coverage branch June 3, 2021 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant