Run angular tests on Jenkins
MODIFY
Dockerfile
Dockerfile
-FROM node:12.18.0-alpine as node
-
-WORKDIR /usr/src/app
-
-COPY package*.json ./
-
-RUN npm install
-#copy the rest of the project into the image
-COPY . .
+FROM devportal-base:latest as base
RUN npm run build-production
# Stage 2
FROM nginx:1.17.10-alpine
-COPY --from=node /usr/src/app/dist/api-mgmt-dev-portal /usr/share/nginx/html
+COPY --from=base /usr/src/app/dist/api-mgmt-dev-portal /usr/share/nginx/html
#copy ssl keys
COPY docker/tls.crt /etc/ssl/certs/tls.crt

MODIFY
Jenkinsfile
Jenkinsfile
@@ -48,6 +48,36 @@ pipeline {
}
}
+ stage('Prepare base docker image') {
+ steps {
+ sh """
+ docker build -t devportal-base:latest -f ./docker/images/base/Dockerfile .
+ docker build -t devportal-tests:latest -f ./docker/images/test/Dockerfile .
+ """
+ }
+ }
+
+ stage('Tests') {
+ agent {
+ docker {
+ image 'devportal-tests:latest'
+ label 'docker'
+ args '-u root:root'
+ }
+ }
+ steps {
+ sh "cd '/usr/src/app/' && npm run test"
+ /* copy test result into workspace destination */
+ sh "cp -r /usr/src/app/junit/* ./junit"
+ }
+ post {
+ always {
+ /* collect the test results */
+ junit "junit/api-mgmt-dev-portal/*.xml*"
+ }
+ }
+ }
+
stage('Build docker image') {
steps {
sh """
@@ -143,7 +173,11 @@ pipeline {
stage('Remove container image') {
steps {
- sh "docker image rm -f api-mgmt/devportal:${PACKAGE_VERSION}"
+ sh """
+ docker image rm -f api-mgmt/devportal:${PACKAGE_VERSION} || true
+ docker image rm devportal-tests:latest || true
+ docker image rm devportal-base:latest || true
+ """
}
}

ADD
docker/images/base/Dockerfile
+FROM node:12.18.0
+
+# Start with npm tasks
+WORKDIR /usr/src/app
+
+COPY package*.json ./
+
+RUN npm install
+#copy the rest of the project into the image
+COPY . .

ADD
docker/images/test/Dockerfile
+FROM devportal-base:latest
+
+RUN apt-get -qqy update \
+ && apt-get -qqy install chromium

MODIFY
karma.conf.js
karma.conf.js
@@ -8,8 +8,8 @@ module.exports = function (config) {
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
- require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
+ require('karma-junit-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
@@ -17,15 +17,25 @@ module.exports = function (config) {
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/api-mgmt-dev-portal'),
- reports: ['html', 'lcovonly', 'text-summary'],
+ reports: ['lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
- reporters: ['progress', 'kjhtml'],
+ reporters: ['junit','progress'],
+ junitReporter: {
+ outputDir: require('path').join(__dirname, './junit/api-mgmt-dev-portal'),
+ suite: 'models'
+ },
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
- browsers: ['Chrome'],
+ browsers: ['Chromium'],
+ customLaunchers: {
+ Chromium: {
+ base: 'ChromiumHeadless',
+ flags: ['--no-sandbox']
+ }
+ },
singleRun: false,
restartOnFileChange: true
});

MODIFY
package-lock.json
package-lock.json
"jasmine-core": "^3.3"
}
},
- "karma-jasmine-html-reporter": {
- "version": "1.4.2",
- "resolved": "https://gitlab.scheer-group.com:8080/repository/npm_group/karma-jasmine-html-reporter/-/karma-jasmine-html-reporter-1.4.2.tgz",
- "integrity": "sha512-7g0gPj8+9JepCNJR9WjDyQ2RkZ375jpdurYQyAYv8PorUCadepl8vrD6LmMqOGcM17cnrynBawQYZHaumgDjBw==",
+ "karma-junit-reporter": {
+ "version": "2.0.1",
+ "resolved": "https://gitlab.scheer-group.com:8080/repository/npm_group/karma-junit-reporter/-/karma-junit-reporter-2.0.1.tgz",
+ "integrity": "sha512-VtcGfE0JE4OE1wn0LK8xxDKaTP7slN8DO3I+4xg6gAi1IoAHAXOJ1V9G/y45Xg6sxdxPOR3THCFtDlAfBo9Afw==",
+ "dev": true,
+ "requires": {
+ "path-is-absolute": "^1.0.0",
+ "xmlbuilder": "12.0.0"
+ },
+ "dependencies": {
+ "xmlbuilder": {
+ "version": "12.0.0",
+ "resolved": "https://gitlab.scheer-group.com:8080/repository/npm_group/xmlbuilder/-/xmlbuilder-12.0.0.tgz",
+ "integrity": "sha512-lMo8DJ8u6JRWp0/Y4XLa/atVDr75H9litKlb2E5j3V3MesoL50EBgZDWoLT3F/LztVnG67GjPXLZpqcky/UMnQ==",
"dev": true
+ }
+ }
},
"karma-source-map-support": {
"version": "1.4.0",

MODIFY
package.json
package.json
"start": "ng serve",
"build": "ng build",
"build-production": "ng build --prod",
- "test": "ng test",
+ "test": "ng test --reporters junit --watch=false",
"lint": "ng lint",
"e2e": "ng e2e"
},
"@angular/cli": "~9.1.8",
"@angular/compiler-cli": "~9.1.11",
"@angular/language-service": "~9.1.11",
- "@types/node": "~12.12.47",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
+ "@types/node": "~12.12.47",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
- "karma-jasmine-html-reporter": "^1.4.0",
+ "karma-junit-reporter": "^2.0.1",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",

GW-384: Run angular tests on Jenkins