From 5504439ce023b5f236bfe0e09dd9baf79342b06c Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Wed, 2 Aug 2023 21:32:58 +0100 Subject: [PATCH] Add tests as a Docker build step to ensure no container with failing tests can be published Signed-off-by: Fred Boniface --- Dockerfile | 2 ++ package-lock.json | 22 ++++---------------- package.json | 2 +- src/utils/translators/ldb/staffStation.ts | 7 ++++--- test/utils/translators/ldb/stationOutputs.ts | 9 +++++--- 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/Dockerfile b/Dockerfile index 012f065..ae40001 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,8 @@ WORKDIR /usr/src/app COPY ./package*.json ./ RUN npm i COPY . . +# Ideally the tests should be run separately in a CI/CD workflow rather than during the build +RUN npm run test RUN npm run build FROM node:20-slim diff --git a/package-lock.json b/package-lock.json index 65258e7..52c181e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "zlib": "^1.0.5" }, "devDependencies": { - "@owlboard/ts-types": "^0.0.3", + "@owlboard/ts-types": "^0.0.5", "@types/jest": "^29.5.3", "eslint": "^8.39.0", "jest": "^29.6.2", @@ -1855,9 +1855,9 @@ } }, "node_modules/@owlboard/ts-types": { - "version": "0.0.3", - "resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fts-types/-/0.0.3/ts-types-0.0.3.tgz", - "integrity": "sha512-7PvFVNzYhIRsYxGPWLQVg1ldMSI0H6a5DA0WJ8dNT3boL+PREZybxA4rWUUKkcND+ct/nO8xax2SODYcWjY7Hw==", + "version": "0.0.5", + "resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fts-types/-/0.0.5/ts-types-0.0.5.tgz", + "integrity": "sha512-MuQlBydSXjHZIKQa6RgCdvDwHjFfG1wJXHioXPQno6GEdsxaDDoN06JCDkPf/l+hPjK/jMYrNNmVI1l5ZorYcg==", "dev": true, "license": "GPL-3.0-or-later" }, @@ -3964,20 +3964,6 @@ "dev": true, "license": "ISC" }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/function-bind": { "version": "1.1.1", "license": "MIT" diff --git a/package.json b/package.json index d4be9d8..5fdea18 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "zlib": "^1.0.5" }, "devDependencies": { - "@owlboard/ts-types": "^0.0.3", + "@owlboard/ts-types": "^0.0.5", "@types/jest": "^29.5.3", "eslint": "^8.39.0", "jest": "^29.6.2", diff --git a/src/utils/translators/ldb/staffStation.ts b/src/utils/translators/ldb/staffStation.ts index 71768fd..39db26d 100644 --- a/src/utils/translators/ldb/staffStation.ts +++ b/src/utils/translators/ldb/staffStation.ts @@ -89,10 +89,11 @@ function transformTrainServices(input: any): TrainServices[] { function transformLocation(input: any): ServiceLocation[] { console.debug(`staffStation.transformLocation running`) let output: ServiceLocation[] = [] - if (!Array.isArray(input)) { - input = [input] + let locations: any[] = input.location + if (!Array.isArray(input.location)) { + locations = [input.location] } - for (const item of input) { + for (const item of locations) { const location: ServiceLocation = { tiploc: item?.tiploc, name: item?.locationName diff --git a/test/utils/translators/ldb/stationOutputs.ts b/test/utils/translators/ldb/stationOutputs.ts index a4c36f8..2ea0d25 100644 --- a/test/utils/translators/ldb/stationOutputs.ts +++ b/test/utils/translators/ldb/stationOutputs.ts @@ -1,4 +1,7 @@ -export const outputs: any[] = [ +import type { StaffLdb, NrccMessage, TrainServices, + ServiceLocation } from '@owlboard/ts-types'; + +export const outputs: StaffLdb[] = [ { generatedAt: expect.any(Date), locationName: "Railway Station", @@ -25,13 +28,13 @@ export const outputs: any[] = [ origin: [ { tiploc: "PLYMTH", - locationName: "Plymouth" + name: "Plymouth" } ], destination: [ { tiploc: "BHAMNWS", - locationName: "Birmingham New Street" + name: "Birmingham New Street" } ] }