Skip to content

Commit

Permalink
c14: ci: downgrade vite to support component tests (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonfelixrico authored Apr 6, 2024
1 parent e423af8 commit c8cae3d
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 113 deletions.
7 changes: 7 additions & 0 deletions client/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ export default defineConfig({
viewportHeight: 1080,
viewportWidth: 1920,
},

component: {
devServer: {
framework: 'react',
bundler: 'vite',
},
},
})
7 changes: 7 additions & 0 deletions client/cypress/e2e/pad-socket.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ describe('pad-socket', () => {
]

cy.visit(`/rooms/${getRoomId()}`)
/*
* This wait is to let the pad be able to do the catch-up (or at least partially)
* Without this, local tests can fail
* TODO remove this once we've found a way to check if catch-up is done
*/
cy.wait(1_000)

cy.getCy('pad')
.should('exist')
.then(() => {
Expand Down
8 changes: 8 additions & 0 deletions client/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,13 @@ Cypress.Commands.add(
}
)

/*
* This is needed to prevent Cypress from failing the test if uncaught exceptions are found, i.e.
* uncaught HTTP errors from API calls
*/
Cypress.on('uncaught:exception', () => {
return false
})

// Without this, TS will complain
export {}
12 changes: 12 additions & 0 deletions client/cypress/support/component-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Components App</title>
</head>
<body>
<div data-cy-root></div>
</body>
</html>
41 changes: 41 additions & 0 deletions client/cypress/support/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint-disable @typescript-eslint/no-namespace */

// ***********************************************************
// This example support/component.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')

import { mount } from 'cypress/react18'

// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.
declare global {
namespace Cypress {
interface Chainable {
mount: typeof mount
}
}
}

Cypress.Commands.add('mount', mount)

// Example use:
// cy.mount(<MyComponent />)
10 changes: 6 additions & 4 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build:clean": "rm -rf ./dist",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"format": "prettier --write ./**/*.{js,ts,tsx,css,md,json}",
"format": "prettier --write './**/*.{js,ts,tsx,css,md,json}'",
"preview": "vite preview",
"cypress:open": "cypress open",
"test:e2e": "cypress run",
"test:e2e:server": "cd ../server && yarn build && yarn start"
"test:e2e": "cypress run --spec './cypress/e2e/**/*.cy.ts'",
"test:e2e:server": "cd ../server && yarn build && yarn start",
"test:component": "cypress run --spec './cypress/component/**/*.cy.ts'"
},
"dependencies": {
"@reduxjs/toolkit": "^2.2.1",
Expand Down Expand Up @@ -55,6 +57,6 @@
"prettier": "^3.2.5",
"sass": "^1.72.0",
"typescript": "^5.2.2",
"vite": "^5.1.4"
"vite": "^4"
}
}
Loading

0 comments on commit c8cae3d

Please sign in to comment.