Skip to content

test: add usedBy matcher / allow scope and origin to be undefined#89

Merged
nikku merged 1 commit intomainfrom
test-helper
Mar 6, 2026
Merged

test: add usedBy matcher / allow scope and origin to be undefined#89
nikku merged 1 commit intomainfrom
test-helper

Conversation

@nikku
Copy link
Copy Markdown
Member

@nikku nikku commented Mar 6, 2026

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:

  • To validate usedBy (containing element IDs)
  • To verify non-existing scope (variables that are only used, but produced no-where)

Examples

Verify that a variable is used in two places:

expect(variables).to.variableInclude({
  name: 'isCaseApprovded',
  usedBy: [ 'SequenceFlow_1', 'SequenceFlow_2' ]
});

Verify that scope is not defined via

expect(variables).to.variableInclude({
  name: 'usedButNotDefinedVariable',
  scope: undefined
});

Checklist

Ensure you provide everything we need to review your contribution:

  • Contribution meets our definition of done
  • Pull request establishes context
    • Link to related issue(s), i.e. Closes {LINK_TO_ISSUE} or Related to {LINK_TO_ISSUE}
    • Brief textual description of the changes
    • Screenshots or short videos showing UI/UX changes
    • Steps to try out, i.e. using the @bpmn-io/sr tool

You may verify that scope is not defined via

```javascript
expect(variables).to.variableInclude({
  name: 'no-scope-var',
  scope: undefined
});
```
@bpmn-io-tasks bpmn-io-tasks bot added the in progress Currently worked on label Mar 6, 2026
@nikku nikku marked this pull request as ready for review March 6, 2026 14:22
@nikku nikku requested review from a team, AlekseyManetov, Copilot and philippfromme March 6, 2026 14:22
@bpmn-io-tasks bpmn-io-tasks bot added needs review Review pending and removed in progress Currently worked on labels Mar 6, 2026
@nikku nikku requested a review from Buckwich March 6, 2026 14:22
@nikku
Copy link
Copy Markdown
Member Author

nikku commented Mar 6, 2026

@Buckwich ready for your review - preparation for what follows in #74.

@nikku nikku merged commit 2370240 into main Mar 6, 2026
7 checks passed
@bpmn-io-tasks bpmn-io-tasks bot removed the needs review Review pending label Mar 6, 2026
@nikku nikku deleted the test-helper branch March 6, 2026 14:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(...) to has(expectedVariable, ...) so tests can explicitly assert scope: undefined / origin: undefined.
  • Add support for asserting usedBy membership 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.

Comment on lines +40 to +48
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;
}
}
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants