Skip to content

Commit

Permalink
chore: enable eslint-plugin-mocha; warn/error on use of .only in cy…
Browse files Browse the repository at this point in the history
…press tests (#1423)
  • Loading branch information
kswenson authored Aug 22, 2024
1 parent 7b9e1f2 commit 09f80fa
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 35 deletions.
8 changes: 7 additions & 1 deletion v3/.eslintrc.build.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ module.exports = {
{ // rules specific to Jest tests
files: ["src/**/*.test.*", "src/test/**"],
rules: {
"jest/no-focused-tests": "warn"
"jest/no-focused-tests": "error"
}
},
{ // rules specific to Cypress tests
files: ["cypress/**"],
rules: {
"mocha/no-exclusive-tests": "error"
}
}
]
Expand Down
14 changes: 10 additions & 4 deletions v3/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ module.exports = {
"@typescript-eslint/no-var-requires": "off",
"jest/no-disabled-tests": "off",
"jest/no-done-callback": "off",
"jest/no-focused-tests": "off" // enabled in .eslintrc.build.js
"jest/no-focused-tests": "warn" // error in .eslintrc.build.js
}
},
{ // rules specific to Cypress tests
Expand All @@ -150,14 +150,20 @@ module.exports = {
node: true,
"cypress/globals": true
},
plugins: ["cypress"],
extends: ["plugin:cypress/recommended"],
plugins: ["cypress", "mocha"],
extends: ["plugin:cypress/recommended", "plugin:mocha/recommended"],
rules: {
"@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-var-requires": "off",
"cypress/no-unnecessary-waiting": "off",
"cypress/unsafe-to-chain-command": "off" // FIXME: eight errors reported
"cypress/unsafe-to-chain-command": "off", // FIXME: multiple errors reported
"mocha/consistent-spacing-between-blocks": "off",
"mocha/max-top-level-suites": "off",
"mocha/no-exclusive-tests": "warn", // error in .eslintrc.build.js
"mocha/no-mocha-arrows": "off",
"mocha/no-setup-in-describe": "off",
"mocha/no-skipped-tests": "off",
}
},
{ // Lint configs in the base v3 directory
Expand Down
16 changes: 8 additions & 8 deletions v3/cypress/e2e/case-card.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

beforeEach(() => {
// cy.scrollTo() doesn't work as expected with `scroll-behavior: smooth`
const queryParams = "?sample=mammals&scrollBehavior=auto"
const url = `${Cypress.config("index")}${queryParams}`
cy.visit(url)
cy.wait(2000)
})

context("case card", () => {
beforeEach(() => {
// cy.scrollTo() doesn't work as expected with `scroll-behavior: smooth`
const queryParams = "?sample=mammals&scrollBehavior=auto"
const url = `${Cypress.config("index")}${queryParams}`
cy.visit(url)
cy.wait(2000)
})

describe("case card", () => {
it("can switch from case table to case card view and back", () => {
const tableHeaderLeftSelector = ".codap-component.codap-case-table .component-title-bar .header-left"
Expand Down
44 changes: 22 additions & 22 deletions v3/cypress/e2e/table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ import { ComponentElements as c } from "../support/elements/component-elements"
import { ToolbarElements as toolbar } from "../support/elements/toolbar-elements"
import { FormulaHelper as fh } from "../support/helpers/formula-helper"

const numOfAttributes = 10
const firstRowIndex = 2
let lastRowIndex = -1
let middleRowIndex = -1
let numOfCases = "0"
const collectionName = "Mammals"
const renamedCollectionName = "Animals"
const newCollectionName = "New Dataset"

beforeEach(() => {
// cy.scrollTo() doesn't work as expected with `scroll-behavior: smooth`
const queryParams = "?sample=mammals&scrollBehavior=auto"
const url = `${Cypress.config("index")}${queryParams}`
cy.visit(url)
cy.wait(1000)
table.getNumOfAttributes().should("equal", numOfAttributes.toString())
table.getNumOfRows().then($cases => {
numOfCases = $cases ?? "0"
lastRowIndex = Number($cases) - 1
middleRowIndex = Math.min(5, Math.floor(lastRowIndex / 2))
context("case table ui", () => {
const numOfAttributes = 10
const firstRowIndex = 2
let lastRowIndex = -1
let middleRowIndex = -1
let numOfCases = "0"
const collectionName = "Mammals"
const renamedCollectionName = "Animals"
const newCollectionName = "New Dataset"

beforeEach(() => {
// cy.scrollTo() doesn't work as expected with `scroll-behavior: smooth`
const queryParams = "?sample=mammals&scrollBehavior=auto"
const url = `${Cypress.config("index")}${queryParams}`
cy.visit(url)
cy.wait(1000)
table.getNumOfAttributes().should("equal", numOfAttributes.toString())
table.getNumOfRows().then($cases => {
numOfCases = $cases ?? "0"
lastRowIndex = Number($cases) - 1
middleRowIndex = Math.min(5, Math.floor(lastRowIndex / 2))
})
})
})

context("case table ui", () => {
describe("table view", () => {
it("populates title bar from sample data", () => {
c.getComponentTitle("table").should("contain", collectionName)
Expand Down
129 changes: 129 additions & 0 deletions v3/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-react": "^7.34.3",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-testing-library": "^6.2.2",
Expand Down

0 comments on commit 09f80fa

Please sign in to comment.