Raathigesh / majestic

⚡ Zero config GUI for Jest
MIT License
7.49k stars 173 forks source link

Customize run command #87

Open deraw opened 5 years ago

deraw commented 5 years ago

Feature Request

Hi! I've discovered this project and I love it, thank you for making it!

I was wondering if it's possible to specify a command to execute, or to make it work with vue-cli I'm using the command vue-cli-service test:unit, and my tests are passing, but with the GUI I suppose it runs Jest directly so it fails with:

import Vue from 'vue';
^^^

SyntaxError: Unexpected identifier

Thanks!

Raathigesh commented 5 years ago

Hey 👋 ,

I'm glad that you like the project.

Could you please add the following configuration to package.json and check?

"majestic": {
    "jestScriptPath": ".\\node_modules\\@vue\\cli-service\\bin\\vue-cli-service.js test:unit"
}
deraw commented 5 years ago

Thanks for your quick reply!

(I've had to replace \\ with /) It's using vu-cli-service now, but it seems it's without the config for jest (defined in the package.json)

If I run ./node_modules/@vue/cli-service/bin/vue-cli-service.js test:unit in the terminal the tests passes But in the GUI it says Jest encountered an unexpected token

(also I'm using TypeScript)

Raathigesh commented 5 years ago

I created a new project via the Vue CLI with Jest (Config in package.json) + typescript and I can run the project. So I'm not sure why your one is not working. If you could share a small repo with the issue, I can take a look into it.

image

deraw commented 5 years ago

You're right I've tried with another similar project and it worked like a charm! I'll try to see what's causing the error in the first project

deraw commented 5 years ago

I haven't touched anything, but now it works! Thank you :smile:

Raathigesh commented 5 years ago

Hey again 👋 ,

From Majestic 1.3 (Which I released just now) onwards the config needs to be as follows.

  "majestic": {
    "jestScriptPath": ".\\node_modules\\@vue\\cli-service\\bin\\vue-cli-service.js",
    "args": [
      "test:unit"
    ]
  }

Cheers!

deraw commented 5 years ago

Hi!

Thank you that's very kind of you!

I also love the coverage integration! :ok_hand:

mattwilson1024 commented 5 years ago

Forgive me if this is a stupid question, but does the jestScriptPath have to be a JS file to be executed with node, or can it be configured to execute a binary? To run things up with my setup I have to run ng test or yarn test, which will then compile the relevant jest config and run up jest, but I'm not sure how to configure majestic to work with that.

Raathigesh commented 5 years ago

It could be any binary but the binary that you provide should forward the args correctly to Jest at the end otherwise things won't work.

Would you be able to share whats in your yarn test script has so I could see how we can make it work?

There are no stupid questions :)

mattwilson1024 commented 5 years ago

Thanks @Raathigesh, any thoughts you have would be appreciated :)

My yarn test script actually doesn't do much, it just calls ng test.

I'm using @angular-builders/jest. My understanding is that it:

If I run this command in the terminal (from the project root folder), I see the test results all ok in the terminal: ng test myproject

I tried adding the following to my package.json and then running majestic: "majestic": { "jestScriptPath": "ng test myproject" }

but when it starts up I see this error in the (web browser) console: ui.bundle.js:42 TypeError: Cannot read property 'projectRoot' of undefined

Raathigesh commented 5 years ago

hey 👋 ,

I created a sample project and I was able to start majestic with the following config.

"majestic": {
    "jestScriptPath": ".\\node_modules\\@angular\\cli\\bin\\ng",
    "args": [
      "test"
    ]
  }

You can add more arguments to the args array like the project name.

Let me know if you run into issues.

pirhoo commented 5 years ago

Hey @Raathigesh, thanks for the amazing work!

I'm trying to make it work with vue-cli as well but it looks like it's just ignoring my jest.config.js file.

I use the following config:

{
  "majestic": {
    "jestScriptPath": "./node_modules/@vue/cli-service/bin/vue-cli-service.js",
    "env": {
      "TEST_MODE": "unit"
    },
    "args": [
      "test:unit",
      "--config=./jest.config.js",
      "--testPathPattern=/unit/",
      "--runInBand"
    ]
  }
}

And when I run majestic --debug I'm getting:

⚡  Majestic v1.4.1 is running at http://localhost:4000 
ℹ Majestic configuration from Package.json:  {                                                                                                                                                                      Config Resolver 16:22:54
  jestScriptPath: './node_modules/@vue/cli-service/bin/vue-cli-service.js',
  env: {
    TEST_MODE: 'unit'
  },
  args: [
    'test:unit',
    '--config=./jest.config.js',
    '--testPathPattern=/unit/',
    '--runInBand'
  ]
}
ℹ Resolved Majestic config : {                                                                                                                                                                                      Config Resolver 16:22:54
  jestScriptPath: '"/home/pirhoo/Repositories/datashare-client/node_modules/@vue/cli-service/bin/vue-cli-service.js"',
  args: [
    'test:unit',
    '--config=./jest.config.js',
    '--testPathPattern=/unit/',
    '--runInBand'
  ],
  env: {
    TEST_MODE: 'unit'
  }
}
ℹ Error occured while obtaining Jest cofiguration for coverage report  

Any clue?

Raathigesh commented 5 years ago

Hey @pirhoo,

It seems like there is something going on when obtaining coverage report path. Unfortunately, the error is not printed to the output but it should have been. I'll do a release with enhanced error logging so we could see what's going on and also fixed a few things around this area so thing might work as well.

I'll ping here after releasing the next version in a couple of days so you could check again.

pirhoo commented 5 years ago

Copy that, thanks @Raathigesh !

Raathigesh commented 5 years ago

Hi again @pirhoo 👋 ,

Released 1.5.0. Could you please try again.

pirhoo commented 5 years ago

Thanks for the doing this so quickly @Raathigesh!

The error is a little bit more explicit now:

ℹ Error occured while obtaining Jest cofiguration for coverage report SyntaxError: Unexpected token d in JSON at position 1

The Jest config is here and works well when executed with jest (thought vue-cli-service). The package.json is also valid.

Raathigesh commented 5 years ago

I checked out the repo and it looks like when I provide the --app flag, I see the error but without the --app flag, it works. Are you seeing the same behavior?

pirhoo commented 5 years ago

You're right, Majestic works well without the --app flag :dizzy_face:

Raathigesh commented 5 years ago

That doesn't add up. I'll have a look at it.

pirhoo commented 5 years ago

(in the meantime I'm using the --noOpen flag - it's great)

vladinator1000 commented 4 years ago

hey y'all, what if you have more than one test script, for example

{
  "scripts": {
    "test": "jest -c jest.config.unit.js",
    "itest": "jest -c jest.config.integration.js",
  }
}