karma-runner / karma-jasmine

A Karma plugin - adapter for Jasmine testing framework.
MIT License
542 stars 162 forks source link

{random = false} has unexpected behaviour #226

Closed DmitryAstafyev closed 5 years ago

DmitryAstafyev commented 6 years ago

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.

Related: https://stackoverflow.com/questions/53199798/karma-jasmin-ordered-test-running

johnjbarton commented 6 years ago

Switch back to an older version of Jasmine. Your problem should be fixed in the next release, when we support 3.3.

On Thu, Nov 8, 2018, 12:51 AM DmitryAstafyev <notifications@github.com wrote:

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)

///

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.

Related: https://stackoverflow.com/questions/53199798/karma-jasmin-ordered-test-running

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/karma-runner/karma-jasmine/issues/226, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMjAr_hw9For0LMTNJo4aXax2v5Dt84ks5us_CUgaJpZM4YUPPn .

rorymcgit commented 5 years ago

I think this is fixed now. My project has below dependencies and I am able to run my tests in order consistently, without the previous this.deprecated is not a function error

EDIT: Yes it looks like it's been fixed in #224

module.exports = function (config) {
  config.set({
...
      client: {
        jasmine: {
          random: false
        }
      }
  });
├─ @types/jasmine@2.8.12
├─ @types/jasminewd2@2.0.6
│  ├─ @types/jasmine@*
│  └─ @types/jasmine@3.3.0
├─ jasmine-core@3.3.0
├─ jasmine-spec-reporter@4.2.1
├─ jasmine@2.8.0
│  ├─ jasmine-core@~2.8.0
│  └─ jasmine-core@2.8.0
├─ jasminewd2@2.2.0
├─ karma-jasmine-html-reporter@1.4.0
├─ karma-jasmine@2.0.1
│  └─ jasmine-core@^3.3
│  ├─ jasmine@2.8.0
│  ├─ jasminewd2@^2.1.0
johnjbarton commented 5 years ago

Thanks for the update!

argelj289 commented 4 years ago

setting random to false not working when I try it to set in my project upgraded in angular 10

package.json:


{
  "name": "my-app",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --dev --env=dev & npm run lint",
    "ngbuilddev": "ng build --progress --configuration=dev --output-path app/ --base-href app/",
    "ngbuildtest": "ng build  --progress --configuration=test --output-path app/ --base-href app/",
    "ngbuildpt": "ng build  --progress --configuration=pt --output-path app/ --base-href app/",
    "ngbuildstg": "ng build --progress  --configuration=stg --output-path app/ --base-href app/",
    "ngbuildprod": "ng build  --progress --configuration=prod --output-path app/ --base-href app/",
    "killport": "sudo kill $(sudo lsof -t -i:4200)",
    "build": "ng build",
    "lint": "tslint -c ./tslint.json --project ./tsconfig.json --force  --format stylish",
    "lintout": "tslint -c ./tslint.json --project ./tsconfig.json --force --out ./reports/tslint.txt",
    "lintbuild": "tslint -c ./tslint.json --project ./tsconfig.json --force --format vso",
    "test": "ng test --browsers Chrome --sourcemaps=false",
    "test-coverage": "ng test --browsers Chrome --code-coverage --sourcemaps=false",
    "testbuild": "ng test --watch false --browsers PhantomJS --code-coverage --sourcemaps=false",
    "e2e": "ng e2e",
    "sonar": "gulp test:sonar",
    "a11y": "gulp test:accessibility",
    "scss-lint": "scss-lint --format=JSON",
    "typedoc": "typedoc --out reports/typedoc src --exclude **/*.spec.ts --mode modules --target ES6",
    "view:coverage": "http-server ./reports/coverage -o -p 8500 -c 1",
    "view:ut": "http-server ./reports/ut -o -p 8500 -c 1",
    "view:typedoc": "http-server ./reports/typedoc -o -p 8500 -c 1",
    "view:doc": "http-server ./reports/doc -o -p 8500 -c 1",
    "outdated": "npm outdated --depth 0 --long",
    "check": "node ./node_modules/npm-check/bin/cli.js -u",
    "doc_shared_contracts": "./node_modules/.bin/compodoc src/app/_shared/contracts -p ./tsconfig.json -d ./reports/doc/_shared/contracts -n SharedContracts --disablePrivateOrInternalSupport --theme Readthedocs --hideGenerator --disableCoverage",
    "doc_shared_directives": "./node_modules/.bin/compodoc src/app/_shared/directives -p ./tsconfig.json -d ./reports/doc/_shared/directives -n SharedDirectives --disablePrivateOrInternalSupport --theme Readthedocs --hideGenerator --disableCoverage",
    "doc_shared_guards": "./node_modules/.bin/compodoc src/app/_shared/guards -p ./tsconfig.json -d ./reports/doc/_shared/guards -n SharedGuards --disablePrivateOrInternalSupport --theme Readthedocs --hideGenerator --disableCoverage",
    "doc_shared_helpers": "./node_modules/.bin/compodoc src/app/_shared/helpers -p ./tsconfig.json -d ./reports/doc/_shared/helpers -n SharedHelpers --disablePrivateOrInternalSupport --theme Readthedocs --hideGenerator --disableCoverage",
    "doc_shared_models": "./node_modules/.bin/compodoc src/app/_shared/models -p ./tsconfig.json -d ./reports/doc/_shared/models -n SharedModels --disablePrivateOrInternalSupport --theme Readthedocs --hideGenerator --disableCoverage",
    "doc_shared_pipes": "./node_modules/.bin/compodoc src/app/_shared/pipes -p ./tsconfig.json -d ./reports/doc/_shared/pipes -n SharedPipes --disablePrivateOrInternalSupport --theme Readthedocs --hideGenerator --disableCoverage",
    "doc_shared_services": "./node_modules/.bin/compodoc src/app/_shared/services -p ./tsconfig.json -d ./reports/doc/_shared/services -n SharedServices --disablePrivateOrInternalSupport --theme Readthedocs --hideGenerator --disableCoverage",
    "doc_ems_mapper": "./node_modules/.bin/compodoc src/app/ems-mapper -p ./tsconfig.json -d ./reports/doc/ems-mapper -n EMSMapper --disablePrivateOrInternalSupport --theme Readthedocs --hideGenerator --disableCoverage",
    "doc_events": "./node_modules/.bin/compodoc src/app/events -p ./tsconfig.json -d ./reports/doc/events -n Events --disablePrivateOrInternalSupport --theme Readthedocs --hideGenerator --disableCoverage",
    "doc_feature": "./node_modules/.bin/compodoc src/app/feature -p ./tsconfig.json -d ./reports/doc/feature -n Feature --disablePrivateOrInternalSupport --theme Readthedocs --hideGenerator --disableCoverage",
    "doc_home": "./node_modules/.bin/compodoc src/app/home -p ./tsconfig.json -d ./reports/doc/home -n Home --disablePrivateOrInternalSupport --theme Readthedocs --hideGenerator --disableCoverage",
    "doc_places": "./node_modules/.bin/compodoc src/app/places -p ./tsconfig.json -d ./reports/doc/places -n Places --disablePrivateOrInternalSupport --theme Readthedocs --hideGenerator --disableCoverage",
    "doc_posts": "./node_modules/.bin/compodoc src/app/posts -p ./tsconfig.json -d ./reports/doc/posts -n Posts --disablePrivateOrInternalSupport --theme Readthedocs --hideGenerator --disableCoverage",
    "doc_security": "./node_modules/.bin/compodoc src/app/security -p ./tsconfig.json -d ./reports/doc/security -n Security --disablePrivateOrInternalSupport --theme Readthedocs --hideGenerator --disableCoverage",
    "doc_security_badge": "./node_modules/.bin/compodoc src/app/security-badge -p ./tsconfig.json -d ./reports/doc/security-badge -n SecurityBadge --disablePrivateOrInternalSupport --theme Readthedocs --hideGenerator --disableCoverage",
    "doc": "npm run doc_shared_contracts && npm run doc_shared_directives && npm run doc_shared_guards && npm run doc_shared_helpers && npm run doc_shared_models && npm run doc_shared_pipes && npm run doc_shared_services && npm run doc_ems_mapper && npm run doc_events && npm run doc_feature && npm run doc_home && npm run doc_places && npm run doc_posts && npm run doc_security && npm run doc_security_badge",
    "postinstall": "ngcc"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^3.0.0-beta.0",
    "@angular/animations": "^10.1.3",
    "@angular/common": "^10.1.3",
    "@angular/compiler": "^10.1.3",
    "@angular/core": "^10.1.3",
    "@angular/forms": "^10.1.3",
    "@angular/localize": "^10.1.3",
    "@angular/platform-browser": "^10.1.3",
    "@angular/platform-browser-dynamic": "^10.1.3",
    "@angular/router": "^10.1.3",
    "@ng-bootstrap/ng-bootstrap": "^7.0.0",
    "@progress/kendo-angular-buttons": "^5.5.1",
    "@progress/kendo-angular-common": "^1.2.3",
    "@progress/kendo-angular-dateinputs": "^4.3.2",
    "@progress/kendo-angular-dropdowns": "^4.3.2",
    "@progress/kendo-angular-excel-export": "^3.1.5",
    "@progress/kendo-angular-grid": "^4.8.0",
    "@progress/kendo-angular-inputs": "^6.7.1",
    "@progress/kendo-angular-intl": "^2.0.0",
    "@progress/kendo-angular-l10n": "^2.0.2",
    "@progress/kendo-angular-pdf-export": "^2.0.4",
    "@progress/kendo-angular-popup": "^3.0.6",
    "@progress/kendo-data-query": "^1.1.1",
    "@progress/kendo-drawing": "^1.4.0",
    "@swimlane/ngx-datatable": "^18.0.0",
    "@types/file-saver": "^2.0.1",
    "@types/googlemaps": "3.39.13",
    "angular2-multiselect-dropdown": "^3.2.1",
    "bootstrap": "^4.1.3",
    "common-tags": "^1.4.0",
    "core-js": "^2.5.1",
    "date-fns": "^1.28.5",
    "feather-icons": "^4.7.3",
    "file-saver": "^2.0.2",
    "font-awesome": "^4.7.0",
    "jquery": "^3.5.1",
    "moment": "^2.25.3",
    "ng-pick-daterange": "^1.0.0",
    "ng-pick-datetime": "^4.3.4",
    "ng-select": "^1.0.2",
    "ng2-file-upload": "^1.4.0",
    "ngx-bootstrap": "^6.1.0",
    "ngx-editor": "^5.0.0-alpha.7",
    "ngx-infinite-scroll": "^8.0.0",
    "ngx-perfect-scrollbar": "^8.0.0",
    "ngx-ui-switch": "^10.0.2",
    "npm-font-open-sans": "^1.1.0",
    "phantomjs": "^2.1.7",
    "popper.js": "^1.14.4",
    "prosemirror-history": "^1.1.3",
    "rxjs": "^6.6.3",
    "rxjs-compat": "^6.6.3",
    "sweetalert2": "^7.29.1",
    "tslib": "^2.0.0",
    "typescript-string-operations": "^1.3.1",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1001.3",
    "@angular/cli": "^10.1.3",
    "@angular/compiler-cli": "^10.1.3",
    "@compodoc/compodoc": "^1.0.1",
    "@types/jasmine": "^2.5.54",
    "@types/lodash": "^4.14.161",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "gulp": "^4.0.2",
    "gulp-a11y": "^0.1.2",
    "gulp-accessibility": "^3.0.1",
    "gulp-load-plugins": "^1.4.0",
    "gulp-rename": "^1.2.2",
    "gulp-sonar": "^3.0.0",
    "gulp-util": "^3.0.8",
    "http-server": "^0.12.3",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-cli": "^1.0.1",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-htmlfile-reporter": "^0.3.5",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "karma-junit-reporter": "^1.2.0",
    "karma-phantomjs-launcher": "^1.0.4",
    "node-sass": "^4.14.1",
    "npm-check": "^5.4.5",
    "protractor": "~7.0.0",
    "protractor-jasmine2-html-reporter": "0.0.7",
    "ts-node": "^3.3.0",
    "tslint": "~6.1.0",
    "typedoc": "^0.19.2",
    "typescript": "4.0.3"
  }
}