Tests can see each other variables #1449
-
I wrote a test for an undefined variable. However, validation completed without the expected error. Experimenting, I found that this was because the test with the expected error could see the variables in other tests. My DSL should have no cross-file capabilities. See the following test file that I wrote for the Hello World project. The second test fails because it does not have the expected error. Am I setting up my test infrastructure wrong? Am I configuring my DSL wrong? import { expect, test } from 'vitest';
import { EmptyFileSystem } from 'langium';
import { validationHelper, expectNoIssues } from 'langium/test';
import { createHelloWorldServices } from '../src/language/hello-world-module.js';
import { Model } from '../src/language/generated/ast.js';
const services = createHelloWorldServices(EmptyFileSystem);
export const validate = validationHelper<Model>(services.HelloWorld);
test('Success', async () => {
const validation = await validate(`
person John
person Jane
Hello John!
Hello Jane!
`)
expectNoIssues(validation);
})
test('Undefined name', async () => {
const validation = await validate(`
person John
person Bob
Hello John!
Hello Jane!
`)
expect(validation.diagnostics).toHaveLength(1); // AssertionError: expected [] to have a length of 1 but got +0
}) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @drhagenabm, The |
Beta Was this translation helpful? Give feedback.
Hey @drhagenabm,
The
ValidationResult
object contains adispose
method that allows you to clean up after itself. It will delete all documents that are associated with that validation test. Alternatively, you can callclearDocuments
yourself. Since Langium doesn't know when a test ends/another one starts, the clean up is left to the adopter.