configure jasmine to not run tests randomly - unit-testing

i just upgraded to jasmine 3.3 and now my tests by default run in random order. Is there a way to configure karma and jasmine to make tests run like they used to before upgrading to this new version?

In Karma config under client: you are supposed to be able to set jasmine:{random:false} but that does not work for me. Does it for you?
See below link from docs and screen cap.
https://github.com/karma-runner/karma-jasmine

A well-written unit test case should provide the same result independent of its execution order.
However, We can change the execution order of Jasmine
Example 1- Add command line flag if you are just using Jasmine
jasmine test/sample.test.js --random=false //global installation
npx jasmine test/sample.test.js --random=false //local installation
Example 2- with karma add this to your config object.
module.exports = function (config) {
config.set({
client:{
jasmine:{
random:false
}
},
// rest of karma configuration goes here
};
//tested with karma 6.3.4 and jasmine v3.8.0

Related

Looking for documentation setup jest for unit test of admin plugin

my project was created with the swdc create-project ...
Is there a documentation, a tutorial or description for the right setup/configuration unit testing with JEST for custom plugin in administration?
This tutorial describes only how to write a test
But i think there must be a official setup documentation because of versions etc.
EDIT: a tutorial with code is now avialable
Using the suggested solution and execute the test, throws an configuration error:
● Test suite failed to run
Configuration error:
Could not locate module src/core/factory/module.factory mapped as:
undefined/src$1.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/^src(.*)$/": "undefined/src$1"
},
"resolver": undefined
}
...
Cause of error:
process.env.ADMIN_PATH not setted but required in %Project%/custom/plugins/%MyPlugin%/src/Resources/app/administration/node_modules/#shopware-ag/jest-preset-sw6-admin/jest-preset.js
My solution:
set process.env.ADMIN_PATH in %Project%/custom/plugins/%MyPlugin%/src/Resources/app/administration/jest.config.js
// jest.config.js
...
const { join, resolve } = require('path');
process.env.ADMIN_PATH = resolve('../../../../../../../src/Administration/Resources/app/administration');
...
I think it is easiest to just copy and adapt from a plugin that already has jest tests set up. Look at the administration directory for SwagPayPal for example. Copy the dependency and script sections from their package.json. Also copy the entire jest.config.js. Then within the administration directory of your plugin you should be able to npm install followed by npm run unit or npm run unit-watch and it should find *.spec.js files within the test sub-directory.

MarkLogic unit test not running any tests

I thought it would be a good idea to set up MarkLogic unit testing, so I've been following the unit-test-project as best as I can. Everything seems to work, but no unit tests are being performed. I've copied the four unit tests to src/test/ml-modules/root/suites/My Tests and the one module to src/main/ml-modules/root/. Everything deploys correctly. But running the unit tests gives me:
$ gradle mlUnitTest
> Task :mlUnitTest
Constructing DatabaseClient that will connect to port: 8021
Run teardown scripts: true
Run suite teardown scripts: true
Run code coverage: false
Running all suites...
Done running all suites; time: 1791ms
0 tests completed, 0 failed
The unit testing UI loads in a browser, but it also displays no tests.
This is my build.gradle file:
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath "com.marklogic:marklogic-unit-test-client:1.0.0"
classpath "com.marklogic:ml-gradle:4.1.0"
}
}
plugins { id "com.marklogic.ml-gradle" version "4.1.0" }
repositories {
jcenter()
}
dependencies {
mlBundle "com.marklogic:marklogic-unit-test-modules:1.0.0"
}
And gradle.properties:
mlAppName=unitTestApp
mlHost=localhost
mlUsername=admin
mlPassword=*****
mlRestPort=8020
mlTestRestPort=8021
mlModulePaths=src/main/ml-modules,src/test/ml-modules
I'm using MarkLogic 10, on 64 bit Linux, ml-gradle 4.0
Ah. It looks like the test suites are expected under the project directory in
src/test/ml-modules/root/test/suites/SuiteName
I had put suites under root and missed the second test directory.

launch one jasmine test with grunt and karma?

I have a big web project with many javascript Jasmine unit tests.
In that web project, i use grunt, karma and jasmine.
Is there any way to launch only one test javascript with grunt with a command line ?
Launching all tests is long, so how to do that without modify my gruntfile.js or my karma-unit.conf.js ??
I tried the following command, but it is more a hack than a real solution :
karma run -- --grep=filteredtestexpr
I am not sure of the best way to specify which test to run from the command line. But it seems like your problem can be solved with the following two pointers:
Change the name of a test from it to iit and karma will run only that test (actually all iit tests).
Change describe to ddescribe to run the entire describe block.
Also, use xit and xdescribe to explicitly exclude tests.

How to unit test Dart in Phpstorm

I installed the dart plugin, set the SDK home path to the dart-sdk folder, configured the scope and checked the 'Dart SDK enabled' option in Phpstorm 6.0.3. Next, I created a dart file in a 'test' directory with the following code (obviously I added the dependency unittest in my pubspec.yaml and ran pub get):
library mytests;
import 'package:unittest/unittest.dart';
main(){
test('my test', (){
expect(1+1, equals(2));
});
}
When I run this unit test however (by right clicking inside the file and selecting 'Run Test: my test', an error is outputted in the unit testing window stating the following:
C:/dart/dart-sdk/bin/dart.exe --ignore-unrecognized-flags --package-root=C:/Users/myname/dart/pokerdart/test/packages/ C:\Users\myname\AppData\Local\Temp\jetbrains_unit_config.dart
Testing started at 18:55 ...
'file:///C:/Users/myname/AppData/Local/Temp/jetbrains_unit_config.dart': error: line 1 pos 1: unresolved implicit call to super constructor 'Configuration()'
import 'package:unittest/unittest.dart';
^
When I run the test using powershell it just works... Am I missing something/doing something wrong?
Any help is greatly appreciated!
WEB-9636 is fixed in version 7. Please try upgrading to PHPStorm 7.1.3. Or, even better, try PHPStorm 8 EAP (http://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Early+Access+Program) - Dart support has been improved there

ReSharper Jasmine AngularJS unit-test using yeoman

I'm trying to get unit-test generated by yeoman to run in Visual Studio using Resharper 8.0.2.
With yeoman if you simply generate a controller you'll get something like this:
'use strict';
describe('Controller: MainCtrl', function () {
// load the controller's module
beforeEach(module('angularYeomanTestApp'));
var MainCtrl,
scope;
// Initialize the controller and a mock scope
beforeEach(function() {
inject(function($controller, $rootScope) {
scope = $rootScope.$new();
MainCtrl = $controller('MainCtrl', {
$scope: scope
});
})
});
it('should attach a list of awesomeThings to the scope', function () {
expect(scope.awesomeThings.length).toBe(3);
});
});
I already have transferred the knowledge of this post because yeoman doesn't generate the anonymous function before the inject statement.
Problem is that I'm always getting errors for each tests like:
Inconclusive: Test wasn't run
Resharper is configured to run tests using the chrome browser and jasmine seems to be properly included into the test page when it opens, but the test page is empty!
Running the tests with karma using e.g. grunt test does work!
Thanks for help!
PS.: I'm using: Visual-Studio-2013, Resharper 8.0.2, angularjs 1.2.6
Karma and Reshaper have nothing to do with each other. You do not have to have karma running or installed to run Resharper tests. For resharper tests you have to have , as I indicated in the comment above, all files you need included as "reference" in each test file.