Skip to content

Commit

Permalink
fix: handle ImportBindings in no-unnecessary-waiting rule
Browse files Browse the repository at this point in the history
  • Loading branch information
mschile authored Apr 28, 2023
2 parents 969b222 + ad396fb commit c626ad5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/rules/no-unnecessary-waiting.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ function isIdentifierNumberConstArgument (node, scope) {
return typeof definition.node.init.value === 'number'
}

// import { WAIT } from './constants'
// cy.wait(WAIT)
// we don't know if WAIT is a number or alias '@someRequest', so don't fail
if (definition.type === 'ImportBinding') return false

const param = definition.node.params[definition.index]

// function wait (amount) { cy.wait(amount) }
Expand Down
7 changes: 6 additions & 1 deletion tests/lib/rules/no-unnecessary-waiting.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const RuleTester = require('eslint').RuleTester
const ruleTester = new RuleTester()

const errors = [{ messageId: 'unexpected' }]
const parserOptions = { ecmaVersion: 6 }
const parserOptions = { ecmaVersion: 6, sourceType: 'module' }

ruleTester.run('no-unnecessary-waiting', rule, {
valid: [
Expand All @@ -27,6 +27,11 @@ ruleTester.run('no-unnecessary-waiting', rule, {
{ code: 'function customWait (ms) { cy.wait(ms) }', parserOptions, errors },
{ code: 'const customWait = (ms) => { cy.wait(ms) }', parserOptions, errors },

{ code: 'import BAR_BAZ from "bar-baz"; cy.wait(BAR_BAZ)', parserOptions },
{ code: 'import { FOO_BAR } from "foo-bar"; cy.wait(FOO_BAR)', parserOptions },
{ code: 'import * as wildcard from "wildcard"; cy.wait(wildcard.value)', parserOptions },
{ code: 'import { NAME as OTHER_NAME } from "rename"; cy.wait(OTHER_NAME)', parserOptions },

// disable the eslint rule
{
code: `
Expand Down

0 comments on commit c626ad5

Please sign in to comment.