Skip to content

Commit

Permalink
Update metadata and description
Browse files Browse the repository at this point in the history
  • Loading branch information
yassin-kammoun-sonarsource committed Nov 29, 2023
1 parent b3dc3f9 commit 75332e8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
14 changes: 13 additions & 1 deletion rules/S2187/javascript/metadata.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
{
}
"title": "Test files should contain tests",
"tags": [
"jasmine",
"jest",
"mocha",
"node",
"tests",
"unused",
"confusing"
],
"quickfix": "infeasible"
}

48 changes: 24 additions & 24 deletions rules/S2187/javascript/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
FIXME: add a description
== Why is this an issue?

// If you want to factorize the description uncomment the following line and create the file.
//include::../description.adoc[]
Test files in JavaScript and TypeScript are meant to contain test cases. These test cases are used to verify the functionality of your code and ensure that it behaves as expected. If a test file doesn't contain any test cases, it's not serving its purpose.

== Why is this an issue?
A test file without test cases might indicate:

FIXME: remove the unused optional headers (that are commented out)
* An incomplete test suite: Perhaps the developer started writing tests but didn't finish.
* A mistake: The developer might have accidentally deleted the test cases or moved them to another file.
//=== What is the potential impact?
This rule flags any file that has a ``++.test++`` or ``++.spec++`` suffix but does not contain any test cases defined using the ``++it++`` or ``++test++`` functions from Jasmine, Jest, Mocha, or Node.js testing API. The alternative forms ``++it.only++`` and ``++test.only++`` are recognized, but their use is generally discouraged.

== How to fix it
//== How to fix it in FRAMEWORK NAME

To fix a test file that doesn't contain any test cases, you should add test cases or delete the file if it isn't needed.

=== Code examples

==== Noncompliant code example

[source,text,diff-id=1,diff-type=noncompliant]
[source,javascript,diff-id=1,diff-type=noncompliant]
----
FIXME
// eval.test.js
/* no test cases */
----

==== Compliant solution

[source,text,diff-id=1,diff-type=compliant]
[source,javascript,diff-id=1,diff-type=compliant]
----
FIXME
----

//=== How does this work?
// eval.test.js
//=== Pitfalls

//=== Going the extra mile
it('1 + 2 should give 3', () => {
expect(1 + 2).toEqual(3);
});
----

== Resources
=== Documentation

//== Resources
//=== Documentation
//=== Articles & blog posts
//=== Conference presentations
//=== Standards
//=== External coding guidelines
//=== Benchmarks
* Jasmine docs - https://jasmine.github.io/pages/getting_started.html[Getting started]
* Jest docs - https://jestjs.io/docs/getting-started[Getting started]
* Mocha docs - https://mochajs.org/#getting-started[Getting started]
* Node.js docs - https://nodejs.org/api/test.html[Test runner]

0 comments on commit 75332e8

Please sign in to comment.