Skip to content
Permalink
Browse files
feat(reporter): implement deterministic socket/port address derivation
  • Loading branch information
robertrossmann committed Mar 5, 2019
1 parent 9ff36ec commit 60643bf2a425f2804ef5ca4f3507824abaef00e4
Showing 5 changed files with 60 additions and 6 deletions.
@@ -1,6 +1,10 @@
'use strict'

module.exports = {
reporterOption: [
`root=${__dirname}`,
'nostats=1',
],
colors: true,
checkLeaks: true,
require: [
@@ -2,7 +2,7 @@

> Deliver Mocha progress events over Unix sockets/TCP connections to someplace else
This reporter allows Mocha to send its progress updates, which would normally appear on console, somewhere else - over Unix sockets or plain TCP connections. This is useful if you need Mocha to "contact" some independent process and feed it with progress, like [ide-mocha][ide-mocha] for Atom, but the use cases are not limited to that.
This reporter allows Mocha to send its progress updates, which would normally appear on console, somewhere else - over Unix sockets or plain TCP connections. This is useful if you need Mocha to "contact" some independent process and feed it with progress, like [IDE-Mocha][ide-mocha] for Atom, but the use cases are not limited to that.

## Usage

@@ -24,6 +24,41 @@ npx mocha --reporter mocha-reporter-remote --reporter-options address=12345

> The socket or TCP server must exist before the reporter starts. The receiving end should likely be permanently listening for data regardless of whether or not Mocha is actually being run. ⚠️
## Reporter options

The following options are accepted by this reporter:

- `root`: Specifies the root directory where Mocha is being run. This is useful for auto-detecting the socket or port of the remote listener.
- `mode`: Specifies the networking mode to be used. Allowed values are `unix` for Unix sockets, `ip` / `IP` for TCP. Default: `unix`.
- `address`: Either TCP port number of the absolute path to the unix socket to which to send events. Only used if `root` is not provided. ⚠️
- `nostats`: When set to `1` or any "truthy" value, Mocha will not print the final test stats to the console when it is done running. Default: `0`.

Reporter options can be provided on the command line or via _.mocharc.js_ or similar mechanism.

**Command line**:

```sh
# Using address
mocha --reporter mocha-reporter-remote --reporter-options address=/path/to/socket.sock,nostats=1
# using root
mocha --reporter mocha-reporter-remote --reporter-options root=${PWD},nostats=1
```

**_mocharc.js_**:

```js
module.exports = {
reporter: 'mocha-reporter-remote',
// This has to be singular, `reporterOptions` does not seem to
// parse the options correctly
reporterOption: [
'address=/path/to/socket.sock',
'nostats=1'
]
// ... other Mocha options
}
```

## Receiving events

@TODO 😢

Some generated files are not rendered by default. Learn more.

@@ -6,11 +6,15 @@
"bugs": "https://github.com/Dreamscapes/atom-ide-mocha-core/issues",
"contributors": [],
"dependencies": {
"remote-event-emitter": "^1.2.0"
"remote-event-emitter": "^1.2.0",
"@atom-ide/utils": "^1.0.0"
},
"devDependencies": {
"mocha": "^5.0.0"
},
"bundledDependencies": [
"@atom-ide/utils"
],
"engines": {
"node": "^10"
},
@@ -1,5 +1,6 @@
import * as Mocha from 'mocha'
import { Provider } from 'remote-event-emitter'
import { mkaddress } from '@atom-ide/utils'
import serialisers from './serialisers'

/**
@@ -55,6 +56,8 @@ class RemoteReporter extends Mocha.reporters.Base {
* @param {Object} opts Options object
* @param {Object} opts.reporterOptions Reporter options, as provided by Mocha
* @param {String} opts.reporterOptions.address Address to send the events to
* @param {String} opts.reporterOptions.root Root directory of the project
* @param {String} opts.reporterOptions.mode Networking mode. either `unix` or `ip`.
* @param {Boolean} opts.reporterOptions.nostats If set to a truthy value, the reporter will
* not print the final suite stats to stdout
*/
@@ -63,6 +66,14 @@ class RemoteReporter extends Mocha.reporters.Base {

this.#runner = runner
this.#options = options

if (this.#options.root) {
this.#options.address = mkaddress({
root: this.#options.root,
mode: this.#options.mode || 'unix',
})
}

// Initialise the remote event emitter provider
this.#provider = new Provider({ destination: options.address })

0 comments on commit 60643bf

Please sign in to comment.