Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS-312 Create rule S1607 (no-skipped-tests): Tests should not be skipped without providing a reason #4797

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"desktop:app/test/unit/git/reset-test.ts": [
35
],
"desktop:app/test/unit/git/status-test.ts": [
287
]
}
43 changes: 43 additions & 0 deletions packages/jsts/src/rules/S1607/fixtures/jasmine/cb.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Test cases with Jasmine

describe('foo', function() {
it('should do something', function(done) {
done();
});
});

describe('foo', function() {
// Reason: There is a bug in the code
xit('should do something', function(done) { // Compliant
done();
});
});


describe('foo', function() {
xit('should do something', function(done) { // Noncompliant {{Remove this unit test or explain why it is ignored.}}
//^^^
done();
});
});

describe('foo', function() {
xcontext('foo', function() { // Noncompliant
it('should do something', function(done) {
done();
});
});
});

xdescribe('foo', function() { // Noncompliant
it('should do something', function(done) {
done();
});
});

describe('foo', function() {
//
xit('should do something', function(done) { // Noncompliant
done();
});
});
35 changes: 35 additions & 0 deletions packages/jsts/src/rules/S1607/fixtures/jasmine/cb.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { basename } from 'path';
import { check } from '../../../../../tests/tools';
import { rule } from '../../';
import { clearPackageJsons, loadPackageJsons } from '../../../helpers';

const sonarId = basename(__dirname);

describe('Rule S1607', () => {
beforeEach(() => {
loadPackageJsons(__dirname, []);
});
afterAll(() => {
clearPackageJsons();
});
check(sonarId, rule, __dirname);
});
5 changes: 5 additions & 0 deletions packages/jsts/src/rules/S1607/fixtures/jasmine/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"jasmine": "1.2.3"
}
}
52 changes: 52 additions & 0 deletions packages/jsts/src/rules/S1607/fixtures/jest/cb.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Test cases with Jest

describe('foo', function() {
it('should do something', function(done) {
done();
});
});

describe('foo', function() {
// Reason: There is a bug in the code
it.skip('should do something', function(done) { // Compliant
done();
});
});


describe('foo', function() {
it.skip('should do something', function(done) { // Noncompliant {{Remove this unit test or explain why it is ignored.}}
//^^^^^^^
done();
});
});

describe('foo', function() {
test.skip('should do something', function(done) { // Noncompliant
done();
});
});

describe.skip('foo', function() { // Noncompliant
it('should do something', function(done) {
done();
});
});

describe('foo', function() {
xit('should do something', function(done) { // Noncompliant
done();
});
});

describe('foo', function() {
xtest('should do something', function(done) { // Noncompliant
done();
});
});

xdescribe('foo', function() { // Noncompliant
it('should do something', function(done) {
done();
});
});
35 changes: 35 additions & 0 deletions packages/jsts/src/rules/S1607/fixtures/jest/cb.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { basename } from 'path';
import { check } from '../../../../../tests/tools';
import { rule } from '../../';
import { clearPackageJsons, loadPackageJsons } from '../../../helpers';

const sonarId = basename(__dirname);

describe('Rule S1607', () => {
beforeEach(() => {
loadPackageJsons(__dirname, []);
});
afterAll(() => {
clearPackageJsons();
});
check(sonarId, rule, __dirname);
});
5 changes: 5 additions & 0 deletions packages/jsts/src/rules/S1607/fixtures/jest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"jest": "1.2.3"
}
}
36 changes: 36 additions & 0 deletions packages/jsts/src/rules/S1607/fixtures/mocha/cb.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Test cases with Mocha

describe('foo', function() {
it('should do something', function(done) {
done();
});
});

describe('foo', function() {
// Reason: There is a bug in the code
it.skip('should do something', function(done) { // Compliant
done();
});
});


describe('foo', function() {
it.skip('should do something', function(done) { // Noncompliant {{Remove this unit test or explain why it is ignored.}}
//^^^^^^^
done();
});
});

describe('foo', function() {
context.skip('foo', function() { // Noncompliant
it('should do something', function(done) {
done();
});
});
});

describe.skip('foo', function() { // Noncompliant
it('should do something', function(done) {
done();
});
});
35 changes: 35 additions & 0 deletions packages/jsts/src/rules/S1607/fixtures/mocha/cb.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { basename } from 'path';
import { check } from '../../../../../tests/tools';
import { rule } from '../../';
import { clearPackageJsons, loadPackageJsons } from '../../../helpers';

const sonarId = basename(__dirname);

describe('Rule S1607', () => {
beforeEach(() => {
loadPackageJsons(__dirname, []);
});
afterAll(() => {
clearPackageJsons();
});
check(sonarId, rule, __dirname);
});
5 changes: 5 additions & 0 deletions packages/jsts/src/rules/S1607/fixtures/mocha/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"mocha": "1.2.3"
}
}
60 changes: 60 additions & 0 deletions packages/jsts/src/rules/S1607/fixtures/nodejs/cb.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Test cases with Node.js

const test = require('node:test');

test('should do something', function(t) {
t.assert.ok(true);
});

test('should do something', { skip: 'There is a bug in the code' }, function(t) { // Compliant
t.assert.ok(true);
});

test('should do something', { skip: true }, function(t) { // Noncompliant {{Remove this unit test or explain why it is ignored.}}
// ^^^^^^^^^^
t.assert.ok(true);
});

test('should do something', { skip: '' }, function(t) { // Noncompliant
t.assert.ok(true);
});

test('should do something', function(t) {
t.skip('There is a bug in the code'); // Compliant
});

test('should do something', function(t) {
t.skip(); // Noncompliant
});

test('should do something', function(t) {
t.skip(''); // Noncompliant
});

test('should do something');

test('should do something', unknown);

test('should do something', function() {

});

test('should do something', function(t) {

});

test('should do something', function(t) {
t.diagnostic('A diagnostic message');
});

test('should do something', 42, function() {

});

test('should do something', {}, function() {

});

test('should do something', { skip: false }, function() {

});
35 changes: 35 additions & 0 deletions packages/jsts/src/rules/S1607/fixtures/nodejs/cb.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { basename } from 'path';
import { check } from '../../../../../tests/tools';
import { rule } from '../../';
import { clearPackageJsons, loadPackageJsons } from '../../../helpers';

const sonarId = basename(__dirname);

describe('Rule S1607', () => {
beforeEach(() => {
loadPackageJsons(__dirname, []);
});
afterAll(() => {
clearPackageJsons();
});
check(sonarId, rule, __dirname);
});
1 change: 1 addition & 0 deletions packages/jsts/src/rules/S1607/fixtures/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
20 changes: 20 additions & 0 deletions packages/jsts/src/rules/S1607/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
export { rule } from './rule';
Loading