vscode-jest icon indicating copy to clipboard operation
vscode-jest copied to clipboard

[Feature Request]: Allow to define different test extensions separated from the jest config.

Open distante opened this issue 3 years ago • 7 comments

Environment

  1. vscode-jest version: v4.4.0
  2. node -v: v16.13.1
  3. npm -v or yarn --version: npm 8.1.2
  4. npm ls jest :
├─┬ [email protected]
│ └── [email protected] deduped
├── [email protected]
└─┬ [email protected]
  └── [email protected] deduped
  1. your vscode-jest settings if customized:
    • jest.jestCommandLine: "npx jest --notify",
    • jest.autoRun:
  "jest.autoRun": {
    "watch": false,
    "onStartup": [],
    "onSave": "test-src-file"
  },
- anything else that you think might be relevant? [fill]
  1. Operating system: MacOs

I am working on a monorepo where some integration tests (*.integration-spec.ts) for a NestJS project exist together with unit test (*.spec.ts).

The unit tests runs as expected after each file change. The integration spec not, which is ok because they need background services that are not always started.

What I am proposing, is to have an extensions array, in which I can add/remove file extensions accordingly, so watch mode reacts to changes on those file extensions or not.

distante avatar May 23 '22 10:05 distante

interesting idea. Right now each folder corresponds to one extension runtime, to change this assumption might not be trivial. However, this also enabled an easy workaround: by creating an "integration-tests" folder with proper config and settings, you can then have all the unit and integration tests running as expected.

Will that work?

connectdotz avatar May 31 '22 19:05 connectdotz

For the current folder structure (based on an nx project) that will not work.

For example, after create a new library we have an structure like this:

feature_root_folder 
  jest.config.ts
  jest.config.integration.ts
  ts.config.json
  project.json
  - src
       index.ts
       test_setup.ts
       - lib
           - module_1
                some_1.controller.ts
                some_1.service.ts
                some_1.spec.ts
                some_1.integration-spec.ts
           - module_2
                some_2.controller.ts
                some_2.service.ts
                some_2.spec.ts
                some_2.integration-spec.ts
           etc.

All those spec.ts and integration-spec.ts are controller by jest.config.js and jest.config.integration.js. And they read the preset from the monorepo root jest.preset.ts.

distante avatar Jun 01 '22 06:06 distante

BTW, I also am not able to run integration-tests from vscode. But I am not really sure if this depends on the extension or not.

distante avatar Jun 02 '22 08:06 distante

BTW, I also am not able to run integration-tests from vscode. But I am not really sure if this depends on the extension or not.

You need to first make sure you can run the integration test in the vscode terminal to verify its config is correct, this has no dependency on this extension.

Once the integration tests are working, you can add a folder to your vscode, and add 2 jest settings in the settings.json file there, something like this:

"jest.rootPath": "..",
"jest.jestCommandLine": "yarn integrationTest"

You might need to adjust the value of the settings accordingly. I think you should be able to run both tests without changing the rest of the project structure. Let me know if that works for you.

connectdotz avatar Jun 02 '22 18:06 connectdotz

I have to be honest, I am now sure what to put in the jestCommandLine for the new file.

The integration-spec.ts files are being run using the nx cli like:

nx run my-feature-project:test-integration --watch

distante avatar Jun 07 '22 12:06 distante

if nx run my-feature-project:test-integration --watch worked in the vscode terminal, you can then try adding the settings below in the integration-test folder:

"jest.rootPath": "..",
"jest.jestCommandLine": "nx run my-feature-project:test-integration"

let me know what you see.

connectdotz avatar Jun 07 '22 19:06 connectdotz

Sorry for the late reply, I could not make it work. Sorry.

distante avatar Jun 22 '22 12:06 distante