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

Make Jest tests work better with TypeScript #2558

Merged
merged 17 commits into from
Jan 12, 2021
Merged

Make Jest tests work better with TypeScript #2558

merged 17 commits into from
Jan 12, 2021

Conversation

Twixes
Copy link
Collaborator

@Twixes Twixes commented Nov 30, 2020

Changes

ts-jest is a way to make Jest work smoothly with TypeScript. Should resolve #2535.

Checklist

  • Jest frontend tests

@timgl timgl temporarily deployed to posthog-ts-jest-yiefcfjdp6tyxz November 30, 2020 08:54 Inactive
@timgl timgl temporarily deployed to posthog-ts-jest-yiefcfjdp6tyxz November 30, 2020 21:18 Inactive
Copy link
Contributor

@paolodamico paolodamico left a comment

Choose a reason for hiding this comment

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

A few non-blocking comments in the review. Only thing is I tested the case reported on #2535 and it still throws the exception.

import { lightColors } from 'lib/colors' // Line 7 of lib/utils.tsx
 FAIL  frontend/src/lib/utils.test.ts
  ● Test suite failed to run

    Configuration error:
    
    Could not locate module lib/colors mapped as:
    ./src/lib/$1.
    
    Please check your configuration for these entries:
    {
      "moduleNameMapper": {
        "/^lib\/(.*)$/": "./src/lib/$1"
      },
      "resolver": undefined
    }

       5 | import moment from 'moment'
       6 | import { EventType } from '~/types'
    >  7 | import { lightColors } from 'lib/colors'

Also, might be worth for someone with stronger expertise on Jest to take a look, but if we can fix the case described above, IMO it's good to go.

frontend/src/lib/utils.tsx Outdated Show resolved Hide resolved
frontend/src/lib/utils.tsx Show resolved Hide resolved
@timgl timgl temporarily deployed to posthog-ts-jest-yiefcfjdp6tyxz November 30, 2020 23:37 Inactive
@Twixes Twixes temporarily deployed to posthog-ts-jest-yiefcfjdp6tyxz December 1, 2020 08:37 Inactive
@Twixes
Copy link
Collaborator Author

Twixes commented Dec 1, 2020

Hm, yes, the problem from #2535 does persist and I honestly have no idea how to fix it. 🤔

@paolodamico
Copy link
Contributor

Maybe it's worth merging this PR anyways, though it seems like #2535 is not resolved yet. It's not an issue right now, but it might become an issue later as we start adding more unit tests to files that have absolute imports.

@Twixes Twixes changed the title Make Jest tests work better with TypeScript using ts-jest Make Jest tests work better with TypeScript Jan 11, 2021
@Twixes
Copy link
Collaborator Author

Twixes commented Jan 11, 2021

@paolodamico Actually ended up not using ts-jest, but this seems to resolve #2535 nevertheless. 🤔 Take a look please, maybe we can merge.

package.json Outdated Show resolved Hide resolved
@paolodamico paolodamico merged commit 598aea0 into master Jan 12, 2021
@paolodamico paolodamico deleted the ts-jest branch January 12, 2021 23:47
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.

Jest path configuration issue
3 participants