Automate karma test in CI
Signed-off-by: ecaiyanlinux <martin.c.yan@est.tech>
Change-Id: Ic7c9896863d18e2a82d5f88998efc06fcfc4e6f0
Issue-Id: NONRTRIC-430
diff --git a/webapp-frontend/Dockerfile b/webapp-frontend/Dockerfile
index c711e47..30d5c2c 100644
--- a/webapp-frontend/Dockerfile
+++ b/webapp-frontend/Dockerfile
@@ -17,9 +17,17 @@
### STAGE 1: Build App ###
FROM node:14-alpine AS stage1
WORKDIR /usr/src/app
-COPY package*.json ./
+COPY package.json ./
RUN npm install
COPY . .
+
+# RUN karma test
+RUN apk update
+RUN apk add chromium
+RUN export CHROME_BIN=/usr/bin/chromium-browser
+ENV CHROME_BIN /usr/bin/chromium-browser
+RUN ./ng test --browsers ChromeHeadless --code-coverage=true --watch=false
+
RUN npm run-script build
### STAGE 2: Run App ###
diff --git a/webapp-frontend/angular.json b/webapp-frontend/angular.json
index 2dc54e2..817e32c 100644
--- a/webapp-frontend/angular.json
+++ b/webapp-frontend/angular.json
@@ -165,5 +165,8 @@
}
}
},
- "defaultProject": "controlpanelApp"
+ "defaultProject": "controlpanelApp",
+ "cli": {
+ "analytics": false
+ }
}
\ No newline at end of file
diff --git a/webapp-frontend/package.json b/webapp-frontend/package.json
index 7ba20bc..e902947 100644
--- a/webapp-frontend/package.json
+++ b/webapp-frontend/package.json
@@ -56,7 +56,7 @@
"codelyzer": "^5.1.2",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
- "karma": "~3.1.1",
+ "karma": "^6.1.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^2.1.1",
"karma-jasmine": "~1.1.2",
diff --git a/webapp-frontend/src/karma.conf.js b/webapp-frontend/src/karma.conf.js
index 421a75d..681ae18 100644
--- a/webapp-frontend/src/karma.conf.js
+++ b/webapp-frontend/src/karma.conf.js
@@ -44,7 +44,19 @@
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
- browsers: ['Chrome'],
+ browsers: ['Chrome','ChromeHeadless'],
+ customLaunchers: {
+ ChromeHeadless: {
+ base: 'Chrome',
+ flags: [
+ '--no-sandbox',
+ '--headless',
+ '--disable-gpu',
+ '--remote-debugging-port=9222'
+ ]
+ }
+ },
+ browserDisconnectTimeout: 60000,
singleRun: false
});
};