Skip to content

Commit f6ffa4d

Browse files
test: fix failing tests due to colliding file names (#569)
### Summary of Changes Clear files loaded into workspace by tests in additional places to prevent colliding file names. This does not fully solve the issue yet, but together with the upcoming update to `Langium` it should get rid of it completely. --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
1 parent 48b5f53 commit f6ffa4d

File tree

7 files changed

+33
-21
lines changed

7 files changed

+33
-21
lines changed

src/language/safe-ds-module.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import {
1010
PartialLangiumServices,
1111
} from 'langium';
1212
import { SafeDsGeneratedModule, SafeDsGeneratedSharedModule } from './generated/module.js';
13-
import { SafeDsValidator, registerValidationChecks } from './validation/safe-ds-validator.js';
13+
import { registerValidationChecks, SafeDsValidator } from './validation/safe-ds-validator.js';
1414
import { SafeDsFormatter } from './formatting/safe-ds-formatter.js';
15-
import { SafeDsWorkspaceManager } from './builtins/workspaceManager.js';
16-
import {SafeDsScopeComputation} from "./scoping/safe-ds-scope-computation.js";
17-
import {SafeDsScopeProvider} from "./scoping/safe-ds-scope-provider.js";
15+
import { SafeDsWorkspaceManager } from './builtins/safe-ds-workspace-manager.js';
16+
import { SafeDsScopeComputation } from './scoping/safe-ds-scope-computation.js';
17+
import { SafeDsScopeProvider } from './scoping/safe-ds-scope-provider.js';
1818

1919
/**
2020
* Declaration of custom services - add your own service classes here.

tests/language/builtins/workspaceManager.test.ts tests/language/builtins/safe-ds-workspace-manager.test.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { beforeAll, describe, expect, it } from 'vitest';
2-
import { listBuiltinsFiles } from '../../../src/language/builtins/workspaceManager.js';
1+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
2+
import { listBuiltinsFiles } from '../../../src/language/builtins/safe-ds-workspace-manager.js';
33
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
44
import { getLinkingErrors } from '../../helpers/diagnostics.js';
55
import { NodeFileSystem } from 'langium/node';
6+
import { clearDocuments } from 'langium/test';
67

78
const services = createSafeDsServices(NodeFileSystem).SafeDs;
89

@@ -11,6 +12,10 @@ describe('SafeDsWorkspaceManager', () => {
1112
await services.shared.workspace.WorkspaceManager.initializeWorkspace([]);
1213
});
1314

15+
afterAll(async () => {
16+
await clearDocuments(services);
17+
});
18+
1419
describe('loadAdditionalDocuments', () => {
1520
it.each(['Any', 'Boolean', 'Float', 'Int', 'Nothing', 'Number', 'String'])(
1621
'should be possible to refer to %s',

tests/language/formatting/testFormatting.test.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
22
import { clearDocuments, expectFormatting } from 'langium/test';
3-
import { describe, it } from 'vitest';
3+
import { afterEach, describe, it } from 'vitest';
44
import { EmptyFileSystem } from 'langium';
55
import { createFormattingTests } from './creator.js';
66

77
const services = createSafeDsServices(EmptyFileSystem).SafeDs;
88
const formatterTests = createFormattingTests();
99

1010
describe('formatter', async () => {
11+
afterEach(async () => {
12+
await clearDocuments(services);
13+
});
14+
1115
// Test that the original code is formatted correctly
1216
it.each(await formatterTests)('$testName', async (test) => {
1317
// Test is invalid
@@ -20,9 +24,6 @@ describe('formatter', async () => {
2024
before: test.originalCode,
2125
after: test.expectedFormattedCode,
2226
});
23-
24-
// Clear loaded documents to avoid colliding URIs (https://github.com/langium/langium/issues/1146)
25-
await clearDocuments(services);
2627
});
2728

2829
// Test that the expected formatted code stays the same when formatted again
@@ -37,8 +38,5 @@ describe('formatter', async () => {
3738
before: test.expectedFormattedCode,
3839
after: test.expectedFormattedCode,
3940
});
40-
41-
// Clear loaded documents to avoid colliding URIs (https://github.com/langium/langium/issues/1146)
42-
await clearDocuments(services);
4341
});
4442
});

tests/language/grammar/testGrammar.test.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it } from 'vitest';
1+
import { afterEach, describe, it } from 'vitest';
22
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
33
import { AssertionError } from 'assert';
44
import { NodeFileSystem } from 'langium/node';
@@ -9,6 +9,10 @@ import { getSyntaxErrors } from '../../helpers/diagnostics.js';
99
const services = createSafeDsServices(NodeFileSystem).SafeDs;
1010

1111
describe('grammar', () => {
12+
afterEach(async () => {
13+
await clearDocuments(services);
14+
});
15+
1216
it.each(createGrammarTests())('$testName', async (test) => {
1317
// Test is invalid
1418
if (test.error) {
@@ -39,8 +43,5 @@ describe('grammar', () => {
3943
});
4044
}
4145
}
42-
43-
// Clear loaded documents to avoid colliding URIs (https://github.com/langium/langium/issues/1146)
44-
await clearDocuments(services);
4546
});
4647
});

tests/language/scoping/testScoping.test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { describe, it } from 'vitest';
1+
import { afterEach, describe, it } from 'vitest';
22
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
33
import { URI } from 'vscode-uri';
44
import { NodeFileSystem } from 'langium/node';
5-
import { isRangeEqual } from 'langium/test';
5+
import { isRangeEqual, clearDocuments } from 'langium/test';
66
import { AssertionError } from 'assert';
77
import { isLocationEqual, locationToString } from '../../helpers/location.js';
88
import { createScopingTests, ExpectedReference } from './creator.js';
@@ -12,6 +12,10 @@ import { Location } from 'vscode-languageserver';
1212
const services = createSafeDsServices(NodeFileSystem).SafeDs;
1313

1414
describe('scoping', async () => {
15+
afterEach(async () => {
16+
await clearDocuments(services);
17+
});
18+
1519
it.each(await createScopingTests())('$testName', async (test) => {
1620
// Test is invalid
1721
if (test.error) {

tests/language/validation/testValidation.test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
import { describe, it } from 'vitest';
1+
import { afterEach, describe, it } from 'vitest';
22
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
33
import { URI } from 'vscode-uri';
44
import { NodeFileSystem } from 'langium/node';
55
import { createValidationTests, ExpectedIssue } from './creator.js';
66
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver-types';
77
import { AssertionError } from 'assert';
8-
import { isRangeEqual } from 'langium/test';
8+
import { clearDocuments, isRangeEqual } from 'langium/test';
99
import { locationToString } from '../../helpers/location.js';
1010

1111
const services = createSafeDsServices(NodeFileSystem).SafeDs;
1212

1313
describe('validation', async () => {
14+
afterEach(async () => {
15+
await clearDocuments(services);
16+
});
17+
1418
it.each(await createValidationTests())('$testName', async (test) => {
1519
// Test is invalid
1620
if (test.error) {

0 commit comments

Comments
 (0)