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

Feature request: Spec files next to sources (co-located tests) #61

Closed
capaj opened this issue Apr 30, 2019 · 13 comments
Closed

Feature request: Spec files next to sources (co-located tests) #61

capaj opened this issue Apr 30, 2019 · 13 comments
Labels
kind: feature New feature or request

Comments

@capaj
Copy link

capaj commented Apr 30, 2019

I like having spec files right next to the source files.
Currently this is not achievable. Can we get a support for this style of filesystem organisation?

@jaredpalmer
Copy link
Owner

I think it’s possible, but would need to investigate and play with the default TS settings.

@mormahr
Copy link

mormahr commented May 3, 2019

So it's not sufficient to change jest's testMatch config? I'm new to TypeScript and used a babel / flow / webpack setup and this was the default. Does TypeScript handle this different?

@techniq
Copy link

techniq commented May 4, 2019

In another project I use Typescript and babel with this config in package.json

  "jest": {
    "rootDir": "src",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx"
    ],
    "transform": {
      "^.+\\.(js|jsx|ts|tsx)$": "babel-jest"
    }
  }

I just tried this in my tsdx project, but it doesn't seem to work.

@techniq
Copy link

techniq commented May 4, 2019

@mormahr the following does seem to locate the tests...

  "jest": {
    "testMatch": [
      "<rootDir>/src/**/?(*.)(spec|test).(ts|js)?(x)"
    ]
  },

but it's failing to find any tests to run

 FAIL  src/app/State.test.tsx
  ● Test suite failed to run

    Your test suite must contain at least one test.

      at node_modules/@jest/core/build/TestScheduler.js:243:24
      at asyncGeneratorStep (node_modules/@jest/core/build/TestScheduler.js:131:24)
      at _next (node_modules/@jest/core/build/TestScheduler.js:151:9)
      at node_modules/@jest/core/build/TestScheduler.js:156:7
      at node_modules/@jest/core/build/TestScheduler.js:148:12
      at onResult (node_modules/@jest/core/build/TestScheduler.js:272:25)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.348s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

although after looking closer, this might be due to some Typescript errors (I was using Typescript 3.1 and not 3.4.3 like tsdx is currently). I'll investigate more later.

@techniq
Copy link

techniq commented May 4, 2019

It did appear to be my failing Typescript types from changes in 3.1 to 3.4.3. Adding testMatch mentioned above was enough to get passing tests within src

@natemoo-re
Copy link
Contributor

natemoo-re commented May 31, 2019

Would folks be open to updating the default testMatch at createJestConfig.ts:15 to support this out of the box?

The version below would support both use cases and running tsdx test from the root of a monorepo (cc #122.)

<rootDir>/**/*.(spec|test).{ts,tsx}

This may have some larger implications, but I think it's worth investigating to keep things as zero-config as possible.

@mormahr
Copy link

mormahr commented May 31, 2019

Yes also: the __tests__/ convention (without needing .test. in the actual test/spec file).

Essentially: Why not use the default jest config of (/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$?

@wachunga
Copy link

I prefer test files next to the source as well, and would prefer not to have to override the testWatch config in my package.json.

@malcolm-kee
Copy link

Is this possible now with v0.8?

@arvinsim
Copy link

Yes, I prefer the test files be next to the source. It's just so much better than having to switch folders view.

@kylemh
Copy link
Contributor

kylemh commented Oct 14, 2019

https://github.com/jaredpalmer/tsdx/blob/master/src/createJestConfig.ts#L12

This is currently possible, and this issue should be closed.

@capaj
Copy link
Author

capaj commented Oct 14, 2019

thanks @kylemh, closing. Will reopen if it doesn't work for me.

@capaj capaj closed this as completed Oct 14, 2019
@agilgur5
Copy link
Collaborator

agilgur5 commented Mar 10, 2020

This was fixed by #159 . Also related to #464 / #472 and #342 / #344

@agilgur5 agilgur5 added the kind: feature New feature or request label Mar 16, 2020
@agilgur5 agilgur5 changed the title Feature request: Spec files next to sources Feature request: Spec files next to sources (co-located tests) Mar 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: feature New feature or request
Projects
None yet
Development

No branches or pull requests

10 participants