tslint rule for prevent only method of chai - chai

I use chai for unit tests. But often forget remove onlymethod before commit. It will be nice to have tslint rule for it.

tslint-microsoft-contrib has a mocha-avoid-only rule that should be exactly what you need.
By the way, a hint for searching: Chai is the library that has a bunch of assertions (methods that throw an error if something is wrong). You're likely using a different library to set up your tests, likely Mocha.

Related

How do I call a function when all tests are finished running? [duplicate]

In Rust, is there any way to execute a teardown function after all tests have been run (i.e. at the end of cargo test) using the standard testing library?
I'm not looking to run a teardown function after each test, as they've been discussed in these related posts:
How to run setup code before any tests run in Rust?
How to initialize the logger for integration tests?
These discuss ideas to run:
setup before each test
teardown before each test (using std::panic::catch_unwind)
setup before all tests (using std::sync::Once)
One workaround is a shell script that wraps around the cargo test call, but I'm still curious if the above is possible.
I'm not sure there's a way to have a global ("session") teardown with Rust's built-in testing features, previous inquiries seem to have yielded little, aside from "maybe a build script". Third-party testing systems (e.g. shiny or stainless) might have that option though, might be worth looking into their exact capabilities
Alternatively, if nightly is suitable there's a custom test frameworks feature being implemented, which you might be able to use for that purpose.
That aside, you may want to look at macro_rules! to cleanup some boilerplate, that's what folks like burntsushi do e.g. in the regex package.

I get errors serving lit-element with the nollup development server

When serving lit-element components with nollup then I keep getting the following error in the browser console that I am not able to track down:
toast-messages.js:56 Uncaught TypeError: modules[number] is not a function
at create_bindings (toast-messages.js:56)
at toast-messages.js:57
at Object.48 (toast-messages.js:365)
at create_bindings (toast-messages.js:56)
at _require (toast-messages.js:141)
at toast-messages.js:249
at toast-messages.js:251
Can anyone point me in the right direction? (I can share my rollup.config.js if required)
This error means that a module has been requested, but there's no module with the specified id (number) included in the bundle. This can happen for a variety of reasons:
There's a call using require passing an invalid id.
Passing a string or something other than a number into require.
Using a library that was compiled to CommonJS but was not transformed to ESM.
It's likely that you're missing the CommonJS plugin, or if you are, then the CommonJS isn't able to catch the require call and convert it. The latter can happen because of obfuscation in the library code. CommonJS plugins work by using static analysis. It would be very difficult for the plugin to transform the following:
var r = require;
r('my-library-code');
Without executing the code, it would be difficult for static analysis to track this. A best effort attempt can be made, but there will be always a situation where it could fail.
So here's the following steps you should take:
* Confirm that the CommonJS plugin is being used.
* If it is, check the file in node_modules for unusual patterns.
* If there is, file an issue with the CommonJS plugin maintainer and see if it's possible to solve, and if not, you might need to contact the maintainer for the toast-message library.
I do realise I'm posting this very late, but better to answer later than never! To avoid this vague error in the future, in 0.10.2 of Nollup I've added a user friendly error that list some things to check for.
Hope this helps!

What is the difference between flow and eslint in react-native? Which one should I use ? Can I use both?

