jira-tools icon indicating copy to clipboard operation
jira-tools copied to clipboard

jest coverage randomly fails

Open ljay79 opened this issue 6 years ago • 6 comments

Running npx jest --coverage fails randomly.

Running above command multiple times without any changes to source or environment, brings different results every time.

Any idea why?

Lastest develop branch with merged changes from your authmode change. Running Ubuntu for Windows 10 WSL

~$ npm version
{ npm: '6.5.0-next.0',
  ares: '1.15.0',
  cldr: '34.0',
  http_parser: '2.8.0',
  icu: '63.1',
  llhttp: '1.0.1',
  modules: '67',
  napi: '3',
  nghttp2: '1.34.0',
  node: '11.6.0',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.24.1',
  v8: '7.0.276.38-node.13',
  zlib: '1.2.11' }

Output:

ljay@xmach:~/workspace/JiraSheetTool$ npx jest --coverage
 PASS  test/Code.test.js
 PASS  test/settings.test.js
 PASS  test/jsLib.test.js
 PASS  test/environmentConfiguration.test.js
 PASS  test/jiraApi.test.js
------------------------------|----------|----------|----------|----------|-------------------|
File                          |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
------------------------------|----------|----------|----------|----------|-------------------|
All files                     |    57.93 |    37.34 |    53.85 |    57.52 |                   |
 src                          |    55.58 |    37.34 |    46.27 |    55.24 |                   |
  Code.gs                     |    93.33 |      100 |    66.67 |    93.33 |                50 |
  Storage.gs                  |    60.53 |    43.75 |       80 |    60.53 |... 04,105,107,120 |
  customFields.gs             |     5.13 |        0 |        0 |     5.26 |... 90,192,193,196 |
  debug.gs                    |    72.41 |    33.33 |    83.33 |    71.43 |... 58,59,60,61,62 |
  environmentConfiguration.gs |      100 |      100 |      100 |      100 |                   |
  jiraApi.gs                  |    86.36 |    78.38 |    72.73 |    85.98 |... 89,144,145,244 |
  jsLib.gs                    |    37.61 |     19.7 |       20 |    34.34 |... 78,289,291,292 |
  settings.gs                 |    73.13 |    77.78 |    81.82 |       75 |... 65,168,177,178 |
 test/mocks                   |      100 |      100 |      100 |      100 |                   |
  PropertiesService.js        |      100 |      100 |      100 |      100 |                   |
  ScriptApp.js                |      100 |      100 |      100 |      100 |                   |
  SpreadsheetApp.js           |      100 |      100 |      100 |      100 |                   |
------------------------------|----------|----------|----------|----------|-------------------|

Test Suites: 5 passed, 5 total
Tests:       12 passed, 12 total
Snapshots:   0 total
Time:        16.167s
Ran all test suites.
ljay@xmach:~/workspace/JiraSheetTool$ npx jest --coverage
 FAIL  test/jsLib.test.js
  ● Test suite failed to run

    Cannot find module '../util/array' from 'merge.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)

 PASS  test/settings.test.js
 PASS  test/Code.test.js
 PASS  test/jiraApi.test.js
 PASS  test/environmentConfiguration.test.js
------------------------------|----------|----------|----------|----------|-------------------|
File                          |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
------------------------------|----------|----------|----------|----------|-------------------|
All files                     |    52.43 |    33.91 |    52.56 |     53.1 |                   |
 src                          |    49.78 |    33.91 |    44.78 |    50.58 |                   |
  Code.gs                     |    93.33 |      100 |    66.67 |    93.33 |                50 |
  Storage.gs                  |    60.53 |    43.75 |       80 |    60.53 |... 04,105,107,120 |
  customFields.gs             |     5.13 |        0 |        0 |     5.26 |... 90,192,193,196 |
  debug.gs                    |    72.41 |    33.33 |    83.33 |    71.43 |... 58,59,60,61,62 |
  environmentConfiguration.gs |      100 |      100 |      100 |      100 |                   |
  jiraApi.gs                  |    86.36 |    78.38 |    72.73 |    85.98 |... 89,144,145,244 |
  jsLib.gs                    |    13.76 |     7.58 |    13.33 |    14.14 |... 78,289,291,292 |
  settings.gs                 |    73.13 |    77.78 |    81.82 |       75 |... 65,168,177,178 |
 test/mocks                   |      100 |      100 |      100 |      100 |                   |
  PropertiesService.js        |      100 |      100 |      100 |      100 |                   |
  ScriptApp.js                |      100 |      100 |      100 |      100 |                   |
  SpreadsheetApp.js           |      100 |      100 |      100 |      100 |                   |
------------------------------|----------|----------|----------|----------|-------------------|

Test Suites: 1 failed, 4 passed, 5 total
Tests:       10 passed, 10 total
Snapshots:   0 total
Time:        16.059s
Ran all test suites.
ljay@xmach:~/workspace/JiraSheetTool$ npx jest --coverage
 PASS  test/settings.test.js
 PASS  test/jiraApi.test.js
 PASS  test/Code.test.js
 PASS  test/environmentConfiguration.test.js
 PASS  test/jsLib.test.js
