options.conflicts.test.js
This file
Path
tests/options.conflicts.test.js
395 lines · 11.7 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
The walk stopped after 200 commits: lines older than 471ec40 point at it.
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 1–5why, one step back1import * as path from 'path';2import * as commander from '../index.js';3import { createTestCommand } from './testHelpers.js';4import { test, describe } from 'node:test';5import assert from 'node:assert/strict';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 6why, one step back6Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 7why, one step back7describe('Option.conflicts()', () => {Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 8–10why, one step back8 function makeProgram(t) {9 const actionMock = t.mock.fn();10 const program = createTestCommand();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 11–13why, one step back11 program12 .command('foo')13 .addOption(Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 14–16why, one step back14 new commander.Option('-s, --silent', "Don't print anything").env(15 'SILENT',16 ),Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 17why, one step back17 )Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 18–22why, one step back18 .addOption(19 new commander.Option('-j, --json', 'Format output as json')20 .env('JSON')21 .conflicts(['silent']),22 )Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 23–27why, one step back23 .action(actionMock);2425 return { program, actionMock };26 }27Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 28why, one step back28 test.beforeEach(() => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 29–34why, one step back29 delete process.env.SILENT;30 delete process.env.JSON;31 delete process.env.DUAL;32 delete process.env.NO_DUAL;33 });34Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 35–36why, one step back35 test('should call action if there are no explicit conflicting options set', (t) => {36 const { program, actionMock } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 37why, one step back37 program.parse('node test.js foo --json'.split(' '));Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 38–40why, one step back38 assert.equal(actionMock.mock.callCount(), 1);39 const callArgs = actionMock.mock.calls[0].arguments;40 assert.deepEqual(callArgs[0], { json: true });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 41–42why, one step back41 });42Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 43–44why, one step back43 test('should call action when there are no implicit conflicting options set', (t) => {44 const { program, actionMock } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 45why, one step back45 program.parse('node test.js foo --silent'.split(' '));Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 46–48why, one step back46 assert.equal(actionMock.mock.callCount(), 1);47 const callArgs = actionMock.mock.calls[0].arguments;48 assert.deepEqual(callArgs[0], { silent: true });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 49–50why, one step back49 });50Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 51–52why, one step back51 test('should exit with error if conflicting options were set', (t) => {52 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 53why, one step back53Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 54–61why, one step back54 assert.throws(55 () => {56 program.parse('node test.js foo --silent --json'.split(' '));57 },58 {59 message:60 "error: option '-j, --json' cannot be used with option '-s, --silent'",61 },Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 62why, one step back62 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 63–64why, one step back63 });64Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 65–66why, one step back65 test('should report the env variable as the conflicting option source, when conflicting option is set', (t) => {66 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 67–69why, one step back6768 process.env.SILENT = true;69Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 70–77why, one step back70 assert.throws(71 () => {72 program.parse('node test.js foo --json'.split(' '));73 },74 {75 message:76 "error: option '-j, --json' cannot be used with environment variable 'SILENT'",77 },Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 78why, one step back78 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 79–80why, one step back79 });80Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 81–82why, one step back81 test('should report the env variable as the configured option source, when configured option is set', (t) => {82 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 83–85why, one step back8384 process.env.JSON = true;85Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 86–93why, one step back86 assert.throws(87 () => {88 program.parse('node test.js foo --silent'.split(' '));89 },90 {91 message:92 "error: environment variable 'JSON' cannot be used with option '-s, --silent'",93 },Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 94why, one step back94 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 95–96why, one step back95 });96Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 97–98why, one step back97 test('should report both env variables as sources, when configured option and conflicting option are set', (t) => {98 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 99–102why, one step back99100 process.env.SILENT = true;101 process.env.JSON = true;102Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 103–110why, one step back103 assert.throws(104 () => {105 program.parse('node test.js foo'.split(' '));106 },107 {108 message:109 "error: environment variable 'JSON' cannot be used with environment variable 'SILENT'",110 },Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 111why, one step back111 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 112–113why, one step back112 });113Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 114–115why, one step back114 test('should allow default value with a conflicting option', (t) => {115 const { program, actionMock } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 116why, one step back116Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 117–121why, one step back117 program.commands[0].addOption(118 new commander.Option('-d, --debug', 'print debug logs')119 .default(true)120 .conflicts(['silent']),121 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 122–124why, one step back122123 program.parse('node test.js foo --silent'.split(' '));124Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 125–127why, one step back125 assert.equal(actionMock.mock.callCount(), 1);126 const callArgs = actionMock.mock.calls[0].arguments;127 assert.deepEqual(callArgs[0], { debug: true, silent: true });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 128–129why, one step back128 });129Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 130–131why, one step back130 test('should report conflict on negated option flag', (t) => {131 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 132–138why, one step back132133 program134 .command('bar')135 .addOption(new commander.Option('--red').conflicts(['color']))136 .addOption(new commander.Option('--color'))137 .addOption(new commander.Option('-N, --no-color'));138Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 139–146why, one step back139 assert.throws(140 () => {141 program.parse('node test.js bar --red -N'.split(' '));142 },143 {144 message:145 "error: option '--red' cannot be used with option '-N, --no-color'",146 },Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 147why, one step back147 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 148–149why, one step back148 });149Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 150–151why, one step back150 test('should report conflict on negated option env variable', (t) => {151 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 152–160why, one step back152153 process.env.NO_COLOR = true;154155 program156 .command('bar')157 .addOption(new commander.Option('--red').conflicts(['color']))158 .addOption(new commander.Option('--color'))159 .addOption(new commander.Option('-N, --no-color').env('NO_COLOR'));160Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 161–168why, one step back161 assert.throws(162 () => {163 program.parse('node test.js bar --red'.split(' '));164 },165 {166 message:167 "error: option '--red' cannot be used with environment variable 'NO_COLOR'",168 },Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 169why, one step back169 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 170–171why, one step back170 });171Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 172–173why, one step back172 test('should report correct error for shorthand negated option', (t) => {173 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 174–179why, one step back174175 program176 .command('bar')177 .addOption(new commander.Option('--red'))178 .addOption(new commander.Option('-N, --no-color').conflicts(['red']));179Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 180–187why, one step back180 assert.throws(181 () => {182 program.parse('node test.js bar --red -N'.split(' '));183 },184 {185 message:186 "error: option '-N, --no-color' cannot be used with option '--red'",187 },Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 188why, one step back188 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 189–190why, one step back189 });190Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 191–192why, one step back191 test('should report correct error for positive option when negated is configured', (t) => {192 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 193–199why, one step back193194 program195 .command('bar')196 .addOption(new commander.Option('--red'))197 .addOption(new commander.Option('--dual').env('DUAL').conflicts(['red']))198 .addOption(new commander.Option('--no-dual').env('NO_DUAL'));199Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 200–205why, one step back200 assert.throws(201 () => {202 program.parse('node test.js bar --red --dual'.split(' '));203 },204 { message: "error: option '--dual' cannot be used with option '--red'" },205 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 206–207why, one step back206 });207Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 208–209why, one step back208 test('should report correct error for negated option when positive is configured', (t) => {209 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 210–216why, one step back210211 program212 .command('bar')213 .addOption(new commander.Option('--red'))214 .addOption(new commander.Option('--dual').env('DUAL').conflicts(['red']))215 .addOption(new commander.Option('--no-dual').env('NO_DUAL'));216Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 217–224why, one step back217 assert.throws(218 () => {219 program.parse('node test.js bar --red --no-dual'.split(' '));220 },221 {222 message: "error: option '--no-dual' cannot be used with option '--red'",223 },224 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 225–226why, one step back225 });226Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 227–228why, one step back227 test('should report correct error for positive env variable when negated is configured', (t) => {228 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 229–236why, one step back229230 program231 .command('bar')232 .addOption(new commander.Option('--red'))233 .addOption(new commander.Option('--dual').env('DUAL').conflicts(['red']))234 .addOption(new commander.Option('--no-dual').env('NO_DUAL'));235236 process.env.DUAL = 'true';Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 237–244why, one step back237 assert.throws(238 () => {239 program.parse('node test.js bar --red'.split(' '));240 },241 {242 message:243 "error: environment variable 'DUAL' cannot be used with option '--red'",244 },Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 245why, one step back245 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 246–247why, one step back246 });247Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 248–249why, one step back248 test('should report correct error for negated env variable when positive is configured', (t) => {249 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 250–257why, one step back250251 program252 .command('bar')253 .addOption(new commander.Option('--red'))254 .addOption(new commander.Option('--dual').env('DUAL').conflicts(['red']))255 .addOption(new commander.Option('--no-dual').env('NO_DUAL'));256257 process.env.NO_DUAL = 'true';Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 258–265why, one step back258 assert.throws(259 () => {260 program.parse('node test.js bar --red'.split(' '));261 },262 {263 message:264 "error: environment variable 'NO_DUAL' cannot be used with option '--red'",265 },Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 266why, one step back266 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 267–268why, one step back267 });268Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 269–270why, one step back269 test('should report correct error for positive option with string value when negated is configured', (t) => {270 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 271–277why, one step back271272 program273 .command('bar')274 .addOption(new commander.Option('--red'))275 .addOption(new commander.Option('--dual2 <str>').conflicts(['red']))276 .addOption(new commander.Option('--no-dual2').preset('BAD'));277Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 278–285why, one step back278 assert.throws(279 () => {280 program.parse('node test.js bar --red --dual2 foo'.split(' '));281 },282 {283 message:284 "error: option '--dual2 <str>' cannot be used with option '--red'",285 },Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 286why, one step back286 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 287–288why, one step back287 });288Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 289–290why, one step back289 test('should report correct error for negated option with preset when negated is configured', (t) => {290 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 291–297why, one step back291292 program293 .command('bar')294 .addOption(new commander.Option('--red'))295 .addOption(new commander.Option('--dual2 <str>').conflicts(['red']))296 .addOption(new commander.Option('--no-dual2').preset('BAD'));297Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 298–306why, one step back298 assert.throws(299 () => {300 program.parse('node test.js bar --red --no-dual2'.split(' '));301 },302 {303 message:304 "error: option '--no-dual2' cannot be used with option '--red'",305 },306 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 307–308why, one step back307 });308Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 309–310why, one step back309 test('should not throw error when conflicts is invoked with a single string that includes another option', (t) => {310 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 311why, one step back311Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 312why, one step back312 const actionMock = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 313–321why, one step back313314 program315 .command('bar')316 .addOption(new commander.Option('--a'))317 .addOption(new commander.Option('--b').conflicts('aa'))318 .action(actionMock);319320 program.parse('node test.js bar --a --b'.split(' '));321Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 322–324why, one step back322 assert.equal(actionMock.mock.callCount(), 1);323 const callArgs = actionMock.mock.calls[0].arguments;324 assert.deepEqual(callArgs[0], { a: true, b: true });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 325–326why, one step back325 });326Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 327–328why, one step back327 test('should throw error when conflicts is invoked with a single string that equals another option', (t) => {328 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 329–334why, one step back329330 program331 .command('bar')332 .addOption(new commander.Option('--a'))333 .addOption(new commander.Option('--b').conflicts('a'));334Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 335–340why, one step back335 assert.throws(336 () => {337 program.parse('node test.js bar --a --b'.split(' '));338 },339 { message: "error: option '--b' cannot be used with option '--a'" },340 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 341–342why, one step back341 });342Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 343–344why, one step back343 test('when conflict on program calling action subcommand then throw conflict', (t) => {344 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 345–355why, one step back345 let exception;346347 program348 .addOption(new commander.Option('--black'))349 .addOption(new commander.Option('--white').conflicts('black'));350351 try {352 program.parse('--white --black foo'.split(' '), { from: 'user' });353 } catch (err) {354 exception = err;355 }Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 356–357why, one step back356 assert.notEqual(exception, undefined);357 assert.equal(exception.code, 'commander.conflictingOption');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 358–359why, one step back358 });359Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 360–361why, one step back360 test('when conflict on program calling action subcommand with help then show help', (t) => {361 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 362–372why, one step back362 let exception;363364 program365 .addOption(new commander.Option('--black'))366 .addOption(new commander.Option('--white').conflicts('black'));367368 try {369 program.parse('--white --black foo --help'.split(' '), { from: 'user' });370 } catch (err) {371 exception = err;372 }Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 373–374why, one step back373 assert.notEqual(exception, undefined);374 assert.equal(exception.code, 'commander.helpDisplayed');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 375–376why, one step back375 });376Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 377–378why, one step back377 test('when conflict on program calling external subcommand then throw conflict', (t) => {378 const { program } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 379–383why, one step back379 let exception;380381 program382 .addOption(new commander.Option('--black'))383 .addOption(new commander.Option('--white').conflicts('black'));Switching to esm-only (#2464)John Geebefore adoptionf4bd470
line 384why, one step back384 const pm = path.join(import.meta.dirname, './fixtures/pm');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 385–391why, one step back385 program.command('ext', 'external command', { executableFile: pm });386387 try {388 program.parse('--white --black ext'.split(' '), { from: 'user' });389 } catch (err) {390 exception = err;391 }Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 392–393why, one step back392 assert.notEqual(exception, undefined);393 assert.equal(exception.code, 'commander.conflictingOption');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 394–395why, one step back394 });395});