levibuzolic / eslint-plugin-no-only-tests

ESLint rule for catching focused/only test blocks
https://www.npmjs.com/package/eslint-plugin-no-only-tests
MIT License
92 stars 18 forks source link

Not detecting spec.ts files #18

Closed bmitchinson closed 3 years ago

bmitchinson commented 3 years ago

What file formats are supported within this extension? Does it look at the listed describe it etc, and all files? Just .js / .ts? If .ts, I'd assume spec.ts would be included, but I never get the lint errors in my cypress spec.ts file :(

Thanks for you work on this lib.

levibuzolic commented 3 years ago

There's no restrictions on file extensions, though I think it's possible that the AST parsing might not be quite right for TypeScript files, I've not tested it myself.

Do you have a sample file/snippet handy that I can test with?

bmitchinson commented 3 years ago

audio.spec.ts:

import { createAudioResponse } from "../responses/audio/createAudioResponse"
import { getPromptCreationInfoResponse } from "../responses/manual-page-load/getPromptCreationInfo"

describe.only("The audio conversion portion of the manual page", function() {
    before(() => {
        cy.server()
        cy.route(
            "POST",
            "/api/graphql?opname=getPromptCreationInfo",
            [getPromptCreationInfoResponse]
        )
    })

        it.only(`can play the received source audio`, () => {
            cy.get(`source-audio-player`).then(playerRef => {
                const playerEle = playerRef.get(0)
                playerEle.play()
            })
            cy.wait(400)
            cy.get(`#source-audio-player`).then(playerRef => {
                const playerEle = playerRef.get(0)
                playerEle.pause()
                expect(playerEle.currentTime).to.be.greaterThan(0)
            })
        })
    })
})
levibuzolic commented 3 years ago

@bmitchinson I suspect there's an issue with your config/setup, I've just tested the plugin with a TS and a JS file side-by-side and both work correctly. There was a syntax error in your sample (an extra })), but I assume that was just because it was a partial of the complete file.

I've pushed up the example as a branch so you can compare with your setup, I've just used eslint's init script to setup a basic config. You can verify it's working correct with yarn run lint

$ yarn run lint

/Users/levi/src/eslint-plugin-no-only-tests/example/tests/example.spec.js
   7:10  error  describe.only not permitted  no-only-tests/no-only-tests
  12:8   error  it.only not permitted        no-only-tests/no-only-tests

/Users/levi/src/eslint-plugin-no-only-tests/example/tests/example.spec.ts
   7:10  error  describe.only not permitted  no-only-tests/no-only-tests
  12:8   error  it.only not permitted        no-only-tests/no-only-tests

✖ 4 problems (4 errors, 0 warnings)

error Command failed with exit code 1.