Skip to content

Commit 209a4fe

Browse files
authored
test: lint more assert(regexp.test(...)) cases
PR-URL: #60878 Refs: #60832 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 10837e3 commit 209a4fe

File tree

4 files changed

+8
-17
lines changed

4 files changed

+8
-17
lines changed

test/eslint.config_partial.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ export default [
110110
message: 'Calling `.catch(common.mustNotCall())` will not detect never-settling promises. Use `.then(common.mustCall())` instead.',
111111
},
112112
{
113-
selector: 'CallExpression[callee.type="MemberExpression"][callee.object.type="Identifier"][callee.object.name="assert"][callee.property.type="Identifier"][callee.property.name="ok"][arguments.0.type="CallExpression"][arguments.0.callee.type="MemberExpression"][arguments.0.callee.object.regex][arguments.0.callee.property.type="Identifier"][arguments.0.callee.property.name="test"]',
113+
selector: 'CallExpression:matches([callee.type="Identifier"][callee.name="assert"], [callee.type="MemberExpression"][callee.object.type="Identifier"][callee.object.name="assert"][callee.property.type="Identifier"][callee.property.name="ok"])[arguments.0.type="CallExpression"][arguments.0.callee.type="MemberExpression"][arguments.0.callee.object.regex][arguments.0.callee.property.type="Identifier"][arguments.0.callee.property.name="test"]',
114114
message: 'Use assert.match instead',
115115
},
116116
{
117-
selector: 'CallExpression[callee.type="MemberExpression"][callee.object.type="Identifier"][callee.object.name="assert"][callee.property.type="Identifier"][callee.property.name="ok"][arguments.0.type="UnaryExpression"][arguments.0.operator="!"][arguments.0.argument.type="CallExpression"][arguments.0.argument.callee.type="MemberExpression"][arguments.0.argument.callee.object.regex][arguments.0.argument.callee.property.name="test"]',
117+
selector: 'CallExpression:matches([callee.type="Identifier"][callee.name="assert"], [callee.type="MemberExpression"][callee.object.type="Identifier"][callee.object.name="assert"][callee.property.type="Identifier"][callee.property.name="ok"])[arguments.0.type="UnaryExpression"][arguments.0.operator="!"][arguments.0.argument.type="CallExpression"][arguments.0.argument.callee.type="MemberExpression"][arguments.0.argument.callee.object.regex][arguments.0.argument.callee.property.name="test"]',
118118
message: 'Use assert.doesNotMatch instead',
119119
},
120120
],

test/parallel/test-promises-warning-on-unhandled-rejection.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ process.on('warning', common.mustCall((warning) => {
1818
case 1:
1919
// Warning about rejection not being handled (will be next tick)
2020
assert.strictEqual(warning.name, 'UnhandledPromiseRejectionWarning');
21-
assert(
22-
/Unhandled promise rejection/.test(warning.message),
23-
'Expected warning message to contain "Unhandled promise rejection" ' +
24-
`but did not. Had "${warning.message}" instead.`
25-
);
21+
assert.match(warning.message, /Unhandled promise rejection/);
2622
break;
2723
case 2:
2824
// Number rejection error displayed. Note it's been stringified
@@ -31,17 +27,12 @@ process.on('warning', common.mustCall((warning) => {
3127
case 3:
3228
// Unhandled rejection warning (won't be handled next tick)
3329
assert.strictEqual(warning.name, 'UnhandledPromiseRejectionWarning');
34-
assert(
35-
/Unhandled promise rejection/.test(warning.message),
36-
'Expected warning message to contain "Unhandled promise rejection" ' +
37-
`but did not. Had "${warning.message}" instead.`
38-
);
30+
assert.match(warning.message, /Unhandled promise rejection/);
3931
break;
4032
case 4:
4133
// Rejection handled asynchronously.
4234
assert.strictEqual(warning.name, 'PromiseRejectionHandledWarning');
43-
assert(/Promise rejection was handled asynchronously/
44-
.test(warning.message));
35+
assert.match(warning.message, /Promise rejection was handled asynchronously/);
4536
}
4637
}, 5));
4738

test/parallel/test-snapshot-eval.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const file = fixtures.path('snapshot', 'mutate-fs.js');
4949
console.log(child.stdout.toString());
5050
assert.strictEqual(child.status, 0);
5151
}
52-
assert(/I am from the snapshot/.test(child.stdout.toString()));
52+
assert.match(child.stdout.toString(), /I am from the snapshot/);
5353
}
5454

5555
{
@@ -68,5 +68,5 @@ const file = fixtures.path('snapshot', 'mutate-fs.js');
6868
console.log(child.stdout.toString());
6969
assert.strictEqual(child.status, 0);
7070
}
71-
assert(/I am from the snapshot/.test(child.stdout.toString()));
71+
assert.match(child.stdout.toString(), /I am from the snapshot/);
7272
}

test/parallel/test-tls-no-sslv3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ process.on('exit', function() {
4646
common.printSkipMessage('`openssl s_client -ssl3` not supported.');
4747
} else {
4848
assert.strictEqual(errors.length, 1);
49-
assert(/:version too low/.test(errors[0].message));
49+
assert.match(errors[0].message, /:version too low/);
5050
}
5151
});

0 commit comments

Comments
 (0)