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

Add "env" config to package.json #371

Closed
gsklee opened this Issue Jan 6, 2016 · 16 comments

Comments

5 participants
@gsklee
Copy link
Contributor

commented Jan 6, 2016

As a continuation of #18, can we add this?

{
  "standard": {
    "env": "mocha"
  }
}

IMHO it's better than either adding /* eslint-env mocha */ to all test files, or adding:

{
  "standard": {
    "globals": ["beforeEach", "describe", "it", ...]
  }
}

@gsklee gsklee changed the title Add Add "env" confit to package.json Jan 6, 2016

@gsklee gsklee changed the title Add "env" confit to package.json Add "env" config to package.json Jan 6, 2016

@dcousens

This comment has been minimized.

Copy link
Member

commented Jan 6, 2016

IMHO, if /* eslint-env mocha */ is a thing, than this is exactly what should be added to all test files.
I don't think blanket application of a mocha env to an entire project is acceptable, though this could be different for other environments.

@rstacruz

This comment has been minimized.

Copy link
Member

commented Jan 7, 2016

bad, mocha. one of the reasons I don't use mocha anymore. :p

@dmitriz

This comment has been minimized.

Copy link

commented Jan 15, 2016

@rstacruz What is better than mocha?

@rstacruz

This comment has been minimized.

Copy link
Member

commented Jan 15, 2016

I personally prefer tape, but that's just me.

Anyway, IMHO this is most certainly doable. Eslint itself has support for environments defined here: http://eslint.org/docs/user-guide/configuring#specifying-environments. These look particularly useful:

  • browser
  • worker
  • mocha
  • ...
@rstacruz

This comment has been minimized.

Copy link
Member

commented Jan 15, 2016

Also, @feross, this might be worth documenting:

/* eslint-env mocha */

...will consider describe/it/beforeEach/etc as predefined globals.

@dcousens

This comment has been minimized.

Copy link
Member

commented Jan 15, 2016

I guess if it is basically just a direct pass-through for a common eslint feature, then I'm not against it.

@dcousens

This comment has been minimized.

Copy link
Member

commented Jan 15, 2016

Though, IMHO /* eslint-env mocha */ (aka, per-file configuration) is a better pattern than package.json defined configuration.

Make the lame things hard, and the bad things impossible

@rstacruz

This comment has been minimized.

Copy link
Member

commented Jan 15, 2016

yes, i agree. there's also the possibility of this:

{
  "scripts": {
    "lint": "standard 'lib/*.js'; standard 'test/**/*.js' --env mocha"
  }
}
@dcousens

This comment has been minimized.

Copy link
Member

commented Jan 15, 2016

@rstacruz that I would agree with a lot more than the blanket suggestion.

@dmitriz

This comment has been minimized.

Copy link

commented Jan 15, 2016

@rstacruz Seems like they require to write this in every single test file:

You always need to require('tape') in test files.

Grows old very fast, imo.

@rstacruz

This comment has been minimized.

Copy link
Member

commented Jan 15, 2016

@dmitriz: i know this is off tangent in the conversation now, but that's precisely why I like it. It means you have write your test files in idiomatic JavaScript—no fancy test runners. In practice, it means your tests are runnable on their own (node test/foo.js), and perfectly browserifyable (browserify test/index.js). This opens up the opportunity to do a lot of interesting things:

node test.js     # run in node.js
hihat test.js    # run in electron (hihat is browserify-aware)
budo test.js     # run in browser (budo is, too)
browserify test.js | smokestack -b firefox  # run in headless browser
@dmitriz

This comment has been minimized.

Copy link

commented Jan 15, 2016

@rstacruz I see, interesting, have you seen ava - that looks similar!

@gsklee

This comment has been minimized.

Copy link
Contributor Author

commented Jan 18, 2016

@rstacruz Interesting info ;-)

@feross

This comment has been minimized.

Copy link
Member

commented Feb 4, 2016

@rstacruz +1 to tape and being unfancy and explicit.

It's not worth saving one line if you break compatibility with everything. All tooling has to add custom support for mocha and know about the exact list of globals that mocha assumes. Not a good tradeoff.

@feross

This comment has been minimized.

Copy link
Member

commented Feb 4, 2016

That said, we'll support passing through this option to eslint, like we've done for the other options.

feross added a commit to standard/standard-engine that referenced this issue Feb 4, 2016

Add --env option
So users can specify custom rules.

Works in `package.json`:

```json
{
"standard": {
"env": {
"mocha": true
}
}
}
```

And the command line:

```
standard --env mocha test/*.js
```

For users that need to change the environment across their entire
project, or just for their tests (e.g. with mocha).

Fixes standard/standard#371

@feross feross referenced this issue Feb 4, 2016

Merged

Add --env option #58

@feross

This comment has been minimized.

Copy link
Member

commented Feb 4, 2016

PR to standard-engine to add support for the --env option: standard/standard-engine#58

Works in package.json:

{
  "standard": {
    "env": {
      "mocha": true
    }
  }
}

And the command line:

standard --env mocha test/*.js

This will be released in standard v6.

@feross feross added the enhancement label May 10, 2018

@lock lock bot locked as resolved and limited conversation to collaborators Aug 8, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.