BoostIO / BoostNote-Legacy

This repository is outdated and new Boost Note app is available! We've launched a new Boost Note app which supports real-time collaborative writing. https://github.com/BoostIO/BoostNote-App
Other
17.07k stars 1.47k forks source link

[WIP] Migrate to jest #3547

Closed ZeroX-DG closed 4 years ago

ZeroX-DG commented 4 years ago

Description

As a first step to migrate from ava to Jest, I've choosen all tests in "tests/lib" as a first target.

Take over from https://github.com/BoostIO/Boostnote/pull/3207

Related issue

1826

Type of changes

Checklist:

Test coverage differencies

Just check to see the coverage don't get worse accidentally.

Before

yarn cross-env NODE_ENV=test nyc ava --serial tests/lib/*-test.js

-------------------------------|----------|----------|----------|----------|-------------------|
File                           |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
-------------------------------|----------|----------|----------|----------|-------------------|
All files                      |    79.31 |    66.38 |    71.56 |     81.4 |                   |
 Boostnote                     |      100 |      100 |      100 |      100 |                   |
  webpack-skeleton.js          |      100 |      100 |      100 |      100 |                   |
 Boostnote/browser/lib         |    84.15 |    74.42 |    77.22 |    85.74 |                   |
  Languages.js                 |    83.33 |      100 |      100 |    83.33 |                84 |
  RcParser.js                  |      100 |      100 |      100 |      100 |                   |
  consts.js                    |      100 |       50 |      100 |      100 |          12,13,45 |
  findNoteTitle.js             |      100 |     96.3 |      100 |      100 |                39 |
  findStorage.js               |       75 |       50 |      100 |      100 |               5,7 |
  getTodoStatus.js             |    83.33 |      100 |    66.67 |    83.33 |             23,24 |
  htmlTextHelper.js            |      100 |      100 |      100 |      100 |                   |
  i18n.js                      |      100 |       50 |      100 |      100 |                12 |
  keygen.js                    |      100 |      100 |      100 |      100 |                   |
  markdown-it-deflist.js       |    92.31 |    84.13 |      100 |     98.2 |            67,130 |
  markdown-it-fence.js         |    79.76 |       58 |       80 |    81.01 |... ,97,98,100,108 |
  markdown-it-frontmatter.js   |       40 |       50 |      100 |       40 |  9,10,11,12,14,18 |
  markdown-it-sanitize-html.js |    76.19 |     64.1 |       60 |    74.14 |... 17,118,120,122 |
  markdown-toc-generator.js    |    97.14 |      100 |      100 |      100 |                   |
  markdown.js                  |     74.1 |    63.93 |       45 |     74.8 |... 07,210,259,277 |
  markdownTextHelper.js        |    66.67 |      100 |      100 |    66.67 |             31,32 |
  normalizeEditorFontFamily.js |      100 |      100 |      100 |      100 |                   |
  search.js                    |    83.33 |    56.25 |    85.71 |    85.71 |          26,27,32 |
  slugify.js                   |      100 |      100 |      100 |      100 |                   |
  utils.js                     |    82.26 |    90.48 |       60 |    83.05 |... 28,129,132,136 |
 Boostnote/browser/main/lib    |    52.48 |    36.21 |    46.15 |    56.04 |                   |
  ConfigManager.js             |    54.35 |     37.5 |    66.67 |    58.33 |... 95,196,199,202 |
  eventEmitter.js              |    33.33 |        0 |        0 |    28.57 |      5,9,13,16,17 |
 Boostnote/tests/fixtures      |    71.03 |    48.21 |       70 |    73.86 |                   |
  TestDummy.js                 |    67.37 |    48.21 |       70 |    69.74 |... 61,163,164,167 |
  markdowns.js                 |      100 |      100 |      100 |      100 |                   |
 Boostnote/tests/helpers       |      100 |      100 |    57.14 |      100 |                   |
  setup-browser-env.js         |      100 |      100 |    66.67 |      100 |                   |
  setup-electron-mock.js       |      100 |      100 |        0 |      100 |                   |
-------------------------------|----------|----------|----------|----------|-------------------|

After

yarn jest --coverage tests/lib

---------------------------------------|----------|----------|----------|----------|-------------------|
File                                   |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
---------------------------------------|----------|----------|----------|----------|-------------------|
All files                              |    81.99 |    64.61 |    76.64 |     83.1 |                   |
 browser/lib                           |    77.14 |    70.02 |    61.86 |    78.59 |                   |
  Languages.js                         |    83.33 |      100 |      100 |    83.33 |                84 |
  RcParser.js                          |      100 |      100 |      100 |      100 |                   |
  consts.js                            |      100 |       50 |      100 |      100 |          12,13,44 |
  contextMenuBuilder.js                |    66.67 |       50 |       50 |    66.67 |... 05,110,113,117 |
  findNoteTitle.js                     |      100 |    95.83 |      100 |      100 |                39 |
  findStorage.js                       |       75 |       50 |      100 |      100 |               5,7 |
  getTodoStatus.js                     |    83.33 |      100 |    66.67 |    83.33 |             23,24 |
  htmlTextHelper.js                    |      100 |      100 |      100 |      100 |                   |
  i18n.js                              |      100 |       50 |      100 |      100 |                11 |
  keygen.js                            |      100 |      100 |      100 |      100 |                   |
  markdown-it-deflist.js               |    92.19 |    84.13 |      100 |    98.17 |            67,130 |
  markdown-it-fence.js                 |    81.01 |       58 |       75 |    81.82 |... ,97,98,100,108 |
  markdown-it-frontmatter.js           |       40 |       50 |      100 |       40 |  9,10,11,12,14,18 |
  markdown-it-sanitize-html.js         |     71.7 |     64.1 |       60 |     71.7 |... 17,118,120,122 |
  markdown-toc-generator.js            |     12.9 |        0 |        0 |    13.33 |... 82,86,90,91,92 |
  markdown.js                          |    69.11 |    62.07 |       45 |    72.17 |... 07,210,259,277 |
  markdownTextHelper.js                |        0 |      100 |        0 |        0 | 10,11,12,31,32,34 |
  normalizeEditorFontFamily.js         |      100 |      100 |      100 |      100 |                   |
  search.js                            |    82.61 |    56.25 |    85.71 |       85 |          26,27,32 |
  slugify.js                           |      100 |      100 |      100 |      100 |                   |
  spellcheck.js                        |    74.36 |    72.34 |       50 |    74.03 |... 05,206,208,215 |
  utils.js                             |    84.75 |    89.74 |       80 |    84.75 |... 27,128,129,132 |
 browser/main/lib                      |    51.06 |     37.5 |    46.15 |    54.65 |                   |
  ConfigManager.js                     |    52.27 |     37.5 |    66.67 |    56.25 |... 95,196,199,202 |
  eventEmitter.js                      |    33.33 |      100 |        0 |    33.33 |         5,9,13,17 |
 tests                                 |    66.67 |      100 |        0 |    66.67 |                   |
  jest.js                              |    66.67 |      100 |        0 |    66.67 |                 6 |
 tests/fixtures                        |    71.13 |     47.5 |       70 |    73.49 |                   |
  TestDummy.js                         |    67.06 |     47.5 |       70 |    69.01 |... 61,163,164,167 |
  markdowns.js                         |      100 |      100 |      100 |      100 |                   |
 tests/lib                             |    95.16 |      100 |    92.68 |    95.04 |                   |
  contextMenuBuilder.test.js           |    99.02 |      100 |       96 |      100 |                   |
  escapeHtmlCharacters.test.js         |      100 |      100 |      100 |      100 |                   |
  find-storage.test.js                 |      100 |      100 |      100 |      100 |                   |
  find-title.test.js                   |      100 |      100 |      100 |      100 |                   |
  get-todo-status.test.js              |      100 |      100 |      100 |      100 |                   |
  html-text-helper.test.js             |    70.59 |      100 |    66.67 |    70.59 |    42,48,49,50,51 |
  markdown-text-helper.test.js         |    33.33 |      100 |        0 |    33.33 |        8,42,43,44 |
  markdown-toc-generator.test.js       |    21.74 |      100 |        0 |    21.74 |... 61,662,663,665 |
  markdown.test.js                     |      100 |      100 |      100 |      100 |                   |
  normalize-editor-font-family.test.js |      100 |      100 |      100 |      100 |                   |
  rc-parser.test.js                    |      100 |      100 |      100 |      100 |                   |
  search.test.js                       |      100 |      100 |      100 |      100 |                   |
  slugify.test.js                      |      100 |      100 |      100 |      100 |                   |
  spellcheck.test.js                   |      100 |      100 |      100 |      100 |                   |
  utils.test.js                        |      100 |      100 |      100 |      100 |                   |
---------------------------------------|----------|----------|----------|----------|-------------------|
Rokt33r commented 4 years ago

@ZeroX-DG Can you fix the tests?

ZeroX-DG commented 4 years ago

Interesting, all tests pass on CI but not at my local. I'll investigate more :smile:

ZeroX-DG commented 4 years ago

The bug appears on my local:

TypeError: Cannot read property 'prototype' of undefined

       8 | const uniqueSlug = require('unique-slug')
       9 | const mdurl = require('mdurl')
    > 10 | const fse = require('fs-extra')
      11 | jest.mock('sander')
      12 | const sander = require('sander')
      13 |

      at patch (node_modules/fs-extra/node_modules/graceful-fs/graceful-fs.js:166:54)
      at Object.<anonymous> (node_modules/fs-extra/node_modules/graceful-fs/graceful-fs.js:27:18)
      at Object.<anonymous> (node_modules/fs-extra/lib/fs/index.js:4:12)
      at Object.<anonymous> (node_modules/fs-extra/lib/index.js:8:12)
      at Object.<anonymous> (tests/dataApi/attachmentManagement.test.js:10:1)

This is due to graceful-fs so it's an upstream issue. I got no idea how the test passed on Travis tho :thinking: https://github.com/isaacs/node-graceful-fs/issues/109

ZeroX-DG commented 4 years ago

Turns out this could be related to the process of jest mocking fs module. I need to investigate this deeper :weary:

ZeroX-DG commented 4 years ago

Turns out it's because there's an error running jest on node 13. I changed to v8 and things works fine.