From ad744b78dcef3bb1bf5ac7dd4c8c77a361322343 Mon Sep 17 00:00:00 2001 From: Georg Schwarz Date: Tue, 21 May 2024 14:40:05 +0200 Subject: [PATCH] Refactor import-reference tests to be less ambiguous (use test.each instead of similar test cases) --- .../src/lib/lsp/import-reference.spec.ts | 64 +++++++------------ 1 file changed, 24 insertions(+), 40 deletions(-) diff --git a/libs/language-server/src/lib/lsp/import-reference.spec.ts b/libs/language-server/src/lib/lsp/import-reference.spec.ts index aa09deead..226044271 100644 --- a/libs/language-server/src/lib/lsp/import-reference.spec.ts +++ b/libs/language-server/src/lib/lsp/import-reference.spec.ts @@ -41,26 +41,18 @@ describe('References to imported elements', () => { services = createJayveeServices(NodeFileSystem).Jayvee; }); - it('should resolve reference to imported element', async () => { - const relativeTestFilePath = - 'import-published-references/valid-reference-to-imported-element.jv'; - - const model = await parseModel(relativeTestFilePath); - - expect(model.pipelines.length).toEqual(1); // file contains one pipeline - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const blocks = model.pipelines[0]!.blocks; - expect(blocks.length).toEqual(1); // pipeline contains one block - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const reference = blocks[0]!.type; // of an imported block type - - expect(reference.ref).toBeDefined(); - }); - - it('should resolve reference to transitively imported element', async () => { - const relativeTestFilePath = - 'import-published-references/valid-reference-to-element-transitive.jv'; - + const validCases: [string, string][] = [ + // [test name, test file path] + [ + 'should resolve reference to imported element', + 'import-published-references/valid-reference-to-imported-element.jv', + ], + [ + 'should resolve reference to transitively imported element', + 'import-published-references/valid-reference-to-element-transitive.jv', + ], + ]; + test.each(validCases)('%s', async (_, relativeTestFilePath) => { const model = await parseModel(relativeTestFilePath); expect(model.pipelines.length).toEqual(1); // file contains one pipeline @@ -73,26 +65,18 @@ describe('References to imported elements', () => { expect(reference.ref).toBeDefined(); }); - it('should not resolve reference to non-existing element', async () => { - const relativeTestFilePath = - 'import-published-references/invalid-reference-to-not-existing-element.jv'; - - const model = await parseModel(relativeTestFilePath); - - expect(model.pipelines.length).toEqual(1); // file contains one pipeline - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const blocks = model.pipelines[0]!.blocks; - expect(blocks.length).toEqual(1); // pipeline contains one block - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const reference = blocks[0]!.type; // of an imported block type - - expect(reference.ref).toBeUndefined(); - }); - - it('should not resolve reference to non-imported element', async () => { - const relativeTestFilePath = - 'import-published-references/invalid-reference-to-not-imported-element.jv'; - + const invalidCases: [string, string][] = [ + // [test name, test file path] + [ + 'should not resolve reference to non-existing element', + 'import-published-references/invalid-reference-to-not-existing-element.jv', + ], + [ + 'should not resolve reference to non-imported element', + 'import-published-references/invalid-reference-to-not-imported-element.jv', + ], + ]; + test.each(invalidCases)('%s', async (_, relativeTestFilePath) => { const model = await parseModel(relativeTestFilePath); expect(model.pipelines.length).toEqual(1); // file contains one pipeline