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

Use "canonical" Jest configuration #312

Merged
merged 5 commits into from
Sep 5, 2017

Conversation

tkrotoff
Copy link
Contributor

@tkrotoff tkrotoff commented Aug 31, 2017

Following #310

  • ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
    should be "^.+\\.tsx?$" see 1, 2, 3
  • "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$"
    should be "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$" see 1, 2

Is "^.+\\.tsx?$" that different from ".(ts|tsx)"? I can't explain it but it changes the coverage results for the simple and simple-async tests:

  • With ".(ts|tsx)":

screen shot 2017-08-31 at 15 51 11

  • With "^.+\\.tsx?$":

screen shot 2017-08-31 at 15 51 54

And I believe the results with "^.+\\.tsx?$" are the correct ones.

As for root package.json, I've changed "testRegex": "/__tests__/.*\\.(spec)\\.(ts|js)$" to "tests/__tests__/.*\\.spec\\.ts$".
The path is now hardcoded to be sure to only match files tests/__tests__/*.spec.ts and not the others that end with .test.ts (differentiate test categories with .spec.ts vs .test.ts is dangerous IMHO).

Copy link
Owner

@kulshekhar kulshekhar left a comment

Choose a reason for hiding this comment

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

The changes looks fine to me but I'd like another review - just to be safe

/cc @GeeWee @bcruddy @morajabi

Note: The previous regexes were a remnant of the earliest days of this repo. I didn't track the changes that happened in Jest - hence the divergence. It's good to have this PR.

@GeeWee
Copy link
Collaborator

GeeWee commented Sep 1, 2017

I'm a little worried about the coverage changing.

Are you saying the new regex only matches files in tests folders? I think we should lean on the original jest regex which iirc matches all files in tests and everything called eg .spec.ts and .test.ts

@kulshekhar
Copy link
Owner

kulshekhar commented Sep 1, 2017

Are you saying the new regex only matches files in tests folders? I think we should lean on the original jest regex which iirc matches all files in tests and everything called eg .spec.ts and .test.ts

I actually prefer that change. It sort of standardizes how we structure our tests.

@tkrotoff
Copy link
Contributor Author

tkrotoff commented Sep 1, 2017

I'm a little worried about the coverage changing.

Talking about "^.+\\.tsx?$" vs ".(ts|tsx)" with simple and simple-async tests?
Please clone my repo and play with it. I've changed coverageReporters so that it generates the HTML report.
I'm very interesting to know why the coverage results change.

Are you saying the new regex only matches files in tests folders?

Talking about "testRegex": "tests/__tests__/.*\\.spec\\.ts$" from root package.json? Yes (+ it's already the case), see https://regex101.com/r/lEHjwz/3

@tkrotoff
Copy link
Contributor Author

tkrotoff commented Sep 1, 2017

I actually prefer the change. It sort of standardizes how we structure our tests

Instead of differentiating tests based on a small part of their filenames (spec.ts vs test.ts), I suggest to create 2 separated directories: makes things clear about having 2 types of tests.

Copy link
Contributor

@morajabi morajabi left a comment

Choose a reason for hiding this comment

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

It does what it's intended to do. I'm OK with separating two kinds of tests in two folders.

@tkrotoff
Copy link
Contributor Author

tkrotoff commented Sep 1, 2017

@morajabi

I'm OK with separating two kinds of tests in two folders

This will be for another PR

@GeeWee
Copy link
Collaborator

GeeWee commented Sep 1, 2017

I have strong opinions on some of this. I'll get back to it after the weekend

@GeeWee
Copy link
Collaborator

GeeWee commented Sep 4, 2017

In regards to the regex I think as stated previously:

I think we should lean on the original jest regex which iirc matches all files in tests and everything called eg .spec.ts and .test.ts

While other conventions might make more sense, I'd hate for someone to convert their js to typescript and then go 'Oh my god why don't half my tests run' - I think it should basically be a carbon-copy of the default config from jest.
Does that make sense?

I don't have time to take a look at the coverage atm, but it's really fkn weird. Maybe there's a some version mixup going on? It makes no sense to me that the coverage would change.

@kulshekhar
Copy link
Owner

While other conventions might make more sense, I'd hate for someone to convert their js to typescript and then go 'Oh my god why don't half my tests run' - I think it should basically be a carbon-copy of the default config from jest.

The regex used in the documentation seems to be a copy of that from Jest. It's only in the tests for this repo that the regex is specific to this repo. That's what I was alluding to when I said it sort of standardizes how we structure our tests

I don't have time to take a look at the coverage atm, but it's really fkn weird. Maybe there's a some version mixup going on? It makes no sense to me that the coverage would change.

The coverage bit confounded me a bit too but then seeing that I didn't entirely understand how it exactly worked in the first place (which lines it ignored, etc), this version doesn't look that different. So I'm kinda ok with it. I'll let @tkrotoff chime in on this.

@GeeWee
Copy link
Collaborator

GeeWee commented Sep 5, 2017

I actually thought the jest regex matched both files in tests and .test and .spec everywhere. If they're the same, I'm fine with it.

@kulshekhar
Copy link
Owner

I actually thought the jest regex matched both files in tests and .test and .spec everywhere

The original regex in our (ts-jests's) package.json did that. But because we only have tests in one place and with a uniform naming convention, this change doesn't have any negative effects. It does restrict how we structure our tests going forward though - the tests will need to be in the specified directory and be named *.spec.*.

@kulshekhar kulshekhar merged commit fee6771 into kulshekhar:master Sep 5, 2017
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.

None yet

4 participants