4

Fail to run tests in strict order.

package.json

{
  "version": "0.0.1",
  "description": "",
  "main": "./src/main.ts",
  "scripts": {

  },
  "devDependencies": {
    "@types/jasmine": "^2.8.9",
    "concurrently": "^4.0.1",
    "jasmine": "^3.3.0",
    "jasmine-core": "^3.3.0",
    "jasmine-spec-reporter": "~4.2.1",
    "jasmine-ts": "^0.3.0",
    "karma": "^3.1.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^1.4.0",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-typescript": "^3.0.13",
    "karma-webpack": "^3.0.5",
    "lite-server": "^2.4.0",
    "source-map-loader": "^0.2.4",
    "ts-loader": "^5.2.2",
    "typescript": "^3.1.3",
    "webpack": "^4.23.1"
  },
  "dependencies": {}
}

karma.config.ts

const webpackConfig = require('./webpack.config');
delete webpackConfig.entry;
webpackConfig.mode = "development";
webpackConfig.devtool = 'inline-source-map';

module.exports = function(config) {
  config.set({
      frameworks: ["jasmine", "karma-typescript"],
      files: [
        "spec/client.spec.ts",
        { pattern: './build/*.css', watched: true, served: true, included: true },
      ],
      preprocessors: {
          "**/*.ts": ['webpack', 'sourcemap']
      },
      webpack: webpackConfig,
      reporters: ["progress", "kjhtml"],
      browsers: ["Chrome"],
      karmaTypescriptConfig: {
        "compilerOptions": {
            "target": "es6",
            "lib": ["es5", "es6", "dom"],
          }
      },
      /*
      client: {
        jasmine: {
          random: false
        }
      }
      */
  });
};

Test (spec/client.spec.ts)

/// <reference path="../node_modules/@types/jasmine/index.d.ts" />

jasmine.DEFAULT_TIMEOUT_INTERVAL = 900000;

console.log('Init');

describe('[client]', () => {
    console.log('Spec declarations');

    it('[Test 1]', (done) => {
        console.log('Test 1: started');
        // Async stuff here
        // ...
        // ...
        expect(true).toBe(true);
        done();
    });

    it('[Test 2]', (done) => {
        console.log('Test 2: started');
        // Async stuff here
        // ...
        // ...
        expect(true).toBe(true);
        done();
    });

    it('[Test 3]', (done) => {
        console.log('Test 3: started');
        // Async stuff here
        // ...
        // ...
        expect(true).toBe(true);
        done();
    });

    it('[Test 4]', (done) => {
        console.log('Test 4: started');
        // Async stuff here
        // ...
        // ...
        expect(true).toBe(true);
        done();
    });


});

The situation is next. If I comment out in karma.config.js settings of jasmine: everything works, but all tests are running in random order.

As results I see the output in browser console:

  • init

  • Spec declarations

  • Test 4: started

  • Test 1: started

  • Test 2: started

  • Test 3: started

The thing is I need a strict order of test's executing: 1, 2, 3 and 4.

If I add settings for jasmine like:

client: { jasmine: { random: false } }

tests didn't run at all. And in the output of browser console I see only:

  • init

  • Spec declarations

All tests work asynchronously.

I've killed tons of time, would be great if someone advice solution.

  • Looks like unsupported feature: https://github.com/karma-runner/karma-jasmine/issues/226 – Dmitry Astafyev Nov 08 '18 at 16:58
  • Someone commented on that github issue page on Dec 18, 2018: [I am able to run my tests in order consistently](https://github.com/karma-runner/karma-jasmine/issues/226#issuecomment-448265030). You may need to use version 3.3 or higher of jasmine. – tedw Sep 16 '19 at 16:02
  • 1
    I just tested and I am able to run the tests in order with `jasmine-core: 3.4.0` and `karma-jasmine: 2.0.1` – tedw Sep 16 '19 at 16:09

0 Answers0