test: add usedBy matcher / allow scope and origin to be undefined#89
test: add usedBy matcher / allow scope and origin to be undefined#89
usedBy matcher / allow scope and origin to be undefined#89Conversation
You may verify that scope is not defined via
```javascript
expect(variables).to.variableInclude({
name: 'no-scope-var',
scope: undefined
});
```
There was a problem hiding this comment.
Pull request overview
Updates the test assertion helpers to support upcoming “input requirement” variables that may not have scope/origin, and to allow validating usedBy references.
Changes:
- Switch matching logic from
isDefined(...)tohas(expectedVariable, ...)so tests can explicitly assertscope: undefined/origin: undefined. - Add support for asserting
usedBymembership and length. - Keep existing variable matching helpers (
variableEqual/variableInclude) behavior with the extended matching rules.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (has(expectedVariable, 'scope')) { | ||
|
|
||
| if (expectedVariable.scope) { | ||
| expect(variable.scope, `variable[name=${name}].scope`).to.exist; | ||
| expect(variable.scope.id, `variable[name=${name}].scope.id`).to.eql(expectedVariable.scope); | ||
| } else { | ||
| expect(variable.scope, `variable[name=${name}].scope`).not.to.exist; | ||
| } | ||
| } |
There was a problem hiding this comment.
The new has(expectedVariable, 'scope') behavior in assertVariableMatches allows asserting scope: undefined, but findVariable still uses isDefined(scope) when selecting a candidate. That means a pattern with scope: undefined won’t filter by scope at all and may match the wrong variable when multiple variables share the same name in different scopes, causing false failures. Align findVariable with the new semantics (distinguish “key not provided” vs “provided as undefined”) so it can specifically match variables with no scope when scope is present but undefined.
Proposed Changes
Preparing for the introduction of variables without a scope, that are just used but not produced anywhere (#74) this adjusts our test helper:
usedBy(containing element IDs)Examples
Verify that a variable is used in two places:
Verify that scope is not defined via
Checklist
Ensure you provide everything we need to review your contribution:
Closes {LINK_TO_ISSUE}orRelated to {LINK_TO_ISSUE}@bpmn-io/srtool