Improve tests following lint advice from eslint-node-test - #2560
Conversation
|
|
||
| const program = new MyCommand(); | ||
|
|
||
| program.configureHelp({ MyCommand }); |
There was a problem hiding this comment.
This is a bogus call I spotted myself, not one reported by the linter.
|
I tried turning on all the rules to see what else looked good. require-top-level-describe enforces the pattern I followed with a file-level describe for any files. It picked up a few cases where I had added tests after the describe block. For single test files, I manually disabled the check as nothing extra to add for context. require-hook picked up the pattern I used for wrapping fixture loops inside a describe means the code is running at file load time rather than test time. It will be a noisy refactor, so I'll turn that on separately. |
| program.parse(['one', 'two'], { from: 'user' }); | ||
| assert.deepEqual(passedArg, ['one', 'two']); | ||
| }); | ||
|
|
There was a problem hiding this comment.
Duplicate of above test
| // semver minor versions. For now, also testing the error.message and that output occurred | ||
| // to detect accidental changes in behaviour. | ||
|
|
||
| function expectCommanderError(err, exitCode, code, message) { |
There was a problem hiding this comment.
Removed expectCommanderError and put tests inline for clarity within tests.
| }); | ||
|
|
||
| test('when specify unknown command then throw CommanderError', (t) => { | ||
| const stderrSpy = t.mock.method(process.stderr, 'write', () => {}); |
There was a problem hiding this comment.
Removed mocks to suppress/check output and used createTestCommand() for clean output instead
| assert.deepEqual(program.opts().comma, ['CCC']); | ||
| }); | ||
|
|
||
| test('when option has default array then specified value is used instead of default (not appended)', () => { |
There was a problem hiding this comment.
Duplicate of above test
|
Finished work, ready for review. No hurry. (I had intended to open as draft, but missed that sorry. Did at least put WIP in title initially!) |
Problem
I transferred a lot of tests to a new testing framework, which I learnt as I went. There is some room for improvement. 😊
Solution
Install https://github.com/sindresorhus/eslint-node-test and fix the lint errors.
Some of changes:
assert.throws, as otherwise even a syntax error would passassert.throws()assert.ok(expression)instead ofassert(expression)ChangeLog