Skip to content

Commit

Permalink
test(ui-form-field): add next js to regression tests
Browse files Browse the repository at this point in the history
Closes: INSTUI-3743, INSTUI-3999
  • Loading branch information
joyenjoyer committed Jun 18, 2024
1 parent d463dbc commit 9af67fb
Show file tree
Hide file tree
Showing 126 changed files with 10,211 additions and 487 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/ssr-regression.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: SSR Regression Tests
on:
# Trigger the workflow on push or pull request,
# but only for the master branch
push:
branches:
- master
jobs:
ssr-regression:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cypress run
uses: cypress-io/github-action@v6
with:
working-directory: ./regression-test
build: npm run build
start: npm start
1 change: 1 addition & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default defineConfig({
},
screenshotOnRunFailure: false,
component: {
excludeSpecPattern: 'regression-test/**',
devServer: {
framework: 'react',
bundler: 'webpack',
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions regression-test/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
next-env.d.ts
3 changes: 3 additions & 0 deletions regression-test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
46 changes: 36 additions & 10 deletions regression-test/.gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
dist/
public/bundle.*
node_modules/
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/out/
.

# production
/build
/src/.next/
/.next/


# misc
.DS_Store
*.pem

# debug
npm-debug.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
22 changes: 7 additions & 15 deletions regression-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@ This app is a target against our regression testing workflow. It simply renders

The regression testing suite is fairly simple at this point, it will only check a couple of things:

- use the latest snapshot version of instui
- check whether every component is in a renderable state (simply render them)
- check whether any error/warning is thrown inside the application
- use the latest snapshot version of InstUI
- check components are in a renderable state (simply render them)

## Run the regeression tests locally

Run `prepare.js` to fetch latest snapshot versions

```sh
# cwd: regression-test
node ./prepare.js
```
## Run the regression tests locally

In order to run the test you have to have it's dependencies installed. (this project is not a workspace of the main instui project)

Expand All @@ -24,18 +16,18 @@ In order to run the test you have to have it's dependencies installed. (this pro
npm install
```

Then build the project(with `esbuild`):
Then build the project:

```sh
# cwd: regression-test
npm run build:esbuild
npm run build
```

The regression testing tool (`testcafe`) will test the app in a real browser, so we have to have a server serving our application:
The regression testing tool will test the app in a real browser, so we have to have a server serving our application:

```sh
# cwd: regression-test
npm run serve
npm run start
```

Now you can run the test suite:
Expand Down
9 changes: 9 additions & 0 deletions regression-test/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
}
}
})
31 changes: 31 additions & 0 deletions regression-test/cypress/e2e/spec.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
describe('regression test', () => {
it('open dialog subpage', () => {
cy.visit('http://localhost:3000')
cy.get('a').contains('dialog').click()
cy.get('button').click()
cy.get('body').should('contain', 'Full name')
cy.get('[class$="closeButton"]').click()
})

it('open alert subpage', () => {
cy.visit('http://localhost:3000')
cy.get('a').contains('alert').click()
// cy.get('button').click()
cy.get('body').should('contain', 'Sample info text')
// cy.get('[class$="closeButton"]').click()
})

it('open breadcrumb subpage', () => {
cy.visit('http://localhost:3000')
cy.get('a').contains('breadcrumb').click()
cy.get('body').should('contain', 'Rabbit Is Rich')
cy.get('body').contains('The Rabbit Novels').click()
const redirect = 'https://instructure.design'
cy.origin(redirect, { args: { redirect } }, ({ redirect }) => {
cy.log(redirect)
cy.location().should((loc) => {
loc.href.includes(redirect)
})
})
})
})
37 changes: 37 additions & 0 deletions regression-test/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
20 changes: 20 additions & 0 deletions regression-test/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.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')
56 changes: 0 additions & 56 deletions regression-test/esbuild.cjs

This file was deleted.

4 changes: 4 additions & 0 deletions regression-test/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;
Loading

0 comments on commit 9af67fb

Please sign in to comment.