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

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

Merged
merged 7 commits into from
Jun 17, 2023

Conversation

araujoarthur0
Copy link
Collaborator

@araujoarthur0 araujoarthur0 commented Jun 16, 2023

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:

  • Adding a babel.config.js file that sets the preset '@babel/preset-env'. It has to be a file and cannot be configured in package.json like it was before, or jest will ignore the file.
  • Adding --ignoreTransformPatterns that makes jest stop ignoring the astronomia package when transpiling .js files. Some people suggest adding this to jest.config.js but it did not work with our setup. Only by adding to the command line did I get it to work.

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.

> [email protected] 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 [email protected] 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.

actions/runner-images#6698
actions/runner-images#6704
actions/runner#1819

@codecov
Copy link

codecov bot commented Jun 16, 2023

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%) ⬇️
js/main-window.js 72.56% <0.00%> (-0.41%) ⬇️
js/windows.js 26.92% <0.00%> (ø)
src/preferences.js 84.26% <0.00%> (ø)
src/workday-waiver.js 82.52% <0.00%> (+0.26%) ⬆️

... and 7 files with indirect coverage changes

@araujoarthur0 araujoarthur0 changed the title Transforming import for jest to work Transforming import for jest to work & fixing test CI Jun 16, 2023
@thamara thamara merged commit d18c9e3 into TTLApp:main Jun 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Workday waiver test failing in CI
2 participants