Include jasmine-sinon to karma - jasmine

I have this matchers file which I would like to include in karma:
link: https://github.com/froots/jasmine-sinon
I'm using jasmine and sinon. I don't think this plugin is supported by karma. Can I manually configure it somehow?
I tried to add it in config files but karma didn't pick it
files: [
'bower_components/jasmine-sinon.js' //Added it here ???
'bower_components/jquery/dist/jquery.js',
'bower_components/underscore/underscore.js',
'bower_components/backbone/backbone.js',
'app/js/*.js'
],
https://www.npmjs.com/package/karma

you will need to have it point directly to the file, in this case, the correct path should be bower_components/jasmine-sinon/lib/jasmine-sinon.js.

Related

Step definition folder structure in cypress cucumber preprocessor

Versions
Cypress version: 8.4.0
Preprocessor version: 4.2.0
Node version: 12.18.2
Hi all, apologies if this is a stupid question, I'm quite new/noob with cypress, let alone cypress + cucumber.
So I wrote some automation tests in cucumber, and they work fine. I have the feature files in the integration folder, and the step definition folders in the integration folder too. Now I'm trying to have some structure where under integration I have a folder named step_definitions (will show better in screenshot).
folder structure
In package.json I put the following:
"cypress-cucumber-preprocessor": { "nonGlobalStepDefinitions": true, "nonGlobalStepBaseDir": "step_definitions", "commonPath": "common", "stepDefinitions": "step_definitions" }
When I try to run the tests, I get the below error:
Error: We've tried to resolve your step definitions at step_definitions, but that doesn't seem to exist. As of version 2.0.0 it's required to set step_definitions in your cypress-cucumber-preprocessor configuration. Look for nonGlobalStepDefinitions and add stepDefinitions right next to it. It should match your cypress configuration has set for integrationFolder. We no longer rely on getting information from that file as it was unreliable and problematic across Linux/MacOS/Windows especially since the config file could have been passed as an argument to cypress.
Any pointers are appreciated :)
It seems to me that the problem in your case in "stepDefinitions": "step_definitions" have you tried to give the full path like "stepDefinitions": "cypress/integration/step_definitions"?
You should set nonGlobalStepDefinitions to false or remove this setting, as you don't have a separate folder for the step_definitions but it is inside the integration folder instead.
So, in order to use your structure, please modify that section in the package.json file to:
"cypress-cucumber-preprocessor": {
"commonPath": "cypress/integration/step_definitions/common",
"stepDefinitions": "cypress/integration/step_definitions"
}
That would be enough. It works.

Excluding specific set of files from lint issue report

I am using gometalinterv2 in my Go project for linting. After the lint report is generated, the report file is linked to sonarqube for analysis and presentation.
I want to exclude some files like *_test.go from linting. I know there is a --exclude flag for gometalinterv2 to exclude folders. But since _test.go files are in the same folder/package as the source code, this won't work.
So is there any way to achieve this (either at linting stage or in sonar properties file)?
Add config file .gometalinter.json to the root of your project and specify rules for excluding:
{
"exclude": [
".*_test.go",
"/any/folder/"
]
}
I found another way after I marked #bayrinet's answer. The files (not just folders) to be excluded can also be passed to the command using the exclude flag like below -
>gometalinter.v2 ./... --exclude=somefolder --exclude=.*_test.go

Not explicitly say where all tests are

When setting up Mocha how can I say 'Grab all test files in the /tests/specs/ folder and run those`?
This is much more useful than having to explicitly define each test Mocha should include and run.
mocha.setup({
ui: 'bdd',
grep: 'tests/specs/*.Spec.js' // Look for all js files in specs folder
});
There is no option you can pass to mocha.setup to find files.
On the command line you just pass a glob pattern to Mocha (e.g. mocha 'some/subdir/**/*.spec.js', the quotes are to prevent some shells from mangling the glob). You can put it in mocha.opts if you don't want to have to repeat it all the time. The startup script (mocha) will find the files and feed them to the test runner.
If you bypass Mocha's startup script but instead decide to write your own code to setup and drive Mocha, you are responsible for finding the test files and feeding them to Mocha with the .addFile method. An except from this example:
// Add each .js file to the mocha instance
fs.readdirSync(testDir).filter(function(file){
// Only keep the .js files
return file.substr(-3) === '.js';
}).forEach(function(file){
mocha.addFile(
path.join(testDir, file)
);
});
You could use node-glob to replicate globbing functionality if you want.
In the browser, Mocha has no notion of "files" so it cannot be told what files to use. You need to use a module loader like RequireJS or SystemJS and load the modules that contain the tests or bundle all the test files with bundlers like Webpack or Browserify and load the bundle after you load Mocha. Mocha will learn of the available tests when your test files call the functions that Mocha leaks into the global space.

gulp, wiredep and custom sass file

So I made a library that I can bower install using a direct link. I can use this library from another internal application by adding the library name in the dependency of the bower.json file. When other internal application does a bower update, the changes I made on the library will be applied to their application. This part is working very well.
Now, I'd like the other software devs to have freedom to change the styles. They can create css file directly and that will work. However, it's a hackish route. I can provide them the same settings file that I use.
So i tried putting that file in the main section of the bower.json but wiredep is processing it. I put it in exclude and the error is gone when I run gulp.
"main": [
"dist/stylesheet.css",
"src/_settings.scss"
],
this is the code that prevented it from being parsed by wiredep
wiredep: {
directory: 'bower_components',
exclude: ['css/foundation.css','src/_settings.scss']
}
Am I right that I'll have to create a new gulp task and put 'src/_settings.scss' as gulp.src like this
gulp.task('sasstask2', function () {
return gulp.src('src/_settings.scss')
.pipe($.sass())
.pipe(gulp.dest('src/css'));
});
I also like the generate css to be injected to index.html but not sure how to do it? Will wiredep automatically inject it to index.html?

in webstorm how to create a mocha test configuration for a single test

I want to debug just a single test in webstorm. The mocha options specify a test directory, but I can't seem to point it to just a single test.js file.
How can I debug/run configure a single mocha test using the webstorm debug configuration options?
As a hack, you could configure the mocha command directly with the CLI option:
mocha --grep login-failure.js
Also, you can use the only function to skip all other tests:
describe(function () {
// these tests will be skipped
});
describe.only(function () {
// these tests will run
});
Source: http://jaketrent.com/post/run-single-mocha-test/
As far as I'm aware it's not currently supported.
https://youtrack.jetbrains.com/issue/WEB-10067 -- watch this ticket (star/vote/comment) to get notified on progress.
I solved this by pointing to a random non-test directory as the test directory and passing my single test filename in as an "extra mocha option"
Why not just create a test folder and create your .js test file inside?

Resources