Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
feat(reporter): implement deterministic socket/port address derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrossmann committed Mar 5, 2019
1 parent 9ff36ec commit 60643bf
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .mocharc.js
@@ -1,6 +1,10 @@
'use strict'

module.exports = {
reporterOption: [
`root=${__dirname}`,
'nostats=1',
],
colors: true,
checkLeaks: true,
require: [
Expand Down
37 changes: 36 additions & 1 deletion packages/mocha-reporter-remote/README.md
Expand Up @@ -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

Expand All @@ -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 😢
Expand Down
8 changes: 4 additions & 4 deletions packages/mocha-reporter-remote/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion packages/mocha-reporter-remote/package.json
Expand Up @@ -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"
},
Expand Down
11 changes: 11 additions & 0 deletions packages/mocha-reporter-remote/src/reporter.mjs
@@ -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'

/**
Expand Down Expand Up @@ -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
*/
Expand All @@ -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 })

Expand Down

0 comments on commit 60643bf

Please sign in to comment.