Skip to content

Commit

Permalink
feature: unit test via karma jasmine
Browse files Browse the repository at this point in the history
* ChromeHeadlessCustom mode
* apt install chrome
  • Loading branch information
askonev committed Apr 5, 2024
1 parent f0ac3ce commit 192170d
Show file tree
Hide file tree
Showing 8 changed files with 12,057 additions and 7,424 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/jasmine.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Karma Jasmine Tests

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
units:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Build Docker image
run: docker build -t jasmine -f ./docker-build/docker-actions/Dockerfile

- name: Run test
run: docker run jasmine
18 changes: 18 additions & 0 deletions docker-build/docker-actions/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:16.17.1-buster

# Install necessary dependencies
RUN apt-get update \
&& apt-get install -y wget gnupg \
&& wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update \
&& apt-get install -y google-chrome-stable \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir /palladium-view
WORKDIR /palladium-view
COPY . /palladium-view

RUN npm install

CMD ["npm" "run" "ng" "test"]
59 changes: 59 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const { Server } = require("karma");

module.exports = function (config) {
config.set({
basePath: "",
frameworks: ["jasmine", "@angular-devkit/build-angular"],
plugins: [
require("karma-jasmine"),
require("karma-chrome-launcher"),
require("karma-jasmine-html-reporter"),
require("karma-coverage-istanbul-reporter"),
require("@angular-devkit/build-angular/plugins/karma"),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require("path").join(__dirname, "./coverage/palladium"),
reports: ["html", "lcovonly", "text-summary"],
fixWebpackSourcePaths: true,
},
reporters: ["progress", "kjhtml"],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ["Chrome"],
singleRun: true,
customLaunchers: {
ChromeHeadlessCustom: {
base: "ChromeHeadless",
flags: [
"--disable-gpu", // Disable hardware acceleration
"--no-sandbox", // Needed when running as root user in Docker
"--headless",
"--disable-dev-shm-usage", // Fixes issues with Docker memory limitations
"--disable-setuid-sandbox", // not recommended for security reasons but sometimes necessary
],
},
},
browsers: ['ChromeHeadlessCustom'],
restartOnFileChange: true,
files: [
{
pattern: "src/**/*.spec.ts",
watched: true,
included: false,
served: false,
},
],
httpsServerOptions: { // disable SSL certificate checks
key: '',
cert: '',
ca: '',
requestCert: false,
rejectUnauthorized: false
}
});
};
Loading

0 comments on commit 192170d

Please sign in to comment.