Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/lib/rooibos/TestGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ export class TestGroup extends TestBlock {
const callPath = util.getAllDottedGetParts(callExpression.callee.obj)?.map((part) => part.text).join('.');

if (callPath) {
// Skip if callPath starts with a namespace name — this is a namespace
// function call (e.g. some.space.assertEqual()), not a method call on
// an object like m. Injecting assertion tracking on a namespace prefix
// produces invalid output (e.g. some_space.currentAssertLineNumber).
const callPathFirstPart = callPath.split('.')[0].toLowerCase();
if (namespaceLookup.has(callPathFirstPart) || scope?.namespaceLookup?.has(callPathFirstPart)) {
return;
}

if (dge.name.text === 'stubCall') {
this.modifyModernRooibosExpectCallExpression(callExpression, editor, namespaceLookup, scope);
return expressionStatement;
Expand Down
33 changes: 33 additions & 0 deletions src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,39 @@ describe('RooibosPlugin', () => {
})).not.to.exist;
});

it('does not inject assertion tracking for namespace function calls with assertion-like names', async () => {
// Regression test: some.space.assertEqual(...) inside a test method should NOT have
// currentAssertLineNumber injected with `some.space` as the target object.
// The call is a namespaced function, not a method call on an object.
program.setFile<BrsFile>('source/someSpace.bs', `
namespace some.space
function assertEqual(a, b)
end function
end namespace
`);
plugin.afterProgramCreate(program);
program.setFile<BrsFile>('source/test.spec.bs', `
@suite
class ATest extends rooibos.BaseTestSuite
@describe("groupA")
@it("is test1")
function Test_1()
some.space.assertEqual(1, 1)
m.assertEqual(2, 2)
end function
end class
`);
program.validate();
await builder.transpile();
const contents = getContents('test.spec.brs');
// The namespace function call must NOT produce some_space.currentAssertLineNumber
expect(contents).not.to.include('some_space.currentAssertLineNumber');
// The m.assertEqual assertion MUST still get currentAssertLineNumber injected
expect(contents).to.include('m.currentAssertLineNumber');
// The namespace call must be transpiled correctly as underscored function
expect(contents).to.include('some_space_assertEqual(1, 1)');
});

it('handles groups that start with numbers', async () => {
plugin.afterProgramCreate(program);
// program.validate();
Expand Down