diff --git a/cypress.config.ts b/cypress.config.ts
index f215bc56..cf0d7e0b 100644
--- a/cypress.config.ts
+++ b/cypress.config.ts
@@ -1,6 +1,8 @@
import { defineConfig } from 'cypress'
import { trimEnd } from 'cypress/types/lodash'
+import plugin from './cypress/plugins'
+
export default defineConfig({
viewportWidth: 1200,
viewportHeight: 800,
@@ -10,7 +12,7 @@ export default defineConfig({
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
- return require('./cypress/plugins/index.js')(on, config)
+ return plugin(on, config)
},
baseUrl: 'http://localhost:4242',
},
diff --git a/cypress/e2e/1.simple.cy.js b/cypress/e2e/1.simple.cy.ts
similarity index 99%
rename from cypress/e2e/1.simple.cy.js
rename to cypress/e2e/1.simple.cy.ts
index d0211983..25cd1111 100644
--- a/cypress/e2e/1.simple.cy.js
+++ b/cypress/e2e/1.simple.cy.ts
@@ -1,4 +1,4 @@
-///
+///
import {
moveGutterByMouse,
diff --git a/cypress/e2e/10.toggle.cy.js b/cypress/e2e/10.toggle.cy.ts
similarity index 94%
rename from cypress/e2e/10.toggle.cy.js
rename to cypress/e2e/10.toggle.cy.ts
index bde0636a..a1f0e75f 100644
--- a/cypress/e2e/10.toggle.cy.js
+++ b/cypress/e2e/10.toggle.cy.ts
@@ -1,4 +1,4 @@
-///
+///
import { moveGutterByMouse, checkSplitDirAndSizes } from '../support/splitUtils'
@@ -49,6 +49,6 @@ context('Toggling DOM and visibility example page tests', () => {
})
})
-function getVisibilityButton(index) {
+function getVisibilityButton(index: number): Cypress.Chainable> {
return cy.get('.btn-group:first').find('> .btn').eq(index)
}
diff --git a/cypress/e2e/2.minmax.cy.js b/cypress/e2e/2.minmax.cy.ts
similarity index 97%
rename from cypress/e2e/2.minmax.cy.js
rename to cypress/e2e/2.minmax.cy.ts
index 5ae0ecba..c7a608c0 100644
--- a/cypress/e2e/2.minmax.cy.js
+++ b/cypress/e2e/2.minmax.cy.ts
@@ -1,4 +1,4 @@
-///
+///
import {
moveGutterByMouse,
@@ -255,15 +255,20 @@ context('Min & max splits example page tests', () => {
})
})
-function checkAreasClasses(sel, all) {
- cy.get(sel).then(($areas) => {
+interface AreaClassExpectation {
+ haveTo: string[]
+ notHaveTo: string[]
+}
+
+function checkAreasClasses(sel: string, all: AreaClassExpectation[]): void {
+ cy.get(sel).then(($areas: JQuery) => {
all.forEach((item, index) => {
checkAreaClasses($areas.eq(index), item.haveTo, item.notHaveTo)
})
})
}
-function checkAreaClasses($area, haveTo, notHaveTo) {
+function checkAreaClasses($area: JQuery, haveTo: string[], notHaveTo: string[]): void {
console.log('$area, haveTo, notHaveTo', $area, haveTo, notHaveTo)
haveTo.forEach((cl) => cy.wrap($area).should('have.class', cl))
notHaveTo.forEach((cl) => cy.wrap($area).should('not.have.class', cl))
diff --git a/cypress/e2e/3.nested.cy.js b/cypress/e2e/3.nested.cy.ts
similarity index 99%
rename from cypress/e2e/3.nested.cy.js
rename to cypress/e2e/3.nested.cy.ts
index 50658ac2..e7a25c8b 100644
--- a/cypress/e2e/3.nested.cy.js
+++ b/cypress/e2e/3.nested.cy.ts
@@ -1,4 +1,4 @@
-///
+///
import { moveGutterByMouse, checkSplitDirAndSizes } from '../support/splitUtils'
diff --git a/cypress/e2e/4.sync.cy.js b/cypress/e2e/4.sync.cy.ts
similarity index 99%
rename from cypress/e2e/4.sync.cy.js
rename to cypress/e2e/4.sync.cy.ts
index 570679a6..50e2a88a 100644
--- a/cypress/e2e/4.sync.cy.js
+++ b/cypress/e2e/4.sync.cy.ts
@@ -1,4 +1,4 @@
-///
+///
import { moveGutterByMouse, checkSplitDirAndSizes } from '../support/splitUtils'
diff --git a/cypress/e2e/5.style.cy.js b/cypress/e2e/5.style.cy.ts
similarity index 98%
rename from cypress/e2e/5.style.cy.js
rename to cypress/e2e/5.style.cy.ts
index d42e0875..5c6244c0 100644
--- a/cypress/e2e/5.style.cy.js
+++ b/cypress/e2e/5.style.cy.ts
@@ -1,4 +1,4 @@
-///
+///
import { moveGutterByMouse, checkSplitDirAndSizes } from '../support/splitUtils'
diff --git a/cypress/e2e/7.click.cy.js b/cypress/e2e/7.click.cy.ts
similarity index 95%
rename from cypress/e2e/7.click.cy.js
rename to cypress/e2e/7.click.cy.ts
index f7863c01..f94b0611 100644
--- a/cypress/e2e/7.click.cy.js
+++ b/cypress/e2e/7.click.cy.ts
@@ -1,8 +1,22 @@
-///
+///
import { moveGutterByMouse, checkSplitDirAndSizes } from '../support/splitUtils'
-function checkEventCount({ dragStartCount, dragEndCount, gutterClickCount, gutterDblClickCount, transitionEndCount }) {
+interface GutterEventCounts {
+ dragStartCount?: number
+ dragEndCount?: number
+ gutterClickCount?: number
+ gutterDblClickCount?: number
+ transitionEndCount?: number
+}
+
+function checkEventCount({
+ dragStartCount,
+ dragEndCount,
+ gutterClickCount,
+ gutterDblClickCount,
+ transitionEndCount,
+}: GutterEventCounts): void {
if (dragStartCount !== undefined) {
cy.get('.logs ul li').filter('.dragStart').should('have.length', dragStartCount)
}
diff --git a/cypress/e2e/9.geek.cy.js b/cypress/e2e/9.geek.cy.ts
similarity index 96%
rename from cypress/e2e/9.geek.cy.js
rename to cypress/e2e/9.geek.cy.ts
index 41d979de..04d0092f 100644
--- a/cypress/e2e/9.geek.cy.js
+++ b/cypress/e2e/9.geek.cy.ts
@@ -1,4 +1,4 @@
-///
+///
import { moveGutterByMouse, checkSplitDirAndSizes } from '../support/splitUtils'
@@ -276,14 +276,14 @@ context('Geek demo example page tests', () => {
})
})
-function checkAreaOrder() {
+function checkAreaOrder(): void {
// Retrieve all as-split-area displayed in order
- cy.get('.as-split-area').then(($splitAreas) => {
- const splitAreasNum = $splitAreas.map((i, $el) => $el.textContent)
+ cy.get('.as-split-area').then(($splitAreas: JQuery) => {
+ const splitAreasNum = $splitAreas.map((_i, $el) => $el.textContent)
// Retrieve all listed areas displayed in order
- cy.get('.opts-area div[draggable="true"] .num').then(($controlAreas) => {
- const controlAreasNum = $controlAreas.map((i, $el) => $el.textContent)
+ cy.get('.opts-area div[draggable="true"] .num').then(($controlAreas: JQuery) => {
+ const controlAreasNum = $controlAreas.map((_i, $el) => $el.textContent)
// Compare 2 lists > should be the same
expect(splitAreasNum.get()).to.deep.eq(controlAreasNum.get())
@@ -291,7 +291,7 @@ function checkAreaOrder() {
})
}
-function moveArea(numArea, gap) {
+function moveArea(numArea: number, gap: number): void {
cy.get('.opts-area div[draggable="true"]')
.eq(numArea)
.as('movedItem')
diff --git a/cypress/plugins/index.js b/cypress/plugins/index.ts
similarity index 84%
rename from cypress/plugins/index.js
rename to cypress/plugins/index.ts
index fd170fba..45564a67 100644
--- a/cypress/plugins/index.js
+++ b/cypress/plugins/index.ts
@@ -11,7 +11,9 @@
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
-module.exports = (on, config) => {
+function plugin(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions): void {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
+
+export default plugin
diff --git a/cypress/support/commands.js b/cypress/support/commands.ts
similarity index 100%
rename from cypress/support/commands.js
rename to cypress/support/commands.ts
diff --git a/cypress/support/e2e.js b/cypress/support/e2e.ts
similarity index 95%
rename from cypress/support/e2e.js
rename to cypress/support/e2e.ts
index d68db96d..d6e11fda 100644
--- a/cypress/support/e2e.js
+++ b/cypress/support/e2e.ts
@@ -13,6 +13,8 @@
// https://on.cypress.io/configuration
// ***********************************************************
+///
+
// Import commands.js using ES2015 syntax:
import './commands'
diff --git a/cypress/support/splitUtils.js b/cypress/support/splitUtils.ts
similarity index 59%
rename from cypress/support/splitUtils.js
rename to cypress/support/splitUtils.ts
index ea5213a6..54cfa832 100644
--- a/cypress/support/splitUtils.js
+++ b/cypress/support/splitUtils.ts
@@ -1,4 +1,12 @@
-export function moveGutterByMouse(gutters, num, x, y) {
+export type SplitDirection = 'horizontal' | 'vertical'
+
+type RectSize = 'width' | 'height'
+
+function isGutterArray(value: number | readonly number[]): value is readonly number[] {
+ return Array.isArray(value)
+}
+
+export function moveGutterByMouse(gutters: string, num: number, x: number, y: number): void {
cy.get(gutters)
.eq(num)
.trigger('mousedown', { which: 1, clientX: 0, clientY: 0, button: 0 })
@@ -13,38 +21,45 @@ export function moveGutterByMouse(gutters, num, x, y) {
cy.wait(10)
}
-export function moveGutterByKeyboard(gutters, num, numKeyPresses, keySequence) {
+export function moveGutterByKeyboard(gutters: string, num: number, numKeyPresses: number, keySequence: string): void {
for (let i = 0; i < numKeyPresses; i++) {
cy.get(gutters).eq(num).focus().type(`{${keySequence}}`)
cy.wait(10)
}
}
-export function checkGutterAriaLabel(gutters, num, ariaLabel) {
+export function checkGutterAriaLabel(gutters: string, num: number, ariaLabel: string): void {
cy.get(gutters).eq(num).should('have.attr', 'aria-label').and('equal', ariaLabel)
}
-export function checkGuttersAriaValueTexts(gutters, ariaValueTexts) {
+export function checkGuttersAriaValueTexts(gutters: string, ariaValueTexts: ReadonlyArray): void {
cy.get(gutters).each(($gutter, index) => {
const ariaValueText = ariaValueTexts[index]
if (ariaValueText === null) {
cy.wrap($gutter).should('not.have.attr', 'aria-valuetext')
} else {
- cy.wrap($gutter).should('have.attr', 'aria-valuetext').and('equal', ariaValueTexts[index])
+ cy.wrap($gutter).should('have.attr', 'aria-valuetext').and('equal', ariaValueText)
}
})
}
//////////////////////////////////////////
-export function checkSplitDirAndCalcSizes(el, dir, w, h, gutter, sizes) {
+export function checkSplitDirAndCalcSizes(
+ el: string,
+ dir: SplitDirection,
+ w: number,
+ h: number,
+ gutter: number,
+ sizes: ReadonlyArray,
+): void {
const propFlexDir = dir === 'horizontal' ? 'row' : 'column'
cy.get(el).should('have.css', 'flex-direction', propFlexDir)
- const propSize = dir === 'horizontal' ? 'width' : 'height'
+ const propSize: RectSize = dir === 'horizontal' ? 'width' : 'height'
cy.get(`${el} > .as-split-gutter`).should('have.css', propSize, `${gutter}px`)
- const propSize2 = propSize === 'width' ? 'height' : 'width'
+ const propSize2: RectSize = propSize === 'width' ? 'height' : 'width'
const propValue2 = propSize === 'width' ? h : w
cy.get(`${el} > as-split-area`)
@@ -57,23 +72,32 @@ export function checkSplitDirAndCalcSizes(el, dir, w, h, gutter, sizes) {
//////////////////////////////////////////
-export function checkSplitDirAndSizes(el, dir, w, h, gutterOrGutters, sizes) {
- const gutters = Array.isArray(gutterOrGutters) ? gutterOrGutters : new Array(sizes.length - 1).fill(gutterOrGutters)
+export function checkSplitDirAndSizes(
+ el: string,
+ dir: SplitDirection,
+ w: number,
+ h: number,
+ gutterOrGutters: number | readonly number[],
+ sizes: readonly number[],
+): void {
+ const gutters = isGutterArray(gutterOrGutters)
+ ? gutterOrGutters
+ : new Array(sizes.length - 1).fill(gutterOrGutters)
cy.log(`-- NEW SPLIT CHECK (${dir},${w},${h},[${gutters.join(',')}],[${sizes.join(',')}])`)
const propGridDir = dir === 'vertical' ? 'grid-template-rows' : 'grid-template-columns'
cy.get(el).should('have.css', propGridDir).should('include', ' ')
- const propSize = dir === 'horizontal' ? 'width' : 'height'
- const propSize2 = propSize === 'width' ? 'height' : 'width'
+ const propSize: RectSize = dir === 'horizontal' ? 'width' : 'height'
+ const propSize2: RectSize = propSize === 'width' ? 'height' : 'width'
const propValue2 = propSize === 'width' ? h : w
- const round = (value) => Math.round(value * 10) / 10
+ const round = (value: number): number => Math.round(value * 10) / 10
cy.get(`${el} > .as-split-gutter`).should('have.length', sizes.length - 1)
- cy.get(`${el} > .as-split-gutter`).each(($el, index) => {
+ cy.get(`${el} > .as-split-gutter`).each(($el: JQuery, index) => {
const rect = $el[0].getBoundingClientRect()
expect(rect[propSize]).to.be.eq(gutters[index])
@@ -82,7 +106,7 @@ export function checkSplitDirAndSizes(el, dir, w, h, gutterOrGutters, sizes) {
cy.get(`${el} > .as-split-area`)
.should('have.length', sizes.length)
- .each(($li, index) => {
+ .each(($li: JQuery, index) => {
const rect = $li[0].getBoundingClientRect()
expect(round(rect[propSize])).to.be.eq(round(sizes[index]))
diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json
new file mode 100644
index 00000000..7560cc37
--- /dev/null
+++ b/cypress/tsconfig.json
@@ -0,0 +1,16 @@
+{
+ "extends": "../tsconfig.json",
+ "compilerOptions": {
+ "types": ["cypress", "node"],
+ "lib": ["es2022", "dom"],
+ "module": "es2020",
+ "moduleResolution": "node10",
+ "noEmit": true,
+ "strict": true,
+ "skipLibCheck": true,
+ "isolatedModules": true,
+ "sourceMap": false
+ },
+ "include": ["./**/*.ts", "../cypress.config.ts"],
+ "exclude": []
+}
diff --git a/package.json b/package.json
index 82b38fd1..c944e563 100644
--- a/package.json
+++ b/package.json
@@ -18,6 +18,7 @@
"lint_lib": "wireit",
"lint_app": "wireit",
"lint": "wireit",
+ "cypress_typecheck": "wireit",
"ng": "ng",
"start": "wireit",
"prepare": "husky install",
@@ -127,10 +128,21 @@
"test_ci": {
"dependencies": [
"build",
+ "cypress_typecheck",
"cypress_serve",
"cypress_run"
]
},
+ "cypress_typecheck": {
+ "command": "tsc -p cypress/tsconfig.json --noEmit --pretty false",
+ "files": [
+ "cypress/**/*.ts",
+ "cypress/tsconfig.json",
+ "cypress.config.ts",
+ "tsconfig.json"
+ ],
+ "output": []
+ },
"ng_serve": {
"command": "ng serve --port 4242",
"service": true
diff --git a/tsconfig.json b/tsconfig.json
index 6f2dfcc7..35acab54 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -22,5 +22,6 @@
},
"angularCompilerOptions": {
"strictTemplates": true
- }
+ },
+ "exclude": ["cypress", "cypress.config.ts"]
}