Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 64 additions & 21 deletions test/assertions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { expect } = require('chai');
const { has } = require('min-dash');


function isDefined(value) {
Expand All @@ -21,30 +22,72 @@ function findVariable(variables, expectedVariable) {
}

function assertVariableMatches(variable, expectedVariable) {
const {
name,
type,
detail,
info,
scope,
isList,
origin,
entries
} = expectedVariable;

isDefined(type) && expect(variable.type, `variable[name=${name}].type`).to.eql(type);
isDefined(info) && expect(variable.info, `variable[name=${name}].info`).to.eql(info);
isDefined(detail) && expect(variable.detail, `variable[name=${name}].detail`).to.eql(detail);
isDefined(scope) && expect(variable.scope.id, `variable[name=${name}].scope.id`).to.eql(scope);
isDefined(isList) && expect(!!variable.isList, `variable[name=${name}].isList`).to.eql(!!isList);
isDefined(entries) && expect(variable.entries, `variable[name=${name}].entries`).to.variableEqual(entries);
const { name } = variable;

isDefined(origin) && origin.forEach((expectedOrigin) => {
const foundOrigin = variable.origin.find(o => o.id === expectedOrigin);
expect(foundOrigin, `origin[name=${expectedOrigin}]`).to.exist;
});
if (has(expectedVariable, 'type')) {
expect(variable.type, `variable[name=${name}].type`).to.eql(expectedVariable.type);
}

if (has(expectedVariable, 'info')) {
expect(variable.info, `variable[name=${name}].info`).to.eql(expectedVariable.info);
}

if (has(expectedVariable, 'detail')) {
expect(variable.detail, `variable[name=${name}].detail`).to.eql(expectedVariable.detail);
}

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

if (has(expectedVariable, 'isList')) {
expect(!!variable.isList, `variable[name=${name}].isList`).to.eql(!!expectedVariable.isList);
}

isDefined(origin) && expect(variable.origin.length, `variable[name=${name}].origin.length`).to.eql(origin.length);
if (has(expectedVariable, 'entries')) {
expect(variable.entries, `variable[name=${name}].entries`).to.variableEqual(expectedVariable.entries);
}

if (has(expectedVariable, 'origin')) {

if (expectedVariable.origin) {
expect(variable.origin, `variable[name=${name}].origin`).to.exist;

expectedVariable.origin.forEach((expectedId) => {
const foundOrigin = variable.origin.find(e => e.id === expectedId);

expect(foundOrigin, `variable[name=${name}] > origin[id=${expectedId}]`).to.exist;
});

expect(variable.origin.length, `variable[name=${name}].origin.length`).to.eql(expectedVariable.origin.length);
} else {
expect(variable.origin, `variable[name=${name}].origin`).not.to.exist;
}
}

if (has(expectedVariable, 'usedBy')) {

if (expectedVariable.usedBy) {
expect(variable.usedBy, `variable[name=${name}].usedBy`).to.exist;

expectedVariable.usedBy.forEach((expectedId) => {
const foundUsedBy = variable.usedBy.find(e => e.id === expectedId);

expect(foundUsedBy, `variable[name=${name}] > usedBy[id=${expectedId}]`).to.exist;
});

expect(variable.usedBy.length, `variable[name=${name}].usedBy.length`).to.eql(expectedVariable.usedBy.length);
} else {
expect(variable.usedBy, `variable[name=${name}].usedBy`).not.to.exist;
}
}
}

/**
Expand Down