Skip to content

Commit

Permalink
test: add trailing commas in event tests
Browse files Browse the repository at this point in the history
As much as I would like to do this everywhere and then modify the lint
rule to enforce it, the churn would be too big. However if we're going
to have relatively frequent nits for this sort of thing (as we do), I'd
prefer we migrate a few files at a time to never actually getting around
to doing it.

Ref: #45448 (review)
PR-URL: #45466
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Trott authored and danielleadams committed Jan 3, 2023
1 parent 5ab7a30 commit 3e87834
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 47 deletions.
10 changes: 5 additions & 5 deletions test/parallel/test-event-capture-rejections.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function NoConstructor() {
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options.captureRejections" property must be of type boolean.' +
common.invalidArgTypeHelper(arg)
common.invalidArgTypeHelper(arg),
}
);
});
Expand Down Expand Up @@ -160,7 +160,7 @@ function thenable() {
assert.strictEqual(resolved, undefined);
rejected(_err);
});
}, 1) // Only 1 call for Promises/A+ compat.
}, 1), // Only 1 call for Promises/A+ compat.
});

return obj;
Expand Down Expand Up @@ -235,7 +235,7 @@ function thenableThatThrows() {
Object.defineProperty(obj, 'then', {
get: common.mustCall(() => {
throw _err;
}, 1) // Only 1 call for Promises/A+ compat.
}, 1), // Only 1 call for Promises/A+ compat.
});

return obj;
Expand Down Expand Up @@ -301,14 +301,14 @@ function argValidation() {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "options.captureRejections" property must be of type ' +
`boolean. Received ${received}`
`boolean. Received ${received}`,
});

assert.throws(() => EventEmitter.captureRejections = obj, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "EventEmitter.captureRejections" property must be of ' +
`type boolean. Received ${received}`
`type boolean. Received ${received}`,
});
}

Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-event-emitter-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ assert.throws(
{
code: 'ERR_UNHANDLED_ERROR',
name: 'Error',
message: "Unhandled error. ('Accepts a string')"
message: "Unhandled error. ('Accepts a string')",
}
);

Expand All @@ -20,18 +20,18 @@ assert.throws(
{
code: 'ERR_UNHANDLED_ERROR',
name: 'Error',
message: "Unhandled error. ({ message: 'Error!' })"
message: "Unhandled error. ({ message: 'Error!' })",
}
);

assert.throws(
() => EE.emit('error', {
message: 'Error!',
[util.inspect.custom]() { throw new Error(); }
[util.inspect.custom]() { throw new Error(); },
}),
{
code: 'ERR_UNHANDLED_ERROR',
name: 'Error',
message: 'Unhandled error. ([object Object])'
message: 'Unhandled error. ([object Object])',
}
);
2 changes: 1 addition & 1 deletion test/parallel/test-event-emitter-invalid-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ for (const method of eventsMethods) {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "listener" argument must be of type function. ' +
'Received null'
'Received null',
}, `event.${method}('foo', null) should throw the proper error`);
}
4 changes: 2 additions & 2 deletions test/parallel/test-event-emitter-max-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ for (const obj of throwsObjs) {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "n" is out of range. ' +
`It must be a non-negative number. Received ${inspect(obj)}`
`It must be a non-negative number. Received ${inspect(obj)}`,
}
);

Expand All @@ -50,7 +50,7 @@ for (const obj of throwsObjs) {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "defaultMaxListeners" is out of range. ' +
`It must be a non-negative number. Received ${inspect(obj)}`
`It must be a non-negative number. Received ${inspect(obj)}`,
}
);
}
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-eventemitter-asyncresource.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function makeHook(trackedTypes) {

before(asyncId) { log(asyncId, 'before'); },
after(asyncId) { log(asyncId, 'after'); },
destroy(asyncId) { log(asyncId, 'destroy'); }
destroy(asyncId) { log(asyncId, 'destroy'); },
}).enable();

return {
Expand All @@ -51,7 +51,7 @@ function makeHook(trackedTypes) {
},
ids() {
return new Set(eventMap.keys());
}
},
};
}

Expand Down Expand Up @@ -150,7 +150,7 @@ throws(
code: 'ERR_INVALID_THIS',
name: /TypeError/,
message: 'Value of "this" must be of type EventEmitterAsyncResource',
stack: new RegExp(`at get ${getter}`)
stack: new RegExp(`at get ${getter}`),
}
);
});
30 changes: 15 additions & 15 deletions test/parallel/test-events-on-async-iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const common = require('../common');
const assert = require('assert');
const { on, EventEmitter } = require('events');
const {
NodeEventTarget
NodeEventTarget,
} = require('internal/event_target');

async function basic() {
Expand Down Expand Up @@ -131,18 +131,18 @@ async function next() {

assert.deepStrictEqual(results, [{
value: ['bar'],
done: false
done: false,
}, {
value: [42],
done: false
done: false,
}, {
value: undefined,
done: true
done: true,
}]);

assert.deepStrictEqual(await iterable.next(), {
value: undefined,
done: true
done: true,
});
}

Expand All @@ -160,19 +160,19 @@ async function nextError() {
]);
assert.deepStrictEqual(results, [{
status: 'rejected',
reason: _err
reason: _err,
}, {
status: 'fulfilled',
value: {
value: undefined,
done: true
}
done: true,
},
}, {
status: 'fulfilled',
value: {
value: undefined,
done: true
}
done: true,
},
}]);
assert.strictEqual(ee.listeners('error').length, 0);
}
Expand All @@ -196,7 +196,7 @@ async function iterableThrow() {
}, {
message: 'The "EventEmitter.AsyncIterator" property must be' +
' an instance of Error. Received undefined',
name: 'TypeError'
name: 'TypeError',
});

const expected = [['bar'], [42]];
Expand Down Expand Up @@ -258,11 +258,11 @@ async function abortableOnBefore() {
const abortedSignal = AbortSignal.abort();
[1, {}, null, false, 'hi'].forEach((signal) => {
assert.throws(() => on(ee, 'foo', { signal }), {
code: 'ERR_INVALID_ARG_TYPE'
code: 'ERR_INVALID_ARG_TYPE',
});
});
assert.throws(() => on(ee, 'foo', { signal: abortedSignal }), {
name: 'AbortError'
name: 'AbortError',
});
}

Expand All @@ -271,11 +271,11 @@ async function eventTargetAbortableOnBefore() {
const abortedSignal = AbortSignal.abort();
[1, {}, null, false, 'hi'].forEach((signal) => {
assert.throws(() => on(et, 'foo', { signal }), {
code: 'ERR_INVALID_ARG_TYPE'
code: 'ERR_INVALID_ARG_TYPE',
});
});
assert.throws(() => on(et, 'foo', { signal: abortedSignal }), {
name: 'AbortError'
name: 'AbortError',
});
}

Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-events-once.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ async function abortSignalBefore() {

await Promise.all([1, {}, 'hi', null, false].map((signal) => {
return rejects(once(ee, 'foo', { signal }), {
code: 'ERR_INVALID_ARG_TYPE'
code: 'ERR_INVALID_ARG_TYPE',
});
}));

return rejects(once(ee, 'foo', { signal: abortedSignal }), {
name: 'AbortError'
name: 'AbortError',
});
}

Expand All @@ -179,7 +179,7 @@ async function abortSignalAfter() {
const ac = new AbortController();
ee.on('error', common.mustNotCall());
const r = rejects(once(ee, 'foo', { signal: ac.signal }), {
name: 'AbortError'
name: 'AbortError',
});
process.nextTick(() => ac.abort());
return r;
Expand Down Expand Up @@ -217,20 +217,20 @@ async function eventTargetAbortSignalBefore() {

await Promise.all([1, {}, 'hi', null, false].map((signal) => {
return rejects(once(et, 'foo', { signal }), {
code: 'ERR_INVALID_ARG_TYPE'
code: 'ERR_INVALID_ARG_TYPE',
});
}));

return rejects(once(et, 'foo', { signal: abortedSignal }), {
name: 'AbortError'
name: 'AbortError',
});
}

async function eventTargetAbortSignalAfter() {
const et = new EventTarget();
const ac = new AbortController();
const r = rejects(once(et, 'foo', { signal: ac.signal }), {
name: 'AbortError'
name: 'AbortError',
});
process.nextTick(() => ac.abort());
return r;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-events-static-geteventlisteners.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { kWeakHandler } = require('internal/event_target');

const {
deepStrictEqual,
throws
throws,
} = require('assert');

const { getEventListeners, EventEmitter } = require('events');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-eventtarget-memoryleakwarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const common = require('../common');
const {
setMaxListeners,
EventEmitter
EventEmitter,
} = require('events');
const assert = require('assert');

Expand Down
18 changes: 9 additions & 9 deletions test/parallel/test-eventtarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ let asyncTest = Promise.resolve();
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "options" argument must be of type object.' +
common.invalidArgTypeHelper(i)
common.invalidArgTypeHelper(i),
})
));
}
Expand Down Expand Up @@ -141,7 +141,7 @@ let asyncTest = Promise.resolve();
handleEvent: common.mustCall(function(event) {
strictEqual(event.type, 'foo');
strictEqual(this, ev2);
})
}),
};

eventTarget.addEventListener('foo', ev1);
Expand Down Expand Up @@ -318,15 +318,15 @@ let asyncTest = Promise.resolve();
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "event" argument must be an instance of Event.' +
common.invalidArgTypeHelper(i)
common.invalidArgTypeHelper(i),
});
});

const err = (arg) => ({
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "listener" argument must be an instance of EventListener.' +
common.invalidArgTypeHelper(arg)
common.invalidArgTypeHelper(arg),
});

[
Expand Down Expand Up @@ -388,7 +388,7 @@ let asyncTest = Promise.resolve();
const event = new Event('foo');
target1.addEventListener('foo', common.mustCall((event) => {
throws(() => target2.dispatchEvent(event), {
code: 'ERR_EVENT_RECURSION'
code: 'ERR_EVENT_RECURSION',
});
}));
target1.dispatchEvent(event);
Expand Down Expand Up @@ -486,7 +486,7 @@ let asyncTest = Promise.resolve();
/a/,
].forEach((i) => {
throws(() => target.dispatchEvent.call(i, event), {
code: 'ERR_INVALID_THIS'
code: 'ERR_INVALID_THIS',
});
});
}
Expand Down Expand Up @@ -627,20 +627,20 @@ let asyncTest = Promise.resolve();
{
const ev = new Event('test');
const evConstructorName = inspect(ev, {
depth: -1
depth: -1,
});
strictEqual(evConstructorName, 'Event');

const inspectResult = inspect(ev, {
depth: 1
depth: 1,
});
ok(inspectResult.includes('Event'));
}

{
const et = new EventTarget();
const inspectResult = inspect(et, {
depth: 1
depth: 1,
});
ok(inspectResult.includes('EventTarget'));
}
Expand Down

0 comments on commit 3e87834

Please sign in to comment.