Skip to content

Commit 54cd2ce

Browse files
authored
chore: adds cypress component tests (#710)
* chore: adds cypress screenshot integration Signed-off-by: Anthony D. Mays <[email protected]> * chore: splits coverage script * chore: adds cypress component tests to build * chore: adds missing env variable for cypress tests Signed-off-by: Anthony D. Mays <[email protected]> * chore: attempts to fix env variable issue Signed-off-by: Anthony D. Mays <[email protected]> * chore: revert previous change Signed-off-by: Anthony D. Mays <[email protected]> * chore: add env variable to build script Signed-off-by: Anthony D. Mays <[email protected]> --------- Signed-off-by: Anthony D. Mays <[email protected]>
1 parent 1995bdb commit 54cd2ce

File tree

15 files changed

+2039
-724
lines changed

15 files changed

+2039
-724
lines changed

.github/workflows/check_fullstack_demo_ts_pr.yaml

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ jobs:
2828
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: ${{ secrets.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY }}
2929
run: |
3030
npm ci
31-
npm run test
31+
npm run test
32+
33+
- name: Run Cypress component tests
34+
uses: cypress-io/github-action@v6
35+
env:
36+
NEXT_PUBLIC_API_URL: http://localhost:8080
37+
with:
38+
working-directory: ./lib/javascript/fullstack_demo
39+
component: true

lib/javascript/fullstack_demo/.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@ yarn-error.log*
4444
next-env.d.ts
4545

4646
# database
47-
db.json
47+
db.json
48+
49+
# Cypress
50+
/cypress/snapshots/actual
51+
/cypress/snapshots/diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { defineConfig } from 'cypress';
2+
import { configureVisualRegression } from 'cypress-visual-regression';
3+
4+
export default defineConfig({
5+
component: {
6+
devServer: {
7+
framework: 'next',
8+
bundler: 'webpack',
9+
},
10+
env: {
11+
visualRegressionType: 'regression',
12+
},
13+
screenshotsFolder: './cypress/snapshots/actual',
14+
setupNodeEvents(on, config) {
15+
configureVisualRegression(on);
16+
},
17+
},
18+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { addCompareSnapshotCommand } from 'cypress-visual-regression/dist/command';
2+
addCompareSnapshotCommand();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<title>Components App</title>
8+
<!-- Used by Next.js to inject CSS. -->
9+
<div id="__next_css__DO_NOT_USE__"></div>
10+
</head>
11+
<body>
12+
<div data-cy-root></div>
13+
</body>
14+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// ***********************************************************
2+
// This example support/component.ts is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import '../../src/app/globals.css';
18+
import './commands';
19+
20+
import { mount } from 'cypress/react';
21+
22+
// Augment the Cypress namespace to include type definitions for
23+
// your custom command.
24+
// Alternatively, can be defined in cypress/support/component.d.ts
25+
// with a <reference path="./component" /> at the top of your spec.
26+
declare global {
27+
namespace Cypress {
28+
interface Chainable {
29+
mount: typeof mount;
30+
}
31+
}
32+
}
33+
34+
Cypress.Commands.add('mount', mount);
35+
36+
// Example use:
37+
// cy.mount(<MyComponent />)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"ts-node": {
3+
"transpileOnly": true,
4+
"compilerOptions": {
5+
"module": "ES2015"
6+
}
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @ts-check
2+
3+
/** @type {import('next').NextConfig} */
4+
const nextConfig = {
5+
/* config options here */
6+
};
7+
8+
export default nextConfig;

lib/javascript/fullstack_demo/next.config.ts

-7
This file was deleted.

0 commit comments

Comments
 (0)