-
Notifications
You must be signed in to change notification settings - Fork 121
Closed
Labels
Description
Description
Mocha now ignores the test files supplied after "--", required to allow consumers to safely generate the command line arguments and avoid conflicts between test files and CLI options.
Steps to Reproduce
Setup
$ PROJECT="/var/tmp/ypdbldash"
$ mkdir ${PROJECT}
$ cd ${PROJECT}
$ mkdir test
$ touch index.js
$ cat << EOF >> "package.json"
{
"name": "ypdbldash",
"version": "1.0.0",
"description": "Test end-of-options (double-dash) argument placement",
"main": "index.js",
"directories": {
"test": "./test"
},
"scripts": {
"test": "mocha"
},
"devDependencies": {
"mocha": "latest",
"unexpected": "latest",
"yargs-parser": "latest"
},
"engines": {
"node": ">=6"
},
"keywords": [
"argv",
"double-dash"
],
"author": "P. Roebuck <plroebuck@users.noreply.github.com>",
"license": "CC0-1.0"
}
EOF
$ cat << EOF >> "test/3899.spec.js"
'use strict';
const expect = require('unexpected');
const yargsParser = require('yargs-parser');
describe('mochajs/mocha#3899', function() {
const filename = 'somefile';
const args = [
'--',
filename
];
context('when given empty config', () => {
let result;
const configuration = {};
before(function() {
//console.log('configuration:', configuration);
result = yargsParser.detailed(args, {configuration});
//console.log(result);
});
it('should not error', () => {
expect(result.error, 'to be null');
});
it('should not create a "-" alias', () => {
expect(result.newAliases, 'to be empty');
});
it('should not populate "-" with positional arg', () => {
expect(result.argv, 'not to have key', '-');
});
it('should populate "_" with positional arg', () => {
expect(result.argv['_'], 'to equal', [ filename ]);
});
});
context("when given config with 'short-option-groups' false", () => {
let result;
const configuration = {
'short-option-groups': false
};
before(function() {
//console.log('configuration:', configuration);
result = yargsParser.detailed(args, {configuration});
//console.log(result);
});
it('should denote use of input configuration settings', () => {
expect(result.configuration, 'to satisfy', {
...configuration
});
});
it('should not error', () => {
expect(result.error, 'to be null');
});
it('should not create a "-" alias', () => {
expect(result.newAliases, 'to be empty');
});
it('should not populate "-" with positional arg', () => {
expect(result.argv, 'not to have key', '-');
});
it('should populate "_" with positional arg', () => {
expect(result.argv['_'], 'to equal', [ filename ]);
});
});
context("when given config with both 'short-option-groups' and 'camel-case-expansion' false", () => {
let result;
const configuration = {
'camel-case-expansion': false,
'short-option-groups': false
};
before(function() {
//console.log('configuration:', configuration);
result = yargsParser.detailed(args, { configuration });
//console.log(result);
});
it('should denote use of input configuration settings', () => {
expect(result.configuration, 'to satisfy', {
...configuration
});
});
it('should not error', () => {
expect(result.error, 'to be null');
});
it('should not create a "-" alias', () => {
expect(result.newAliases, 'to be empty');
});
it('should not populate "-" with positional arg', () => {
expect(result.argv, 'not to have key', '-');
});
it('should populate "_" with positional arg', () => {
expect(result.argv['_'], 'to equal', [ filename ]);
});
});
});
EOF
$ npm installTest
$ npm testExpected behavior: All tests should complete without errors.
Actual behavior: Multiple tests fail in the provided Mocha specification file.
Versions
- Node: v10.15.0
- OS: macOS 10.13.6
- Shell: bash
Above provided for my testing, but issue unlikely to be platform-specific.
Additional Information
Bug exists in "yargs-parser" v11.1.1 (Mocha's pinned version), but persists in current version.
Upstream: mochajs/mocha#3899