Gathering detailed insights and metrics for call-matcher
Gathering detailed insights and metrics for call-matcher
Gathering detailed insights and metrics for call-matcher
Gathering detailed insights and metrics for call-matcher
escallmatch
ECMAScript CallExpression matcher made from simple API definition
jest-callslike
A jest assertion that checks calls for count, order and informed parameters, all at once
jest-matcher-called-on
Jest Custom Matcher Asserts the Context the Spy is Called On
jest-matcher-called-with-once
Adds .toHaveBeenCalledWithOnce() to your Jest expect() matchers
ECMAScript CallExpression matcher made from function/method signature
npm install call-matcher
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
4 Stars
59 Commits
6 Forks
2 Watchers
5 Branches
2 Contributors
Updated on May 19, 2020
Latest Version
2.0.0
Package Id
call-matcher@2.0.0
Size
5.23 kB
NPM Version
6.4.1
Node Version
10.15.0
Published on
Jan 21, 2019
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
6
ECMAScript CallExpression matcher made from function/method signature
Creating CallExpression matcher for method signature 'assert.equal(actual, expected, [message])'
.
Then match against path/to/some_test.js
.
1var CallMatcher = require('call-matcher'); 2var esprima = require('esprima'); 3var estraverse = require('estraverse'); 4var fs = require('fs'); 5 6var ast = esprima.parse('assert.equal(actual, expected, [message])'); 7var expression = ast.body[0].expression; 8var matcher = new CallMatcher(expression); 9 10estraverse.traverse(esprima.parse(fs.readFileSync('path/to/some_test.js')), { 11 enter: function (currentNode, parentNode) { 12 if (matcher.test(currentNode)) { 13 // currentNode is a CallExpression that matches to the signature 14 } 15 var argMatched = matcher.matchArgument(currentNode, parentNode); 16 if (argMatched) { 17 if (argMatched.kind === 'mandatory') { 18 // mandatory arg (in this case, `actual` or `expected`) 19 } else if (argMatched.kind === 'optional') { 20 // optional arg (in this case, `message`) 21 } 22 } 23 } 24});
where content of path/to/some_test.js
is:
1var assert = require('assert'); 2var anotherAssert = assert; 3var equal = assert.equal.bind(assert); 4var foo = '2'; 5var bar = 2; 6 7assert.equal(foo, bar); // matches 8assert.equal(bar, foo); // matches 9assert.equal(foo, bar, 'foo shoule be equal to bar'); // matches (with optional arg) 10 11assert.equal(); // does not match (less args) 12assert.equal(foo); // does not match (less args) 13assert.equal(foo, bar, 'hoge', 'fuga'); // does not match (too much args) 14 15assert.notEqual(foo, bar); // does not match (callee method name differs) 16anotherAssert.equal(foo, bar); // does not match (callee object name differs) 17equal(foo, bar); // does not match (callee does not match)
call-matcher
is a spin-off product of power-assert project.
Pull-requests, issue reports and patches are always welcomed.
Create matcher object for a given expression.
1var ast = esprima.parse('assert.equal(actual, expected, [message])'); 2var expression = ast.body[0].expression; 3var matcher = new CallMatcher(expression);
Any signature string enclosed in bracket (for example, [message]
) means optional parameters. Without bracket means mandatory parameters.
Returns matcher
object having four methods, test
, matchArgument
, calleeAst
, and argumentSignatures
.
an object
for configuration options. If not passed, default options will be used.
type | default value |
---|---|
object | (return value of estraverse.VisitorKeys ) |
VisitorKeys for AST traversal. See estraverse.VisitorKeys and babel.types.VISITOR_KEYS.
type | default value |
---|---|
object | N/A |
Type and property whitelist on creating AST clone. astWhiteList
is an object containing NodeType as keys and properties as values.
1{ 2 ArrayExpression: ['type', 'elements'], 3 ArrayPattern: ['type', 'elements'], 4 ArrowFunctionExpression: ['type', 'id', 'params', 'body', 'generator', 'expression'], 5 AssignmentExpression: ['type', 'operator', 'left', 'right'], 6 ...
Tests whether node
matches the signature or not.
true
if matched.false
if not matched.node
should be an AST node object defined in The ESTree Spec (formerly known as Mozilla SpiderMonkey Parser API).
Returns match result object representing whether node
(and its parentNode
) matches some argument of the signature or not.
null
if not matched.{index: 0, name: 'actual', kind: 'mandatory'}
, whose index
is an index of matched argument, name
is an argument name in the signature and kind
is 'mandatory'
or 'optional'
.node
and parentNode
should be AST node objects defined in The ESTree Spec (formerly known as Mozilla SpiderMonkey Parser API).
Returns clone of callee AST object based on signature passed to CallMatcher
function. Returned tree is one of AST node objects defined in The ESTree Spec (formerly known as Mozilla SpiderMonkey Parser API) (in most cases, Identifier
or MemberExpression
).
Returns array of argument signature objects based on signature passed to CallMatcher
function. Returns array of objects like [{index: 0, name: 'actual', kind: 'mandatory'}]
, whose index
is an index of matched argument, name
is an argument name in the signature and kind
is 'mandatory'
or 'optional'
.
Install
$ npm install --save call-matcher
See CHANGELOG
Licensed under the MIT license.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/16 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
13 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More