------------------------------|----------|----------|----------|----------|-------------------|
File                          |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
------------------------------|----------|----------|----------|----------|-------------------|
All files                     |    57.93 |    37.34 |    53.85 |    57.52 |                   |
 src                          |    55.58 |    37.34 |    46.27 |    55.24 |                   |
  Code.gs                     |    93.33 |      100 |    66.67 |    93.33 |                50 |
  Storage.gs                  |    60.53 |    43.75 |       80 |    60.53 |... 04,105,107,120 |
  customFields.gs             |     5.13 |        0 |        0 |     5.26 |... 90,192,193,196 |
  debug.gs                    |    72.41 |    33.33 |    83.33 |    71.43 |... 58,59,60,61,62 |
  environmentConfiguration.gs |      100 |      100 |      100 |      100 |                   |
  jiraApi.gs                  |    86.36 |    78.38 |    72.73 |    85.98 |... 89,144,145,244 |
  jsLib.gs                    |    37.61 |     19.7 |       20 |    34.34 |... 78,289,291,292 |
  settings.gs                 |    73.13 |    77.78 |    81.82 |       75 |... 65,168,177,178 |
 test/mocks                   |      100 |      100 |      100 |      100 |                   |
  PropertiesService.js        |      100 |      100 |      100 |      100 |                   |
  ScriptApp.js                |      100 |      100 |      100 |      100 |                   |
  SpreadsheetApp.js           |      100 |      100 |      100 |      100 |                   |
------------------------------|----------|----------|----------|----------|-------------------|

Test Suites: 5 passed, 5 total
Tests:       12 passed, 12 total
Snapshots:   0 total
Time:        16.188s
Ran all test suites.
ljay@xmach:~/workspace/JiraSheetTool$ npx jest --coverage
 FAIL  test/settings.test.js
  ● Test suite failed to run

    Cannot find module 'isstream'

      at Object.<anonymous> (node_modules/request/lib/multipart.js:5:16)

 PASS  test/Code.test.js
 PASS  test/jiraApi.test.js
 PASS  test/environmentConfiguration.test.js
 PASS  test/jsLib.test.js
------------------------------|----------|----------|----------|----------|-------------------|
File                          |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
------------------------------|----------|----------|----------|----------|-------------------|
All files                     |    57.93 |    37.34 |    53.85 |    57.52 |                   |
 src                          |    55.58 |    37.34 |    46.27 |    55.24 |                   |
  Code.gs                     |    93.33 |      100 |    66.67 |    93.33 |                50 |
  Storage.gs                  |    60.53 |    43.75 |       80 |    60.53 |... 04,105,107,120 |
  customFields.gs             |     5.13 |        0 |        0 |     5.26 |... 90,192,193,196 |
  debug.gs                    |    72.41 |    33.33 |    83.33 |    71.43 |... 58,59,60,61,62 |
  environmentConfiguration.gs |      100 |      100 |      100 |      100 |                   |
  jiraApi.gs                  |    86.36 |    78.38 |    72.73 |    85.98 |... 89,144,145,244 |
  jsLib.gs                    |    37.61 |     19.7 |       20 |    34.34 |... 78,289,291,292 |
  settings.gs                 |    73.13 |    77.78 |    81.82 |       75 |... 65,168,177,178 |
 test/mocks                   |      100 |      100 |      100 |      100 |                   |
  PropertiesService.js        |      100 |      100 |      100 |      100 |                   |
  ScriptApp.js                |      100 |      100 |      100 |      100 |                   |
  SpreadsheetApp.js           |      100 |      100 |      100 |      100 |                   |
------------------------------|----------|----------|----------|----------|-------------------|

Test Suites: 1 failed, 4 passed, 5 total
Tests:       11 passed, 11 total
Snapshots:   0 total
Time:        16.716s
Ran all test suites.
ljay@xmach:~/workspace/JiraSheetTool$

ljay79 avatar Jan 22 '19 20:01 ljay79

Sorry completely missed this. I have not had this issue at all. What version of node are you using and is the issue still occuring?

paul-lemon avatar Jan 30 '19 17:01 paul-lemon

Still happening, all details see above.

ljay79 avatar Jan 30 '19 18:01 ljay79

Ah sorry - missed that too! :) This must be an issue with Jest / Node on your machine. I'm sure its a bug but not one I can fix with the code in this Repo (or probably one I can fix at all!)

We can try updating Jest to the latest version. Currently its locked on 23.6.x in package.json I'll do that in a quick branch and give you a pull request. If you still have the issue then we should submit a report to the Jest team.

paul-lemon avatar Jan 31 '19 07:01 paul-lemon

Yeah i believe its due to my environment ubuntu under windows 10 WSL. I have similar behavior when working on other projects with docker when the project processes a lot of files.

I will see, how far i can deal with it by executing unit tests one by one instead of all at once.

ljay79 avatar Jan 31 '19 10:01 ljay79

using npm test will run all tests - does that have the same issue? npx jest --coverage runs all tests and generates a coverage report to help you see gaps where the unit tests may need improving. I only run that before I make a pull request and that's not essential

paul-lemon avatar Jan 31 '19 10:01 paul-lemon

Same with npm test. Fails almost always with a different error every time. Always some kind of cannot find module or similar things from node_modules directory.

ljay79 avatar Jan 31 '19 19:01 ljay79