SAP/karma-ui5

Karma issue in Jenkins pipeline

tamiarah opened this issue · 1 comments

Hi colleagues,

We are currently facing the following issue, when we run our pipeline, where we also have a unit test step for our Karma + Jasmine tests:
image

We have 4 spec files - 2 of them always run through, but when it should start execute the other 2 specs, we often face the above error. With the second or third pipeline run, it finally runs through. However, it impedes our development extremely.
Unfortunately, I couldn't find any solution, when I searched for this error. I cannot reproduce this locally, it occurs only on our pipeline.

karma.conf.js is:

const path = require('path');
const failOnFirstRequest = require('../helper/failOnFirstRequest');

module.exports = function (config) {
    const pathToProjectRoot = '../../../../../';

    config.set({
        basePath: pathToProjectRoot + 'app/mkv_classes/',
        browsers: ['ChromeHeadless'],
        browserDisconnectTimeout: 60000,
        browserDisconnectTolerance: 4,
        browserNoActivityTimeout: 60000,

        files: ['webapp/test/**/*.spec.js'],
        exclude: [],

        ui5: {
            mode: 'script',
            type: 'application',
            url: 'https://sapui5.hana.ondemand.com',
            config: {
                bindingSyntax: 'complex',
                debug: false,
                inspect: true,
                async: false,
                resourceRoots: {
                    'com/sap/utilities/c4u/edom/mkv/mkv_classes': './base/webapp',
                },
            },
        },

        frameworks: ['ui5', 'jasmine', 'browserify'],
        reporters: ['junit', 'coverage', 'mocha'],

        specReporter: {
            maxLogLines: 5, // limit number of lines logged per test
            suppressErrorSummary: true, // do not print error summary
            suppressFailed: false, // do not print information about failed tests
            suppressPassed: false, // do not print information about passed tests
            suppressSkipped: false, // do not print information about skipped tests
            showSpecTiming: false, // print the time elapsed for each spec
            failFast: true, // test would finish with error when a first fail occurs.
        },
        mochaReporter: {
            ignoreSkipped: true,
        },
        junitReporter: {
            outputDir: '',
            outputFile: path.resolve(
                __dirname,
                pathToProjectRoot,
                's4hana_pipeline/reports/frontend-unit/Test-jasmine.tests.xml'
            ),
            suite: 'MKV application',
        },

        coverageReporter: {
            // specify a common output directory
            dir: path.join(__dirname, pathToProjectRoot, 's4hana_pipeline/reports/coverage-reports/frontend-unit/'),
            reporters: [
                {type: 'html', subdir: '/report-html/ut'},
                {type: 'lcov', subdir: 'report-lcosv'},
                {type: 'cobertura', subdir: 'app/mkv_classes', file: 'cobertura.frontend.unit.xml'},
                {type: 'text-summary'},
            ],
        },

        preprocessors: {
            'webapp/!(test)/**/*.js': 'coverage',
            'webapp/*.js': 'coverage',
            'webapp/test/**/*.spec.js': ['browserify'],
        },

        middleware: ['failOnFirstRequest'],
        plugins: [
            'karma-chrome-launcher',
            'karma-ui5',
            'karma-jasmine',
            'karma-junit-reporter',
            'karma-mocha-reporter',
            'karma-coverage',
            'karma-browserify',
            {
                'middleware:failOnFirstRequest': [
                    'factory',
                    function () {
                        return (req, res, next) => {
                            failOnFirstRequest(
                                (errorMessage) => {
                                    console.error(errorMessage);
                                    console.error('Exiting Karma');
                                    process.exit(1);
                                },
                                req,
                                res,
                                next
                            );
                        };
                    },
                ],
            },
        ],

        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: false,
        singleRun: true,
    });
};

package.json is:

{
    "name": "mkv_classes-ui",
    "version": "0.1.0",
    "private": true,
    "license": "UNLICENSED",
    "description": "",
    "dependencies": {},
    "devDependencies": {
        "@ui5/cli": "2.2.6",
        "browserify": "16.5.1",
        "cpy-cli": "3.1.1",
        "cross-env": "6.0.3",
        "jasmine-ajax": "4.0.0",
        "jasmine-core": "3.5.0",
        "karma": "4.4.1",
        "karma-browserify": "7.0.0",
        "karma-chrome-launcher": "3.1.0",
        "karma-cli": "2.0.0",
        "karma-coverage": "2.0.2",
        "karma-jasmine": "3.1.0",
        "karma-junit-reporter": "2.0.1",
        "karma-mocha-reporter": "2.2.5",
        "karma-ui5": "2.2.0",
        "lodash": "4.17.19",
        "rimraf": "3.0.2",
        "watchify": "3.11.1"
    },
    "scripts": {
        "build": "rimraf dist && ui5 build preload --include-task=generateManifestBundle generateCachebusterInfo && cpy ./xs-app.json dist",
        "test:unit": "cross-env NODE_ENV=unit karma start --browsers ChromeHeadless ./webapp/test/unit/karma.config.js",
        "test:unit:debug": "cross-env NODE_ENV=unit karma start --browsers Chrome ./webapp/test/unit/karma.config.js debug",
        "ci-frontend-unit-test": "npm run test:unit"
    },
    "engines": {
        "node": "^10.0.0"
    }
}

I already tried to find out more with the Log-Level 'Debug', but this doesn't give more information. I could imagine it is a config or version problem, but I am not sure.
Furthermore, our pipeline currently has space problems, not sure, if this plays a role for the above error.
Do you have any idea, how this could be solved?

Thank you very much already!
Best regards,
Christina

Hi Christina!

Thank you for filing this detailed issue.

However, I'm afraid that with the given information we can't provide you with any support at this moment. The described issue doesn't ring a bell for us.

There can be many causes for the error shown in the screenshot and it's quite possible that these are not directly related to karma-ui5. The fact that it only breaks infrequently might indicate an issue with your test setup or infrastructure and not with the configuration.