mardi 9 mars 2021

Upgrade from Angular 9 to 11, only issue with tests which don't get executed

I upgraded from Angular 9 to 11, after having installed ESlint and fixed all warning and issues, the project now get served and built successfully, only issue I got now it's with running unit test

Karma

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('@angular-devkit/build-angular/plugins/karma'),
      require('karma-spec-reporter'),
      require('karma-junit-reporter'),
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    reporters: ['spec', 'junit'],
    
    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: true,      // do not print information about skipped tests
      showSpecTiming: false,      // print the time elapsed for each spec
    },
    // karma-junit-reporter config (https://www.npmjs.com/package/karma-junit-reporter#configuration)
    junitReporter: {
      // REPORTS_DIRECTORY environment variable is expected to be defined in pom.xml
      // (see https://plugins.jenkins.io/pipeline-maven/)
      outputDir: process.env.REPORTS_DIRECTORY || 'target/karma-reports/',
      outputFile: 'TESTS.frontend-NAME.xml',
      suite: 'frontend-NAME', // suite will become the package name attribute in xml testsuite element
      useBrowserName: false, // add browser name to report and classes names
      nameFormatter: (browser, result) => result.description,
      // group all tests inside 'eu.COMPANY.PROJECT.ui' package, for better Jenkins visualization
      classNameFormatter: (browser, result) => 'eu.COMPANY.PROJECT.ui.' + result.suite.join('.')
    },
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: false,
    browsers: ['ChromiumHeadless'],
    singleRun: true,
  });
};

Karma local

// import base config file
var baseConfig = require('./karma.conf.js');

// export settings
module.exports = function (config) {
  // load base config
  baseConfig(config);
  // then the overrides
  config.set({
    // append to existing plugings
    plugins: config.plugins.concat([
      require('karma-jasmine-html-reporter'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage'),
    ]),
    // append to existing reporters
    reporters: config.reporters.concat(['progress', 'kjhtml']),
    jasmineHtmlReporter: {
      suppressAll: true // removes the duplicated traces
    },
    coverageReporter: {
      dir: require('path').join(__dirname, './coverage/PROJECT'),
      subdir: '.',
      reporters: [
        { type: 'html' },
        { type: 'text-summary' }
      ]
    },
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    restartOnFileChange: true
  });
};

The error getting after having run the local config is:

Generating browser application bundles (phase: building)...09 03 2021 08:46:11.693:WARN [karma]: No captured browser, open http://localhost:9876/
09 03 2021 08:46:11.705:INFO [karma-server]: Karma v6.1.1 server started at http://localhost:9876/
09 03 2021 08:46:11.706:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
09 03 2021 08:46:11.709:INFO [launcher]: Starting browser Chrome
✔ Browser application bundle generation complete.
09 03 2021 08:46:44.644:WARN [karma]: No captured browser, open http://localhost:9876/
09 03 2021 08:46:44.854:INFO [Chrome 89.0.4389.82 (Mac OS 10.15.6)]: Connected on socket VrX_mqflyya8IEbsAAAB with id 6097681
Chrome 89.0.4389.82 (Mac OS 10.15.6): Executed 0 of 0 SUCCESS (0 secs / 0 secs)
Chrome 89.0.4389.82 (Mac OS 10.15.6) ERROR
  An error was thrown in afterAll
Chrome 89.0.4389.82 (Mac OS 10.15.6) ERROR
  An error was thrown in afterAll
  Script error.
Chrome 89.0.4389.82 (Mac OS 10.15.6): Executed 0 of 0 ERROR (0 secs / 0 secs)
Chrome 89.0.4389.82 (Mac OS 10.15.6) ERROR
  An error was thrown in afterAll
Chrome 89.0.4389.82 (Mac OS 10.15.6): Executed 0 of 0 ERROR (0.013 secs / 0 secs)

Error in the console of the opened Karma tab

Uncaught SyntaxError: Unexpected token ' in JSON at position 1
    at JSON.parse (<anonymous>)
    at Module.W7Qn (:9876/_karma_webpack_/webpack:/testkit/mobile-import/mobile-import-test-data.ts:4)
    at __webpack_require__ (:9876/_karma_webpack_/webpack:/webpack/bootstrap:84)
    at Module.b8+U (:9876/_karma_webpack_/webpack:/src/app/common/modals/mobile-import-modal/mobile-import-modal.component.spec.ts:1)
    at __webpack_require__ (:9876/_karma_webpack_/webpack:/webpack/bootstrap:84)
    at webpackContext (:9876/_karma_webpack_/webpack:/src sync \.spec\.ts$:51)
    at Array.map (<anonymous>)
    at Module.CB3P (:9876/_karma_webpack_/webpack:/src/test.ts:29)
    at __webpack_require__ (:9876/_karma_webpack_/webpack:/webpack/bootstrap:84)
    at checkDeferredModules (:9876/_karma_webpack_/webpack:/webpack/bootstrap:45)

Aucun commentaire:

Enregistrer un commentaire