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

feat: introduce __mocha_worker_id__ property #4922

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var Runnable = require('./runnable');
const {inherits, constants} = require('./utils');
const {MOCHA_ID_PROP_NAME} = constants;
const {MOCHA_ID_PROP_NAME, MOCHA_WORKER_ID_PROP_NAME} = constants;

/**
* Expose `Hook`.
Expand Down Expand Up @@ -84,6 +84,7 @@ Hook.prototype.serialize = function serialize() {
state: this.state,
title: this.title,
type: this.type,
[MOCHA_ID_PROP_NAME]: this.id
[MOCHA_ID_PROP_NAME]: this.id,
[MOCHA_WORKER_ID_PROP_NAME]: process.env.MOCHA_WORKER_ID
};
};
5 changes: 3 additions & 2 deletions lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const debug = require('debug')('mocha:suite');
const milliseconds = require('ms');
const errors = require('./errors');

const {MOCHA_ID_PROP_NAME} = utilsConstants;
const {MOCHA_ID_PROP_NAME, MOCHA_WORKER_ID_PROP_NAME} = utilsConstants;

/**
* Expose `Suite`.
Expand Down Expand Up @@ -586,8 +586,9 @@ Suite.prototype.serialize = function serialize() {
$$isPending: Boolean(this.isPending()),
root: this.root,
title: this.title,
parent: this.parent ? {[MOCHA_ID_PROP_NAME]: this.parent.id} : null,
[MOCHA_ID_PROP_NAME]: this.id,
parent: this.parent ? {[MOCHA_ID_PROP_NAME]: this.parent.id} : null
[MOCHA_WORKER_ID_PROP_NAME]: process.env.MOCHA_WORKER_ID
};
};

Expand Down
5 changes: 3 additions & 2 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var errors = require('./errors');
var createInvalidArgumentTypeError = errors.createInvalidArgumentTypeError;
var isString = utils.isString;

const {MOCHA_ID_PROP_NAME} = utils.constants;
const {MOCHA_ID_PROP_NAME, MOCHA_WORKER_ID_PROP_NAME} = utils.constants;

module.exports = Test;

Expand Down Expand Up @@ -108,6 +108,7 @@ Test.prototype.serialize = function serialize() {
title: this.title,
type: this.type,
file: this.file,
[MOCHA_ID_PROP_NAME]: this.id
[MOCHA_ID_PROP_NAME]: this.id,
[MOCHA_WORKER_ID_PROP_NAME]: process.env.MOCHA_WORKER_ID
};
};
5 changes: 4 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var he = require('he');

const MOCHA_ID_PROP_NAME = '__mocha_id__';

const MOCHA_WORKER_ID_PROP_NAME = '__mocha_worker_id__';

/**
* Inherit the prototype methods from one constructor into another.
*
Expand Down Expand Up @@ -612,7 +614,8 @@ exports.castArray = function castArray(value) {
};

exports.constants = exports.defineConstants({
MOCHA_ID_PROP_NAME
MOCHA_ID_PROP_NAME,
MOCHA_WORKER_ID_PROP_NAME
});

/**
Expand Down