From f21274b91ef4aba2c219f76d27712dd36322dae6 Mon Sep 17 00:00:00 2001 From: Dwight Van Lancker Date: Tue, 20 Feb 2024 10:24:27 +0100 Subject: [PATCH] Fix unit tests + remove builds and testing for node 14 & 16, adding 18 and 20 --- .github/workflows/ci-build.yml | 3 +- .github/workflows/ci-unit-tests.yml | 3 +- packages/oslo-converter-uml-ea/package.json | 6 +- packages/oslo-extractor-uml-ea/package.json | 6 +- .../package.json | 6 +- ...dfVocabularyGenerationService.unit.test.ts | 19 +--- .../test/data/mockData.ts | 96 ++++++++----------- 7 files changed, 61 insertions(+), 78 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index ddd973a..d59c077 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -13,9 +13,8 @@ jobs: matrix: os: [ubuntu-latest] node-version: - - 14.x - - 16.x - 18.x + - 20.x steps: - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 diff --git a/.github/workflows/ci-unit-tests.yml b/.github/workflows/ci-unit-tests.yml index 7473e01..fa575cd 100644 --- a/.github/workflows/ci-unit-tests.yml +++ b/.github/workflows/ci-unit-tests.yml @@ -13,9 +13,8 @@ jobs: matrix: os: [ubuntu-latest] node-version: - - 14.x - - 16.x - 18.x + - 20.x steps: - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 diff --git a/packages/oslo-converter-uml-ea/package.json b/packages/oslo-converter-uml-ea/package.json index dadd027..0528691 100644 --- a/packages/oslo-converter-uml-ea/package.json +++ b/packages/oslo-converter-uml-ea/package.json @@ -46,7 +46,11 @@ "/node_modules/", "index.js" ], - "testEnvironment": "node" + "testEnvironment": "node", + "moduleNameMapper": { + "^@oslo-core/(.*)$": "/../oslo-core/lib/$1", + "^@oslo-converter-uml-ea/(.*)$": "/lib/$1" + } }, "scripts": { "build": "npm run build:ts", diff --git a/packages/oslo-extractor-uml-ea/package.json b/packages/oslo-extractor-uml-ea/package.json index 7037b00..31325b3 100644 --- a/packages/oslo-extractor-uml-ea/package.json +++ b/packages/oslo-extractor-uml-ea/package.json @@ -42,7 +42,11 @@ "./lib/utils", "./lib/types" ], - "testEnvironment": "node" + "testEnvironment": "node", + "moduleNameMapper": { + "^@oslo-core/(.*)$": "/../oslo-core/lib/$1", + "^@oslo-extractor-uml-ea/(.*)$": "/lib/$1" + } }, "scripts": { "build": "npm run build:ts", diff --git a/packages/oslo-generator-rdf-vocabulary/package.json b/packages/oslo-generator-rdf-vocabulary/package.json index 8b957d6..2405be5 100644 --- a/packages/oslo-generator-rdf-vocabulary/package.json +++ b/packages/oslo-generator-rdf-vocabulary/package.json @@ -44,7 +44,11 @@ "/node_modules/", "index.js" ], - "testEnvironment": "node" + "testEnvironment": "node", + "moduleNameMapper": { + "^@oslo-core/(.*)$": "/../oslo-core/lib/$1", + "^@oslo-generator-rdf-vocabulary/(.*)$": "/lib/$1" + } }, "scripts": { "build": "npm run build:ts", diff --git a/packages/oslo-generator-rdf-vocabulary/test/RdfVocabularyGenerationService.unit.test.ts b/packages/oslo-generator-rdf-vocabulary/test/RdfVocabularyGenerationService.unit.test.ts index 88d6bb8..4c5c4df 100644 --- a/packages/oslo-generator-rdf-vocabulary/test/RdfVocabularyGenerationService.unit.test.ts +++ b/packages/oslo-generator-rdf-vocabulary/test/RdfVocabularyGenerationService.unit.test.ts @@ -14,7 +14,7 @@ import { jsonldAttributeWithoutAssignedUri, jsonldAttributeWithoutDomain, jsonldAttributeWithParent, - jsonldAttributeWithRangeStatement, + jsonldAttributeWithRange, jsonldClassWithoutAssignedUri, jsonldClassWithoutDefinition, jsonldClassWithParent, @@ -138,7 +138,7 @@ describe('RdfVocabularyGenerationService', () => { expect(quads.some((quad: RDF.Quad) => quad.subject.equals(df.namedNode('http://example.org/id/class/1')) && quad.predicate.equals(ns.vann('usageNote')) && - quad.object.equals(df.literal('A usage note', 'en')))) + quad.object.equals(df.literal('A vocabulary usage note', 'en')))) .toBe(true); }); @@ -262,17 +262,6 @@ describe('RdfVocabularyGenerationService', () => { expect(service.logger.error).toHaveBeenCalled(); }); - it('should search in rdf:Statements for the assigned URI of a range', async () => { - store.addQuads(await parseJsonld(jsonldAttributeWithRangeStatement)); - const quads = await service.createAttributeQuads(vocabularyUri); - - expect(quads.some((quad: RDF.Quad) => - quad.subject.equals(df.namedNode('http://example.org/id/property/1')) && - quad.predicate.equals(ns.rdfs('range')) && - quad.object.equals(df.namedNode('http://example.org/id/class/2')))) - .toBe(true); - }); - it('should add a link to the parent of the attribute it that information was found', async () => { store.addQuads(await parseJsonld(jsonldAttributeWithParent)); const quads = await service.createAttributeQuads(vocabularyUri); @@ -286,8 +275,8 @@ describe('RdfVocabularyGenerationService', () => { // eslint-disable-next-line max-len it('should log an error when the definition of the attribute could not be found in the requested language', async () => { - // This 'jsonldAttributeWithRangeStatement' snippet can also be used for this test - store.addQuads(await parseJsonld(jsonldAttributeWithRangeStatement)); + // This 'jsonldAttributeWithRange' snippet can also be used for this test + store.addQuads(await parseJsonld(jsonldAttributeWithRange)); jest.spyOn(service.logger, 'error'); await service.createAttributeQuads(vocabularyUri); diff --git a/packages/oslo-generator-rdf-vocabulary/test/data/mockData.ts b/packages/oslo-generator-rdf-vocabulary/test/data/mockData.ts index af2bb01..ae5cd7e 100644 --- a/packages/oslo-generator-rdf-vocabulary/test/data/mockData.ts +++ b/packages/oslo-generator-rdf-vocabulary/test/data/mockData.ts @@ -1,15 +1,15 @@ export const jsonldPackageWithoutAssignedUri = [ { '@id': 'http://example.org/.well-known/id/package/1', - '@type': 'http://example.org/Package', + '@type': 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#Package', }, ]; export const jsonldPackage = [ { '@id': 'http://example.org/.well-known/id/package/1', - '@type': 'http://example.org/Package', - 'http://example.org/assignedUri': { + '@type': 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#Package', + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/package/1', }, }, @@ -18,39 +18,39 @@ export const jsonldPackage = [ export const jsonldWithClassAndProperty = [ { '@id': 'http://example.org/.well-known/id/class/1', - 'http://example.org/assignedUri': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/class/1', }, '@type': 'http://www.w3.org/2002/07/owl#Class', - 'http://www.w3.org/2000/01/rdf-schema#label': [ + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#vocLabel': [ { '@language': 'en', '@value': 'TestClass', }, ], - 'http://www.w3.org/2000/01/rdf-schema#comment': [ + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#vocDefinition': [ { '@language': 'en', '@value': 'A comment', }, ], - 'http://purl.org/vocab/vann/usageNote': [ + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#vocUsageNote': [ { '@language': 'en', - '@value': 'A usage note', + '@value': 'A vocabulary usage note', }, ], - 'http://example.org/scope': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#scope': { '@id': 'https://data.vlaanderen.be/id/concept/scope/InPackage', }, }, { '@id': 'http://example.org/.well-known/id/property/1', - 'http://example.org/assignedUri': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/property/1', }, '@type': 'http://www.w3.org/2002/07/owl#DatatypeProperty', - 'http://www.w3.org/2000/01/rdf-schema#comment': [ + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#vocDefinition': [ { '@language': 'en', '@value': 'Comment on property', @@ -64,13 +64,13 @@ export const jsonldWithClassAndProperty = [ 'http://www.w3.org/2000/01/rdf-schema#range': { '@id': 'http://example.org/.well-known/id/class/1', }, - 'http://purl.org/vocab/vann/usageNote': [ + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#vocUsageNote': [ { '@language': 'en', '@value': 'A usage note of the property', }, ], - 'http://example.org/scope': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#scope': { '@id': 'https://data.vlaanderen.be/id/concept/scope/InPackage', }, }, @@ -80,7 +80,7 @@ export const jsonldClassWithoutAssignedUri = [ { '@id': 'http://example.org/id/.well-known/class/1', '@type': 'http://www.w3.org/2002/07/owl#Class', - 'http://example.org/scope': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#scope': { '@id': 'https://data.vlaanderen.be/id/concept/scope/InPackage', }, }, @@ -90,10 +90,10 @@ export const jsonldClassWithoutDefinition = [ { '@id': 'http://example.org/id/.well-known/class/1', '@type': 'http://www.w3.org/2002/07/owl#Class', - 'http://example.org/assignedUri': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/class/1', }, - 'http://example.org/scope': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#scope': { '@id': 'https://data.vlaanderen.be/id/concept/scope/InPackage', }, }, @@ -103,10 +103,10 @@ export const jsonldClassWithParent = [ { '@id': 'http://example.org/id/.well-known/class/1', '@type': 'http://www.w3.org/2002/07/owl#Class', - 'http://example.org/assignedUri': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/class/1', }, - 'http://www.w3.org/2000/01/rdf-schema#comment': [ + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#vocDefinition': [ { '@language': 'en', '@value': 'A comment', @@ -115,14 +115,14 @@ export const jsonldClassWithParent = [ 'http://www.w3.org/2000/01/rdf-schema#subClassOf': { '@id': 'http://example.org/id/.well-known/class/2', }, - 'http://example.org/scope': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#scope': { '@id': 'https://data.vlaanderen.be/id/concept/scope/InPackage', }, }, { '@id': 'http://example.org/id/.well-known/class/2', '@type': 'http://www.w3.org/2002/07/owl#Class', - 'http://example.org/assignedUri': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/class/2', }, }, @@ -132,10 +132,10 @@ export const jsonldParentWithoutAssignedUri = [ { '@id': 'http://example.org/id/.well-known/class/1', '@type': 'http://www.w3.org/2002/07/owl#Class', - 'http://example.org/assignedUri': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/class/1', }, - 'http://www.w3.org/2000/01/rdf-schema#comment': [ + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#vocDefinition': [ { '@language': 'en', '@value': 'A comment', @@ -144,7 +144,7 @@ export const jsonldParentWithoutAssignedUri = [ 'http://www.w3.org/2000/01/rdf-schema#subClassOf': { '@id': 'http://example.org/id/.well-known/class/2', }, - 'http://example.org/scope': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#scope': { '@id': 'https://data.vlaanderen.be/id/concept/scope/InPackage', }, }, @@ -158,7 +158,7 @@ export const jsonldAttributeWithoutAssignedUri = [ { '@id': 'http://example.org/.well-known/id/property/1', '@type': 'http://www.w3.org/2002/07/owl#DatatypeProperty', - 'http://example.org/scope': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#scope': { '@id': 'https://data.vlaanderen.be/id/concept/scope/InPackage', }, }, @@ -167,11 +167,11 @@ export const jsonldAttributeWithoutAssignedUri = [ export const jsonldAttributeWithoutDomain = [ { '@id': 'http://example.org/.well-known/id/property/1', - 'http://example.org/assignedUri': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/property/1', }, '@type': 'http://www.w3.org/2002/07/owl#DatatypeProperty', - 'http://example.org/scope': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#scope': { '@id': 'https://data.vlaanderen.be/id/concept/scope/InPackage', }, }, @@ -180,7 +180,7 @@ export const jsonldAttributeWithoutDomain = [ export const jsonldDomainWithoutAssignedUri = [ { '@id': 'http://example.org/.well-known/id/property/1', - 'http://example.org/assignedUri': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/property/1', }, '@type': 'http://www.w3.org/2002/07/owl#DatatypeProperty', @@ -189,7 +189,7 @@ export const jsonldDomainWithoutAssignedUri = [ '@id': 'http://example.org/.well-known/id/class/1', }, ], - 'http://example.org/scope': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#scope': { '@id': 'https://data.vlaanderen.be/id/concept/scope/InPackage', }, }, @@ -198,7 +198,7 @@ export const jsonldDomainWithoutAssignedUri = [ export const jsonldDomainWithoutRange = [ { '@id': 'http://example.org/.well-known/id/property/1', - 'http://example.org/assignedUri': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/property/1', }, '@type': 'http://www.w3.org/2002/07/owl#ObjectProperty', @@ -207,13 +207,13 @@ export const jsonldDomainWithoutRange = [ '@id': 'http://example.org/.well-known/id/class/1', }, ], - 'http://example.org/scope': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#scope': { '@id': 'https://data.vlaanderen.be/id/concept/scope/InPackage', }, }, { '@id': 'http://example.org/.well-known/id/class/1', - 'http://example.org/assignedUri': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/class/1', }, }, @@ -222,7 +222,7 @@ export const jsonldDomainWithoutRange = [ export const jsonldRangeWithoutAssignedUri = [ { '@id': 'http://example.org/.well-known/id/property/1', - 'http://example.org/assignedUri': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/property/1', }, '@type': 'http://www.w3.org/2002/07/owl#DatatypeProperty', @@ -236,22 +236,22 @@ export const jsonldRangeWithoutAssignedUri = [ '@id': 'http://example.org/.well-known/id/class/2', }, ], - 'http://example.org/scope': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#scope': { '@id': 'https://data.vlaanderen.be/id/concept/scope/InPackage', }, }, { '@id': 'http://example.org/.well-known/id/class/1', - 'http://example.org/assignedUri': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/class/1', }, }, ]; -export const jsonldAttributeWithRangeStatement = [ +export const jsonldAttributeWithRange = [ { '@id': 'http://example.org/.well-known/id/property/1', - 'http://example.org/assignedUri': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/property/1', }, '@type': 'http://www.w3.org/2002/07/owl#DatatypeProperty', @@ -265,38 +265,22 @@ export const jsonldAttributeWithRangeStatement = [ '@id': 'http://example.org/.well-known/id/class/2', }, ], - 'http://example.org/scope': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#scope': { '@id': 'https://data.vlaanderen.be/id/concept/scope/InPackage', }, }, { '@id': 'http://example.org/.well-known/id/class/1', - 'http://example.org/assignedUri': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/class/1', }, }, - { - '@id': 'http://example.org/id/.well-known/statement/1', - '@type': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement', - 'http://www.w3.org/1999/02/22-rdf-syntax-ns#subject': { - '@id': 'http://example.org/.well-known/id/property/1', - }, - 'http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate': { - '@id': 'http://www.w3.org/2000/01/rdf-schema#range', - }, - 'http://www.w3.org/1999/02/22-rdf-syntax-ns#object': { - '@id': 'http://example.org/.well-known/id/class/2', - }, - 'http://example.org/assignedUri': { - '@id': 'http://example.org/id/class/2', - }, - }, ]; export const jsonldAttributeWithParent = [ { '@id': 'http://example.org/.well-known/id/property/1', - 'http://example.org/assignedUri': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#assignedURI': { '@id': 'http://example.org/id/property/1', }, '@type': 'http://www.w3.org/2002/07/owl#DatatypeProperty', @@ -313,7 +297,7 @@ export const jsonldAttributeWithParent = [ 'http://www.w3.org/2000/01/rdf-schema#subPropertyOf': { '@id': 'http://example.org/id/parent/1', }, - 'http://example.org/scope': { + 'https://implementatie.data.vlaanderen.be/ns/oslo-toolchain#scope': { '@id': 'https://data.vlaanderen.be/id/concept/scope/InPackage', }, },