Skip to content

Commit

Permalink
Switch to jsspec for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HookyQR committed Jul 11, 2019
1 parent 597bba5 commit c83a8c1
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 204 deletions.
135 changes: 33 additions & 102 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@jsspec/cli-options",
"version": "0.0.5",
"version": "0.0.6",
"description": "Command line option parser",
"main": "lib/options.js",
"scripts": {
"test": "c8 mocha test --recursive -r chai/register-expect"
"test": "c8 jsspec -r chai/register-expect -- test/options.test.js test/parser.test.js"
},
"repository": {
"type": "git",
Expand All @@ -24,7 +24,7 @@
},
"homepage": "https://github.com/JSSpec/cli-options#readme",
"devDependencies": {
"mocha": "~5.2.0",
"@jsspec/jsspec": "*",
"chai": "4.2.0",
"c8": "^4.1.5"
},
Expand Down
22 changes: 22 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"env": {
"es6": true,
"node": true,
"jsspec/jsspec": true
},

"plugins": ["jsspec"],

"extends": "eslint:recommended",
"overrides": [{
"files": ["*.test.js"],
"globals": { "expect": false }
}],
"rules": {
"indent": ["error", 2, { "SwitchCase": 1 }],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"no-console": "off"
}
}
90 changes: 49 additions & 41 deletions test/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,78 @@
const Option = require('../lib/options');

describe('Option', () => {
subject('option', () => new Option(args, options, 'files'));

let options = {
random: { alias: 'R', type: Boolean, required: false, default: true },
require: { alias: 'r', type: Array, required: false, default: [] },
format: { alias: 'f', type: String, required: false, default: 'documentation', },
files: { type: Array, required: false, default: [] }
};

it('picks up a simple arg set correctly', () => {
let args = '-r ./some/file ./some/otherFile -fd run/this/test and/this/one'.split(' ');
let option = new Option(args, options, 'files');
context('with a simple arg set', () => {
set('args', '-r ./some/file ./some/otherFile -fd run/this/test and/this/one'.split(' '));

expect(option.settings).to.deep.include({
random: true,
require: ['./some/file', './some/otherFile'],
format: 'd',
files: ['run/this/test', 'and/this/one']
it('picks up a simple arg set correctly', () => {
expect(option.settings).to.deep.include({
random: true,
require: ['./some/file', './some/otherFile'],
format: 'd',
files: ['run/this/test', 'and/this/one']
});
});
});

it('picks up a both parts of an array correctly', () => {
let args = '--require=./some/file ./some/otherFile -fd run/this/test and/this/one'.split(' ');
let option = new Option(args, options, 'files');
context('with multiple values to an array setting', () => {
set('args', '--require=./some/file ./some/otherFile -fd run/this/test and/this/one'.split(' '));

expect(option.settings).to.deep.include({
random: true,
require: ['./some/file', './some/otherFile'],
format: 'd',
files: ['run/this/test', 'and/this/one']
it('picks up a both parts of an array correctly', () => {
expect(option.settings).to.deep.include({
random: true,
require: ['./some/file', './some/otherFile'],
format: 'd',
files: ['run/this/test', 'and/this/one']
});
});
});

it('bails from an array setting with `--`', () => {
let args = '--require=./some/file ./some/otherFile -- run/this/test and/this/one'.split(' ');
let option = new Option(args, options, 'files');
describe('bailing from an array setting', () => {
context('using `--`', () => {
set('args', '--require=./some/file ./some/otherFile -- run/this/test and/this/one'.split(' '));

it('bails from an array setting with `--`', () => {
expect(option.settings).to.deep.include({
random: true,
require: ['./some/file', './some/otherFile'],
files: ['run/this/test', 'and/this/one']
});

console.log(option.settings);
expect(option.settings).to.deep.include({
random: true,
require: ['./some/file', './some/otherFile'],
files: ['run/this/test', 'and/this/one']
expect(options.errors).to.be.undefined;
});
});

expect(options.errors).to.be.undefined;
});
context('using the full default flag', () => {
set('args', '--require=./some/file ./some/otherFile --files run/this/test and/this/one'.split(' '));
it('bails from an array setting with the full default flag', () => {

it('bails from an array setting with the full default flag', () => {
let args = '--require=./some/file ./some/otherFile --files run/this/test and/this/one'.split(' ');
let option = new Option(args, options, 'files');
expect(option.settings).to.deep.include({
random: true,
require: ['./some/file', './some/otherFile'],
files: ['run/this/test', 'and/this/one']
});

expect(option.settings).to.deep.include({
random: true,
require: ['./some/file', './some/otherFile'],
files: ['run/this/test', 'and/this/one']
expect(options.errors).to.be.undefined;
});
});

expect(options.errors).to.be.undefined;
});

it('fails on an unknown and toggles flags', () => {
let args = '--youDontKnowMe -RR'.split(' ');
let option = new Option(args, options, 'files');
context('unknown flags', () => {
set('args', '--youDontKnowMe -RR'.split(' '));

expect(option.settings).to.deep.include({ random: false });
expect(option.errors).to.have.length(1);
expect(option.errors[0]).to.match(/unknown argument 'youDontKnowMe'/);
it('fails on an unknown and toggles flags', () => {
expect(option.settings).to.deep.include({ random: false });
expect(option.errors).to.have.length(1);
expect(option.errors[0]).to.match(/unknown argument 'youDontKnowMe'/);
});
});
});
Loading

0 comments on commit c83a8c1

Please sign in to comment.