I was asked to use static analyser in my project in react-native. As I am already using Eslint , prettier which also help to identify compile time errors and then I found flow for static analysis in react-native.
Its making me confuse as eslint does the similar work.
and I didn't find difference between flow and eslint. so my question is
Are eslint and flow solve the same purpose ?
if not then when to use eslint and when to use flow
Can I use flow and eslint together ?
Are eslint and flow solve the same purpose ?
Yes. I think they have same final purpose (it doesn't mean they solve same problem). Help programmers realize the bugs/risky codes that may cause bugs at the typing/coding phase by warning the ugly/wrong-syntax codes. So it will reduce runtime bugs.
if not then when to use eslint and when to use flow
ESLint is a linter
https://eslint.org/docs/about/
Code linting is a type of static analysis that is frequently used to
find problematic patterns or code that doesn’t adhere to certain style
guidelines. There are code linters for most programming languages, and
compilers sometimes incorporate linting into the compilation process.
ESLint checks the rules more like convention rules.
Flow is a static type checker
https://flow.org/en/docs/getting-started/
Flow is a static type checker for your JavaScript code. It does a lot
of work to make you more productive. Making you code faster, smarter,
more confidently, and to a bigger scale.
Flow checks your code for errors through static type annotations.
These types allow you to tell Flow how you want your code to work, and
Flow will make sure it does work that way.
It's a little bit same as ESLint, but focus deeply on type annotations.
If you want to reduce typo/risky/ugly code in JS at the convention level -> ESLint is required.
If you want to add sticky type to JS code, and other programmer won't use your code in the wrong way -> Flow
Can I use flow and eslint together ?
Yes. I'm using #babel/preset-flow and eslint-config-airbnb.
P/s: In my opinion, ESLint is a must have. Flow/TypeScript can be considered
Flow is a type checker for javascript, it ensures that you pass functions or classes the correct type of information, based on information that you provided beforehand before you even run the code.
ESLint is a linter
Lint, or a linter, is a tool that analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs.
https://en.wikipedia.org/wiki/Lint_(software)
So ESLint has a long list of prefined rules that you can tweak to your liking that allow you to catch errors, whether it be syntax, code style or bad practices before you run it.
So to conclude each program attempts to solve two different issues, and therefore can be used independently, together, or neither of them.

Karma-Jasmine: Conflicting source files

I have a pretty nice Gulp based Karma-Jasmine unit test workflow going. My question is about how to avoid source conflicts in one's tests. Without having to do anything, Karma-Jasmine has auto-magically exposed my src files to Jasmine and detected my tests. I can't see how this would be useful in a real codebase where things don't fit the happy-path.
Example: Create two files you would like to test that both implement a function with the same name, Test(). One returns true, the other false. Which one is your test actually testing? Do I have any control over this? I want to be able to test both (forget telling me about better JS design, that is obvious).

grunt lesslint how to prevent output from being written to console

We are trying to use grunt-lesslint in our project, as our UI developer is comfortable fix errors in less file. grunt-recess seems more powerful but not sure if it can point errors in less file itself. I am unable to comprehend enough from lesslint page, and there do not seem to be many examples. Does anyone know the following:
How to prevent lesslint from displaying on the console. I use formatters and the report file is generated, but it also prints on console, which I do not want to.
How to make lesslint fail only in the case of errors (not warnings). Also csslint seems to report errors also, while lesslint mostly gives warnings only, why is that so? Does lesslint throw errors as well? How to make it fail only in case of errors?
I tried using 'checkstyle-xml' formatter, but it does not seem to use it (I have used in jshint and it gives a properly formatted xml, which it does not give for lesslint).
Is it possible to compile less (many files or directories) in conjunction with lesslint? Any example?
Thanks,
Paddy
I'd say it's more of a common practice to display stdout for this kind of thing; the JSHint plugin does it, as does any other linting plugin that I've used. If you get in another developer that uses Grunt they'll probably expect stdout too. If you really want to override this, use grunt-verbosity: https://npmjs.org/package/grunt-verbosity
Again, this is a convention in Grunt; if a task has any warnings then it fails. The reason being if you lint a file and the linter flags something up it should be dealt with straight away, rather than delay it; six months time you have 500 errors that you haven't fixed and you're less likely to fix them then. Most linting plugins allow you to specify custom options (I've used CSS Lint and that is very customisable), so if you don't like a rule you can always disable it.
This should work. If there's a bug with this feature you should report it on the issue tracker, where it will be noticed by the developers of the plugin. https://github.com/kevinsawicki/grunt-lesslint/issues
Yes. You can set up a custom task that runs both your linter and compile in one step: something like grunt.registerTask('buildless', 'Lint and compile LESS files.', ['lesslint', 'less']); note that you'll have to install https://github.com/gruntjs/grunt-contrib-less to get that to work. Also note that, failing linting will not compile your LESS files; mandate that your code always passes the lint check; you'll help everyone involved in the project.