Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: levibuzolic/eslint-plugin-no-only-tests
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.1.0
Choose a base ref
...
head repository: levibuzolic/eslint-plugin-no-only-tests
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.2.0
Choose a head ref
  • 10 commits
  • 5 files changed
  • 3 contributors

Commits on Oct 23, 2022

  1. Update readme

    levibuzolic committed Oct 23, 2022
    Copy the full SHA
    81d3f37 View commit details
  2. Update readme

    levibuzolic committed Oct 23, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    levibuzolic Levi Buzolic
    Copy the full SHA
    22ee724 View commit details

Commits on Jul 12, 2023

  1. Bump semver from 7.3.5 to 7.5.4

    Bumps [semver](https://github.com/npm/node-semver) from 7.3.5 to 7.5.4.
    - [Release notes](https://github.com/npm/node-semver/releases)
    - [Changelog](https://github.com/npm/node-semver/blob/main/CHANGELOG.md)
    - [Commits](npm/node-semver@v7.3.5...v7.5.4)
    
    ---
    updated-dependencies:
    - dependency-name: semver
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Jul 12, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5a28e71 View commit details

Commits on Jul 19, 2023

  1. Bump word-wrap from 1.2.3 to 1.2.4

    Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4.
    - [Release notes](https://github.com/jonschlinkert/word-wrap/releases)
    - [Commits](jonschlinkert/word-wrap@1.2.3...1.2.4)
    
    ---
    updated-dependencies:
    - dependency-name: word-wrap
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Jul 19, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    716c68e View commit details

Commits on Jul 31, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8e7861f View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    709c025 View commit details

Commits on Jul 23, 2024

  1. Add option to test for methods like fit or xit

    Klaus Herberth committed Jul 23, 2024
    Copy the full SHA
    6d48d58 View commit details

Commits on Aug 9, 2024

  1. Merge pull request #44 from sualko/feature/fit

    Add option to test for methods like fit or xit
    levibuzolic authored Aug 9, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    21613b2 View commit details

Commits on Aug 15, 2024

  1. Add test case for functions

    levibuzolic committed Aug 15, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    levibuzolic Levi Buzolic
    Copy the full SHA
    424419a View commit details
  2. Set version to 3.2.0

    levibuzolic committed Aug 15, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    levibuzolic Levi Buzolic
    Copy the full SHA
    8fb57fc View commit details
Showing with 56 additions and 15 deletions.
  1. +8 −7 README.md
  2. +1 −1 package.json
  3. +32 −1 rules/no-only-tests.js
  4. +9 −0 tests.js
  5. +6 −6 yarn.lock
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,9 +2,9 @@

[![Version](https://img.shields.io/npm/v/eslint-plugin-no-only-tests.svg)](https://www.npmjs.com/package/eslint-plugin-no-only-tests) [![Downloads](https://img.shields.io/npm/dm/eslint-plugin-no-only-tests.svg)](https://npmcharts.com/compare/eslint-plugin-no-only-tests?minimal=true) [![GitHub Tests](https://github.com/levibuzolic/eslint-plugin-no-only-tests/workflows/Tests/badge.svg)](https://github.com/levibuzolic/eslint-plugin-no-only-tests/actions?query=workflow%3ATests)

ESLint rule for `.only` tests in [mocha](https://mochajs.org/), [jest](https://jestjs.io/), [jasmine](https://jasmine.github.io/), [Mocha Cakes 2](https://github.com/iensu/mocha-cakes-2) and other JS testing libraries.
ESLint rule for `.only` tests in [Mocha](https://mochajs.org/), [Jest](https://jestjs.io/), [Jasmine](https://jasmine.github.io/), [Mocha Cakes 2](https://github.com/iensu/mocha-cakes-2) and other JS testing libraries.

By default the following test blocks are matched by default: `describe`, `it`, `context`, `tape`, `test`, `fixture`, `serial`.
The following test blocks are matched by default: `describe`, `it`, `context`, `tape`, `test`, `fixture`, `serial`, `Feature`, `Scenario`, `Given`, `And`, `When` and `Then`.

Designed to prevent you from committing focused (`.only`) tests to CI, which may prevent your entire test suite from running.

@@ -65,8 +65,9 @@ This rule supports opt-in autofixing when the `fix` option is set to `true` to a

## Options

Option | Type | Description
---|---|---
`block` | `string[]` | Specify the block names that your testing framework uses. Add a `*` to the end of any string to enable prefix matching (ie. `test*` will match `testExample.only`)<br>Defaults to `["describe", "it", "context", "test", "tape", "fixture", "serial", "Feature", "Scenario", "Given", "And", "When", "Then"]`
`focus` | `string[]` | Specify the focus scope that your testing framework uses.<br>Defaults to `["only"]`
`fix` | `boolean` | Enable this rule to auto-fix violations, useful for a pre-commit hook, not recommended for users with auto-fixing enabled in their editor.<br>Defaults to `false`
| Option | Type | Description |
| ----------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `block` | `string[]` | Specify the block names that your testing framework uses. Add a `*` to the end of any string to enable prefix matching (ie. `test*` will match `testExample.only`)<br>Defaults to `["describe", "it", "context", "test", "tape", "fixture", "serial", "Feature", "Scenario", "Given", "And", "When", "Then"]` |
| `focus` | `string[]` | Specify the focus scope that your testing framework uses.<br>Defaults to `["only"]` |
| `functions` | `string[]` | Specify not permitted functions. Good examples are `fit` or `xit`.<br>Defaults to `[]` (disabled) |
| `fix` | `boolean` | Enable this rule to auto-fix violations, useful for a pre-commit hook, not recommended for users with auto-fixing enabled in their editor.<br>Defaults to `false` |
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-no-only-tests",
"version": "3.1.0",
"version": "3.2.0",
"description": "ESLint rule for .only blocks in mocha tests",
"keywords": [
"eslint",
33 changes: 32 additions & 1 deletion rules/no-only-tests.js
Original file line number Diff line number Diff line change
@@ -10,8 +10,23 @@
//------------------------------------------------------------------------------

const defaultOptions = {
block: ['describe', 'it', 'context', 'test', 'tape', 'fixture', 'serial', 'Feature', 'Scenario', 'Given', 'And', 'When', 'Then'],
block: [
'describe',
'it',
'context',
'test',
'tape',
'fixture',
'serial',
'Feature',
'Scenario',
'Given',
'And',
'When',
'Then',
],
focus: ['only'],
functions: [],
fix: false,
};

@@ -44,6 +59,14 @@ module.exports = {
uniqueItems: true,
default: defaultOptions.focus,
},
functions: {
type: 'array',
items: {
type: 'string',
},
uniqueItems: true,
default: defaultOptions.functions,
},
fix: {
type: 'boolean',
default: defaultOptions.fix,
@@ -57,10 +80,18 @@ module.exports = {
const options = Object.assign({}, defaultOptions, context.options[0]);
const blocks = options.block || [];
const focus = options.focus || [];
const functions = options.functions || [];
const fix = !!options.fix;

return {
Identifier(node) {
if (functions.length && functions.indexOf(node.name) > -1) {
context.report({
node,
message: node.name + ' not permitted',
});
}

const parentObject = node.parent && node.parent.object;
if (parentObject == null) return;
if (focus.indexOf(node.name) === -1) return;
9 changes: 9 additions & 0 deletions tests.js
Original file line number Diff line number Diff line change
@@ -24,6 +24,10 @@ ruleTester.run('no-only-tests', rules['no-only-tests'], {
options: [{focus: ['focus']}],
code: 'test.only("Options will exclude this from being caught", function() {});',
},
{
options: [{functions: ['fit', 'xit']}],
code: 'it("Options will exclude this from being caught", function() {});',
},
],

invalid: [
@@ -194,6 +198,11 @@ ruleTester.run('no-only-tests', rules['no-only-tests'], {
output: 'Then("Some assertion", function() {});',
errors: [{message: 'Then.only not permitted'}],
},
{
options: [{functions: ['fit', 'xit']}],
code: 'xit("No skipped tests", function() {});',
errors: [{message: 'xit not permitted'}],
},
],
});

12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -670,9 +670,9 @@ rimraf@^3.0.2:
glob "^7.1.3"

semver@^7.2.1:
version "7.3.5"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
version "7.5.4"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==
dependencies:
lru-cache "^6.0.0"

@@ -794,9 +794,9 @@ which@^2.0.1:
isexe "^2.0.0"

word-wrap@^1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"
integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==
version "1.2.4"
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.4.tgz#cb4b50ec9aca570abd1f52f33cd45b6c61739a9f"
integrity sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==

wrappy@1:
version "1.0.2"