Skip to content
This repository was archived by the owner on Feb 18, 2024. It is now read-only.

--watch isn't being handled by the mocha preset #736

Closed
armenzg opened this issue Mar 7, 2018 · 6 comments
Closed

--watch isn't being handled by the mocha preset #736

armenzg opened this issue Mar 7, 2018 · 6 comments
Labels

Comments

@armenzg
Copy link

armenzg commented Mar 7, 2018

I'm currently using "./node_modules/mocha/bin/mocha ./test//*.test.js --watch" instead of "neutrino test ./test//*.test.js --watch".

Preset referred:
https://github.com/mozilla-neutrino/neutrino-dev/blob/master/packages/mocha/src/mocha.js

@edmorley
Copy link
Member

Hi!

The --watch option is recognised by neutrino test, which passes it down to whatever registered the test command. For the karma preset this is then passed onto the test runner like so:
https://github.com/mozilla-neutrino/neutrino-dev/blob/8b03d8bd21b707f711ea6931f30c8016513e34db/packages/karma/index.js#L55-L60

Would you be up for making a similar change to the mocha preset? :-)
https://github.com/mozilla-neutrino/neutrino-dev/blob/8b03d8bd21b707f711ea6931f30c8016513e34db/packages/mocha/src/index.js#L7

@edmorley edmorley added the bug label Mar 10, 2018
@armenzg
Copy link
Author

armenzg commented Mar 12, 2018

I've managed to see this move forward, however, mocha runs once and then it runs once more (upon file changes) with 0 passing tests [1]

Further file changes do not change the output. The script seems to always be watching.

[1]

getChromePopular
✓ should return an array (10111ms)

11 passing (17s)

0 passing (0ms)

The mocha code being reached is this:
https://github.com/mochajs/mocha/blob/50aec7a249c7b2a28e2fdc18058829f48e6ee6d6/bin/_mocha#L523-L577

@armenzg
Copy link
Author

armenzg commented Mar 12, 2018

Here's the neutrino-dev changes:
master...armenzg:watch

The project I'm trying to make watching work for is:
https://github.com/mozilla/firefox-health-backend

The "watch:test" script requires changing "mocha" for "neutrino test"
https://github.com/mozilla/firefox-health-backend/blob/master/package.json#L8

eliperelman added a commit that referenced this issue May 23, 2018
… tools (#852)

__Edited to reflect current state of PR.__

Fixes #708.
Fixes #736.
Fixes #870.
Fixes #842.
Closes #773.
Closes #839.
Closes #849.

Outstanding issues to file:

- [x] Update docs to reflect these API changes (#896)
- [x] ~~Determine need for config-loading bins instead of forcing config file boilerplate (still unsure if we should do this because of IDE integration)~~
- [x] Modify stats to produce friendlier build output (#897)

This patch is a work-in-progress, and is quite the overhaul of Neutrino into something different. Right now there is no change to the documentation, which I will change if we decide to move forward with this.

This patch morphs Neutrino into a "preset engine" for transforming managed webpack configuration into a format that can be consumed by other CLI tools. No longer would we wrap external CLI tools like webpack, eslint, jest, karma, mocha, stylelint, etc. Instead, Neutrino could augment these tools by exposing methods for returning usable configuration.

This approach gives the user control of their CLI tool back, and they can programmatically invoke Neutrino to load their configuration, and override however they like:

```bash
webpack --mode production
```

```js
// webpack.config.js
const neutrino = require('neutrino');

// Load with no config overrides:
module.exports = neutrino().webpack();

// Load with config overrides:
module.exports = neutrino().webpack(config => {
  // return whatever config you want
});

// Load with no config overrides using low-level API:
module.exports = neutrino().output('webpack');

// Load with config overrides using low-level API:
module.exports = neutrino().output('webpack', config => {
  // return whatever config you want
});
```

The same works for ESLint and friends too (except for mocha, since it has no config file we can be required from):

```bash
eslint src
```

```js
// .eslintrc.js
const neutrino = require('neutrino');

// Load with no config overrides:
module.exports = neutrino().eslintrc();

// Load with config overrides:
module.exports = neutrino().eslintrc(config => {
  // return whatever config you want, like manipulating rules, etc.
});
```

---

- This approach is predicated on having middleware defined in `.neutrinorc.js`, which shouldn't change at all.
- ~~This does do away with a bunch of CLI functionality like `--inspect` or `--use`, but those become less useful if we are just an interface to external CLI tools. We can discuss potentially bringing those back.~~ This is now back in the form of the CLI with `neutrino --inspect`.
- ~~All environment variables are gone. We rely only on webpack's `mode` value.~~ We internally only use webpack's `mode` value, but still set `process.env.NODE_ENV` if not set based on the mode, or defaulted to `production`.
- ~~There is no longer a create-project tool, since we cannot force users to choose between competing tools like webpack-cli or webpack-command, and webpack-dev-server or webpack-serve.~~ The create-project tool is back, and we opt for `webpack-cli` and `webpack-dev-server` as opinions for now.

I'm sure there are other major things I am neglecting to mention. Let's discuss! I see so many benefits to this, including reduced maintenance burden and the ability to allow people to use Neutrino without dumping their existing tools.

cc: @mozilla-neutrino/core-contributors
@markshust
Copy link

i believe this issue should be reopened, --watch isn't working with mocha for me. the tests just run once and stop as if --watch isn't even being seen.

@edmorley
Copy link
Member

Hi! The PR that closed this issue is just on master and not the release/v8 branch - so not present in Neutrino 8. We'll be releasing Neutrino 9 shortly which will include it :-)

@markshust
Copy link

I didn't know there was a new version of Neutrino coming out.... sounds great! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants