Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FE unit tests initial #47

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
dist
vendor
.tscache
coverage
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:11

RUN apt-get -qq update
RUN apt-get install -y chromium

RUN mkdir -p /opt/karma
WORKDIR /opt/karma
RUN npm install -g karma
CMD karma start
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,22 @@ With any changes done to backend, the binary file should be recompiled and *graf

* `docker run --rm -v ${PWD}:/go/src/github.com/ha/gcp -w /go/src/github.com/ha/gcp golang go build -i -o ./dist/cassandra-plugin_linux_amd64 ./backend`
* `docker-compose restart grafana`

### Unit Tests

#### Frontend, Docker Way (Recommended)

To build:
* `docker build -t docker-karma .`

To run:
* `docker run -p 9876:9876 -v $PWD:/opt/karma -i -t docker-karma`

To view detailed Unit testing report, open in browser: http://localhost:9876

#### Frontend, Locally
To run:
* `karma start`

To view detailed coverage report of the Unit tests, open in the browser: `coverage/index.html`

79 changes: 79 additions & 0 deletions docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

REPO="docker-karma"

HOST_MOUNT="$PWD"
CONTAINER_MOUNT="/opt/karma"

HOST_PORT="9876"
CONTAINER_PORT="9876"

function setup {
if [[ -z "$MOUNT" && -n "$HOST_MOUNT" && -n "$CONTAINER_MOUNT" ]]; then
MOUNT="-v $HOST_MOUNT:$CONTAINER_MOUNT"
fi

if [[ -z "$PORT" && -n "$HOST_PORT" && -n "$CONTAINER_PORT" ]]; then
PORT="-p $HOST_PORT:$CONTAINER_PORT"
fi
}

function build {
setup
docker build -rm -t $REPO .
}

function run {
setup
docker run -rm $PORT $MOUNT -i -t $REPO
}

function cleanup {
# Remove stopped containers
CONTAINERS=$(docker ps -a | grep 'Exit' | awk '{print $1}')
if [[ -n $CONTAINERS ]]; then
docker rm $CONTAINERS
fi

# Remove untagged images
IMAGES=$(docker images | grep "^<none>" | awk '{print $3}')
if [[ -n $IMAGES ]]; then
docker rmi $IMAGES
fi
}

function remove {
IMAGE=$(docker images | grep $REPO | awk '{print $3}')
if [[ -n $IMAGE ]]; then
docker rmi $IMAGE
fi
}

function usage {
echo "Usage: $0 [build | run | cleanup | remove]"
}

MOUNT=""
PORT=""
while [[ -n "$1" ]]; do
case $1 in
-v ) shift
MOUNT="-v $1"
;;
-p ) shift
PORT="-p $1"
;;
build ) build
;;
run ) run
;;
cleanup ) cleanup
;;
remove ) remove
;;
* ) usage
exit 1
;;
esac
shift
done
115 changes: 115 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
const isDocker = require('is-docker')();

module.exports = function(config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',

// list of files / patterns to load in the browser
files: [
'src/tests/*spec.ts',
'src/tests/*spec.js'
],

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'karma-typescript'],

plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('karma-typescript')
],

// specifying for karma-typescript on tsconfig.json
karmaTypescriptConfig: {
tsconfig: "./tsconfig.json",
},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'kjhtml', 'coverage-istanbul', 'karma-typescript'],

client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},

coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage'),
reports: ['html', 'lcovonly', 'text-summary'],
// Combines coverage information from multiple browsers into one report rather than outputting a report
// for each browser.
combineBrowserReports: true,

// if using webpack and pre-loaders, work around webpack breaking the source path
fixWebpackSourcePaths: true,

// Omit files with no statements, no functions and no branches covered from the report
skipFilesWithNoCoverage: true,

// output config used by istanbul for debugging
verbose: true
},

// list of files / patterns to exclude
exclude: [
],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
"**/*.ts": "karma-typescript" // *.tsx for React Jsx
},

// web server port
port: 9876,

// enable / disable colors in the output (reporters and logs)
colors: true,

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,

// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['ChromeNoSandboxHeadless'],
customLaunchers: {
ChromeNoSandboxHeadless: {
base: 'Chromium',
flags: isDocker ? [
'--no-sandbox',
// See https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
'--headless',
'--disable-gpu',
// Without a remote debugging port, Google Chrome exits immediately.
' --remote-debugging-port=9222'
] : []
}
},

// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
});
}
Loading