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

Rewrite requesttoken.spec.js with Jest #27286

Merged

Conversation

francoisfreitag
Copy link
Contributor

@francoisfreitag francoisfreitag commented May 29, 2021

Jest is a test runner that focuses on simplicity.
It instruments babel to transform modules and test them.

Using Jest simplifies the existing configuration and allows dropping a
bunch of workarounds, as well as following the shared Babel
configuration for new code.

Signed-off-by: François Freitag [email protected]

Closes #27229
Closes #27227

Copy link
Member

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please!! ❤️

@skjnldsv skjnldsv added 3. to review Waiting for reviews enhancement labels May 30, 2021
@skjnldsv skjnldsv added this to the Nextcloud 22 milestone May 30, 2021
@skjnldsv
Copy link
Member

Can't thank you enough! It was really becoming complicated with webpack5 and stuff!! 🚀

[Jest](https://jestjs.io/) is a test runner that focuses on simplicity.
It instruments babel to transform modules and test them.

Using Jest simplifies the existing configuration and allows dropping a
bunch of workarounds, as well as following the shared Babel
configuration for new code.

Signed-off-by: François Freitag <[email protected]>
@francoisfreitag
Copy link
Contributor Author

francoisfreitag commented May 30, 2021

Thanks for the review!

I just downgraded the jest-babel and jest version to 26.6.3. The main reason is to make it compatible with vue-jest. The 27.x series change the transformer interface in jest-babel. That causes vue tests from #27008 to fail with:

 FAIL  apps/dav/src/views/CalDavSettings.spec.js
  ● Test suite failed to run

    TypeError: Cannot destructure property 'config' of 'undefined' as it is undefined.

      1 | import { render } from '@testing-library/vue'
      2 | import userEvent from '@testing-library/user-event'
    > 3 | import CalDavSettings from './CalDavSettings'
        | ^
      4 | // eslint-disable-next-line no-unused-vars
      5 | import { generateUrl } from '@nextcloud/router'
      6 |

      at Object.getCacheKey (node_modules/vue-jest/lib/index.js:10:7)
      at ScriptTransformer._getCacheKey (node_modules/@jest/transform/build/ScriptTransformer.js:280:41)
      at ScriptTransformer._getFileCachePath (node_modules/@jest/transform/build/ScriptTransformer.js:351:27)
      at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:588:32)
      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:758:40)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:815:19)
      at Object.<anonymous> (apps/dav/src/views/CalDavSettings.spec.js:3:1)

Also, it avoids using jsdom-global, which allows removing the setupFilesAfterEnv entry and makes the jestBabelTransformer.js slighly simpler by using the export from babel-jest directly instead of aliasing default.

@skjnldsv skjnldsv merged commit fd63132 into nextcloud:master May 31, 2021
@francoisfreitag francoisfreitag deleted the rewrite-npm-test-with-jest branch May 31, 2021 08:28
@blizzz blizzz mentioned this pull request Jun 2, 2021
57 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants