Add build and test stages.

This commit is contained in:
Spencer Ofwiti 2020-11-25 13:26:00 +03:00
parent 13ac7fe77c
commit 4091b04c03
5 changed files with 98 additions and 7 deletions

View File

@ -1,6 +1,11 @@
stages: stages:
- install - install
variables:
PROJECT_PATH: "$CI_PROJECT_DIR"
APP_OUTPUT_PATH: "$CI_PROJECT_DIR/artifacts/app"
OUTPUT_PATH: "$CI_PROJECT_DIR/artifacts"
install_dependencies: install_dependencies:
stage: install stage: install
image: node:15-alpine3.10 image: node:15-alpine3.10
@ -21,3 +26,53 @@ install_dependencies:
- master - master
changes: changes:
- package-lock.json - package-lock.json
build_app:
stage: build_and_test
image: node:15-alpine3.10
tags:
- docker
script:
- ng build --prod
after_script:
- mv $PROJECT_PATH/nginx.conf $PROJECT_PATH/default.conf
- cp $PROJECT_PATH/default.conf $APP_OUTPUT_PATH
- cp $PROJECT_PATH/Dockerfile $APP_OUTPUT_PATH
artifacts:
name: "cic-staff-client-pipeline"
paths:
- $APP_OUTPUT_PATH
cache:
key:
files:
- package-lock.json
paths:
- node_modules
policy: pull
test_app:
stage: build_and_test
image: node:15-alpine3.10
tags:
- docker
before_script:
- apk add chromium
- export CHROME_BIN=/usr/bin/chromium-browser
script:
- ng lint
- ng test --code-coverage --watch=false --browsers=GitlabChromeHeadless
coverage: '/Statements\s+:\s\d+.\d+%/'
artifacts:
name: "tests-and-coverage"
reports:
junit:
- $OUTPUT_PATH/tests/junit-test-results.xml
cobertura:
- $OUTPUT_PATH/coverage/cobetura-coverage.xml
cache:
key:
files:
- package-lock.json
paths:
- node_modules
policy: pull

View File

@ -17,7 +17,7 @@
"build": { "build": {
"builder": "@angular-devkit/build-angular:browser", "builder": "@angular-devkit/build-angular:browser",
"options": { "options": {
"outputPath": "dist/cic-staff-client", "outputPath": "artifacts/app",
"index": "src/index.html", "index": "src/index.html",
"main": "src/main.ts", "main": "src/main.ts",
"polyfills": "src/polyfills.ts", "polyfills": "src/polyfills.ts",

View File

@ -7,6 +7,7 @@ module.exports = function (config) {
frameworks: ['jasmine', '@angular-devkit/build-angular'], frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [ plugins: [
require('karma-jasmine'), require('karma-jasmine'),
require('karma-junit-reporter'),
require('karma-chrome-launcher'), require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'), require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'), require('karma-coverage-istanbul-reporter'),
@ -16,17 +17,33 @@ module.exports = function (config) {
clearContext: false // leave Jasmine Spec Runner output visible in browser clearContext: false // leave Jasmine Spec Runner output visible in browser
}, },
coverageIstanbulReporter: { coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/cic-staff-client'), dir: require('path').join(__dirname, './artifacts/coverage'),
reports: ['html', 'lcovonly', 'text-summary'], reports: ['html', 'lcovonly', 'text-summary', 'cobertura'],
fixWebpackSourcePaths: true fixWebpackSourcePaths: true,
'report-config': {
'text-summary': {
file: 'text-summary.txt'
}
},
}, },
reporters: ['progress', 'kjhtml'], junitReporter: {
outputDir: 'artifacts/tests',
outputFile: 'junit-test-results.xml',
useBrowserName: false
},
reporters: ['progress', 'kjhtml', 'junit'],
port: 9876, port: 9876,
colors: true, colors: true,
logLevel: config.LOG_INFO, logLevel: config.LOG_INFO,
autoWatch: true, autoWatch: true,
browsers: ['Chrome'], browsers: ['Chrome'],
singleRun: false, singleRun: false,
restartOnFileChange: true restartOnFileChange: true,
customLaunchers: {
GitlabHeadlessChrome: {
base: 'ChromeHeadless',
flags: ['--no-sandbox'],
},
},
}); });
}; };

18
package-lock.json generated
View File

@ -7032,6 +7032,24 @@
"integrity": "sha512-PtilRLno5O6wH3lDihRnz0Ba8oSn0YUJqKjjux1peoYGwo0AQqrWRbdWk/RLzcGlb+onTyXAnHl6M+Hu3UxG/Q==", "integrity": "sha512-PtilRLno5O6wH3lDihRnz0Ba8oSn0YUJqKjjux1peoYGwo0AQqrWRbdWk/RLzcGlb+onTyXAnHl6M+Hu3UxG/Q==",
"dev": true "dev": true
}, },
"karma-junit-reporter": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/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://registry.npmjs.org/xmlbuilder/-/xmlbuilder-12.0.0.tgz",
"integrity": "sha512-lMo8DJ8u6JRWp0/Y4XLa/atVDr75H9litKlb2E5j3V3MesoL50EBgZDWoLT3F/LztVnG67GjPXLZpqcky/UMnQ==",
"dev": true
}
}
},
"karma-source-map-support": { "karma-source-map-support": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/karma-source-map-support/-/karma-source-map-support-1.4.0.tgz", "resolved": "https://registry.npmjs.org/karma-source-map-support/-/karma-source-map-support-1.4.0.tgz",

View File

@ -27,9 +27,9 @@
"@angular-devkit/build-angular": "~0.1002.0", "@angular-devkit/build-angular": "~0.1002.0",
"@angular/cli": "~10.2.0", "@angular/cli": "~10.2.0",
"@angular/compiler-cli": "~10.2.0", "@angular/compiler-cli": "~10.2.0",
"@types/node": "^12.11.1",
"@types/jasmine": "~3.5.0", "@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3", "@types/jasminewd2": "~2.0.3",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0", "codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0", "jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0", "jasmine-spec-reporter": "~5.0.0",
@ -38,6 +38,7 @@
"karma-coverage-istanbul-reporter": "~3.0.2", "karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~4.0.0", "karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0", "karma-jasmine-html-reporter": "^1.5.0",
"karma-junit-reporter": "^2.0.1",
"protractor": "~7.0.0", "protractor": "~7.0.0",
"ts-node": "~8.3.0", "ts-node": "~8.3.0",
"tslint": "~6.1.0", "tslint": "~6.1.0",