thamara / time-to-leave

Log work hours and get notified when it's time to leave the office and start to live.
http://timetoleave.app
GNU General Public License v3.0
463 stars 272 forks source link

Transforming import for jest to work & fixing test CI #982

Closed araujoarthur0 closed 1 year ago

araujoarthur0 commented 1 year ago

Related issue

Closes #980

Context / Background

__tests__/__renderer__/workday-waiver.js is failing due to one of its includes not being written in ES6 and needing transpilation. SyntaxError: Unexpected token 'export'

What change is being introduced by this PR?

Searched for many possible solutions. Seems this might be fixed in newer jest versions, but I think we should go that way after we fix our electron usage. Leveraging a few solutions I found over the internet, this is the only solution I found to be working.

A few sources https://stackoverflow.com/questions/75578896/running-test-with-jest-in-repo-using-yarn-syntaxerror-unexpected-token-export https://stackoverflow.com/questions/49263429/jest-gives-an-error-syntaxerror-unexpected-token-export https://jestjs.io/docs/configuration#transformignorepatterns-arraystring

Changes:

How will this be tested?

Running npm run test:jest


Update 1:

Also added a node version to Checks.yml so that the CI can work through the Puppeteer include error. This is fixed in newer versions of node.

> puppeteer@19.5.2 postinstall /home/runner/work/time-to-leave/time-to-leave/node_modules/puppeteer
> node install.js

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'puppeteer/internal/node/install.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:[18](https://github.com/thamara/time-to-leave/actions/runs/5285712756/jobs/9564455308#step:4:19))
    at Object.<anonymous> (/home/runner/work/time-to-leave/time-to-leave/node_modules/puppeteer/install.js:38:27)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! puppeteer@[19](https://github.com/thamara/time-to-leave/actions/runs/5285712756/jobs/9564455308#step:4:20).5.2 postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the puppeteer@19.5.2 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/[20](https://github.com/thamara/time-to-leave/actions/runs/5285712756/jobs/9564455308#step:4:21)[23](https://github.com/thamara/time-to-leave/actions/runs/5285712756/jobs/9564455308#step:4:24)-06-16T02_52_[28](https://github.com/thamara/time-to-leave/actions/runs/5285712756/jobs/9564455308#step:4:29)_767Z-debug.log
Error: Process completed with exit code 1.

Update 2: The repo has a patch for jest 3.0.0 and it seems there is a new 3.0.1 for which the patch fails. Changed package.json to force the version we are patching.


Update 3:

Error happening for macos:

 ● Notifications › notify › displays a notification in test

    : Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error:

      22 |         });
      23 |
    > 24 |         test('displays a notification in test', (done) =>
         |         ^
      25 |         {
      26 |             process.env.NODE_ENV = 'test';
      27 |             const notification = createNotification('test');

      at new Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
      at Suite.<anonymous> (__tests__/__main__/notification.js:24:9)

This test has a mock fix for Linux, attempting same for macos.


Update 4:

Fixing version of ubuntu to ubuntu-20.04 as actions on ubuntu-latest are getting stuck.

https://github.com/actions/runner-images/issues/6698 https://github.com/actions/runner-images/issues/6704 https://github.com/actions/runner/issues/1819

codecov[bot] commented 1 year ago

Codecov Report

Merging #982 (2c19bb7) into main (3040f66) will decrease coverage by 0.14%. The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #982      +/-   ##
==========================================
- Coverage   70.38%   70.24%   -0.14%     
==========================================
  Files          27       27              
  Lines        2161     2188      +27     
  Branches      323      348      +25     
==========================================
+ Hits         1521     1537      +16     
- Misses        640      651      +11     
Impacted Files Coverage Δ
js/classes/FlexibleMonthCalendar.js 60.05% <0.00%> (-0.36%) :arrow_down:
js/main-window.js 72.56% <0.00%> (-0.41%) :arrow_down:
js/windows.js 26.92% <0.00%> (ø)
src/preferences.js 84.26% <0.00%> (ø)
src/workday-waiver.js 82.52% <0.00%> (+0.26%) :arrow_up:

... and 7 files with indirect coverage changes