SAP/karma-ui5

Karma failed on Jenkins sometime

haorannnnn opened this issue · 1 comments

Hi colleagues,

We have an issue about running karma coverage by Jenkins job, sometime it's successful, but sometime it's failed, and it's not stable. (However, it's weird that this issue only occurs on Jenkins, when we run karma locally, it's always successful. )

The Jenkins error logs:

15:05:43  Loading "xml_validator.coffee" tasks...ERROR
15:05:43  >> Error: Grunt attempted to load a .coffee file but CoffeeScript was not installed.
15:05:43  >> Please run `npm install --dev coffeescript` to enable loading CoffeeScript.
15:05:43  
15:05:43  Running "clean:coverage" (clean) task
15:05:43  >> 0 paths cleaned.
15:05:43  
15:05:43  Running "karma:coverage" (karma) task
15:05:43  �[32m03 11 2021 08:05:43.530:INFO [karma]: �[39mKarma v2.0.5 server started at http://0.0.0.0:9876/
15:05:43  �[32m03 11 2021 08:05:43.532:INFO [launcher]: �[39mLaunching browser Chrome with unlimited concurrency
15:05:43  �[32m03 11 2021 08:05:43.536:INFO [launcher]: �[39mStarting browser Chrome
15:05:44  �[32m03 11 2021 08:05:44.113:INFO [Chrome 70.0.3538 (Linux 0.0.0)]: �[39mConnected on socket xxx with id xxx
15:05:48  Chrome 70.0.3538 (Linux 0.0.0) ERROR
15:05:48    {
15:05:48      "message": "Uncaught ReferenceError: sap is not defined\nat webapp/test/karma-main.js:7:3\n\nReferenceError: sap is not defined\n    at webapp/test/karma-main.js:7:3\n    at webapp/test/karma-main.js:24:3",
15:05:48      "str": "Uncaught ReferenceError: sap is not defined\nat webapp/test/karma-main.js:7:3\n\nReferenceError: sap is not defined\n    at webapp/test/karma-main.js:7:3\n    at webapp/test/karma-main.js:24:3"
15:05:48    }

At first, we doubt it's caused by karma-openui5 and need to migrate it to karma-ui5 by following guideline https://github.com/SAP/karma-ui5/blob/master/docs/migrate-v1.md. But after migration, it still doesn't works, this issue is still existed. This is our current karma configuration:
package.json:

"engines": {
    "node": ">=3.0.0"
  },
  "scripts": {
    "test": "grunt test"
  },
  "dependencies": {
    "archiver": "^3.0.0",
    "grunt-contrib-clean": "^1.1.0",
    "grunt-contrib-copy": "^1.0.0",
    "grunt-contrib-cssmin": "^2.2.1",
    "grunt-contrib-uglify": "^5.0.1",
    "grunt-eslint": "^20.1.0",
    "grunt-jsonlint": "^1.1.0",
    "grunt-karma": "^2.0.0",
    "grunt-mkdir": "^1.0.0",
    "grunt-openui5": "^0.12.0",
    "grunt-xml-validator": "^1.1.3",
    "karma": "^2.0.0",
    "karma-chrome-launcher": "^2.2.0",
    "karma-coverage": "^1.1.1",
    "karma-qunit": "^1.2.1",
    "karma-sinon": "^1.0.5",
    "karma-ui5": "^2.3.4",
    "qunitjs": "^2.4.1",
    "sinon": "^5.0.9"
  },
  "devDependencies": {
    "grunt": "^1.1.0",
    "grunt-cli": "^1.2.0",
    "grunt-contrib-jshint": "^0.9.2",
    "grunt-contrib-nodeunit": "^0.3.3",
    "eslint-config-ems-ui": "latest"
  },
  "peerDependencies": {
    "karma-junit-reporter": "^1.2.0",
    "karma-webdriver-launcher": "^1.0.0"
  },
  "keywords": [
    "gruntplugin"
  ]

karma.conf.js:


    karma: {
      options: {
        basePath: './',
        frameworks: ['ui5', 'qunit', 'sinon'],
        ui5: {
          url: 'https://sapui5.hana.ondemand.com/1.84.20',
          mode: 'script',
          config: {
            theme: 'sap_belize',
            libs: 'sap.ui.core, sap.m, sap.ushell, sap.ui.layout, sap.ui.unified, sap.ui.comp, sap.ui.table, sap.f, sap.uxap',
            language: 'EN',
            bindingSyntax: 'complex',
            compatVersion: 'edge',
            preload: 'async'
          }
        },
        client: {
          qunit: {
            showUI: true
          },
          continuum: {
            ampApiToken: null,
            ampOrgId: null,
            ampAssetId: null,
            ignoreViolationIds: [364] /* ignore violation id */,
            defaultStandardIds: [
              1387, 1388, 1389
            ] /* WCAG 2.1 Level A, AA, AAA */,
            minSeverityLevel: 0 /* low: 1-3, medium: 4-7, high: 8-10 */
          }
        },
        files: [
          {
            pattern: 'node_modules/grunt-ems/lib/continuum.conf.js',
            included: true,
            served: true,
            watched: true
          },
          {
            pattern:
              'node_modules/grunt-ems/lib/continuum-continuum-javascript-professional-4.7.0/AccessEngine.*.js',
            included: true,
            served: true,
            watched: true
          },
          {
            pattern:
              'node_modules/grunt-ems/lib/continuum-continuum-javascript-professional-4.7.0/Continuum.*.js',
            included: true,
            served: true,
            watched: true
          },
          {
            pattern: 'node_modules/grunt-ems/lib/continuum-karma.js',
            included: true,
            served: true,
            watched: true
          },
          {
            pattern: 'webapp/test/karma-main.js',
            included: true,
            served: true,
            watched: true
          },
          {
            pattern: 'webapp/**',
            included: false,
            served: true,
            watched: true
          },
          {
            pattern: 'node_modules/ems-ui-lib/**',
            included: false,
            served: true,
            watched: true
          }
        ],
        proxies: {
          '/base/webapp/lib': '/base/node_modules/ems-ui-lib/src/sap/ems/ui',
          '/resources/sap/ems/ui':
            '/base/node_modules/ems-ui-lib/src/sap/ems/ui',
          '/webapp/resources/sap/ems/ui':
            '/base/node_modules/ems-ui-lib/src/sap/ems/ui',
          '/base/webapp/test-resources': {
            target: 'https://sapui5.hana.ondemand.com/test-resources',
            changeOrigin: true
          },
          '/test-resources': {
            target: 'https://sapui5.hana.ondemand.com/test-resources',
            changeOrigin: true
          },
          '/resources': {
            target: 'https://sapui5.hana.ondemand.com/resources',
            changeOrigin: true
          }
        },
        reporters: ['progress'],
        port: 9876,
        logLevel: 'INFO',
        browsers: ['Chrome'],
        colors: true,
        captureTimeout: 180000,
        browserNoActivityTimeout: 900000,
        browserDisconnectTolerance: 3,
        browserDisconnectTimeout: 900000
      },
      coverage: {
        singleRun: true,
        browsers: ['Chrome'],
        preprocessors: {
          'webapp/*.js': ['coverage'],
          'webapp/!(test|localService|lib)/**/*.js': ['coverage']
        },
        coverageReporter: {
          includeAllSources: true,
          reporters: [
            {
              type: 'html',
              dir: './coverage/'
            },
            {
              type: 'text'
            },
            {
              type: 'cobertura',
              subdir: 'cobertura',
              file: 'coverage.xml'
            }
          ],
          check: {
            each: {
              statements: 0,
              branches: 0,
              functions: 0,
              lines: 0
            }
          }
        },
        reporters: ['progress', 'coverage']
      },
      watch: {
        client: {
          clearContext: false
        }
      }
    },

Then we change to a new dock image which has a higher-version node.js and chrome, but it still doesn't work.

10:33:43  + node -v
10:33:43  v14.18.1
10:33:44  Running "karma:coverage" (karma) task
10:33:45  (node:44) Warning: Accessing non-existent property 'VERSION' of module exports inside circular dependency
10:33:45  (Use `node --trace-warnings ...` to show where the warning was created)
10:33:45  �[32m05 11 2021 03:33:45.169:INFO [karma]: �[39mKarma v2.0.5 server started at http://0.0.0.0:9876/
10:33:45  �[32m05 11 2021 03:33:45.171:INFO [launcher]: �[39mLaunching browser Chrome with unlimited concurrency
10:33:45  �[32m05 11 2021 03:33:45.174:INFO [launcher]: �[39mStarting browser Chrome
10:33:45  �[32m05 11 2021 03:33:45.593:INFO [Chrome 95.0.4638 (Linux 0.0.0)]: �[39mConnected on socket xxx with id xxx
10:33:49  Chrome 95.0.4638 (Linux 0.0.0) ERROR
10:33:49    {
10:33:49      "message": "Uncaught ReferenceError: jQuery is not defined\nat node_modules/grunt-ems/lib/continuum-karma.js:9:5\n\nReferenceError: jQuery is not defined\n    at node_modules/grunt-ems/lib/continuum-karma.js:9:5\n    at node_modules/grunt-ems/lib/continuum-karma.js:15:3",
10:33:49      "str": "Uncaught ReferenceError: jQuery is not defined\nat node_modules/grunt-ems/lib/continuum-karma.js:9:5\n\nReferenceError: jQuery is not defined\n    at node_modules/grunt-ems/lib/continuum-karma.js:9:5\n    at node_modules/grunt-ems/lib/continuum-karma.js:15:3"
10:33:49    }

Could you please kindly help us to check why karma sometime failed on Jenkins job ?
Thanks a lot.

matz3 commented

I'm not sure whether we can really help here. The error message appears in a package that doesn't seem to be part of the public npm registry (grunt-ems).
Also there is much more involved than just the karma-ui5 plugin, so I'd like to suggest that you try to pin-point this issue to a specific module.
The code seems to use jQuery, but it doesn't seem to be loaded (yet). So this sounds like a timing issue where it's not ensured that jQuery has been loaded already, which can be different due to CPU load and speed.