Skip to content

Feat/plugin basic UI #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ videos
coverage
dist
dump
dump_har
screenshots

# next.js
Expand Down
53 changes: 50 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cypress Debugger

Debug cypress tests in CI - use rrweb to capture the execution, and cypress hooks the capture cypress commands.
Debug cypress tests in CI - use rrweb to capture the execution, cypress hooks to capture cypress commands, and HttpArchive Generator to record the network.

## Development

Expand All @@ -16,7 +16,54 @@ Runs a few tests
```sh
cd apps/web
npm install
npx run cypress
npx cypress run
```

You will see new `json` files created in `apps/web/dump`. Each file contains fields: `cy`, `rr`, and `har`.

- `cy` - data from cypress events
- `rr` - data from the [rrweb](https://www.npmjs.com/package/rrweb)
- `har` - data from the [HttpArchive Generator]((https://github.com/NeuraLegion/cypress-har-generator))

Extract those fields and replace the contents of `cy.json`, `rr.json`, and `har.json` respectively in `apps/web/data`.

A basic UI that consumes the data from `apps/web/data` is available at http://localhost:3000/

### Notes

A `har.json` file could be visualized with [this tool](https://toolbox.googleapps.com/apps/har_analyzer/)

The [HAR generator](https://github.com/NeuraLegion/cypress-har-generator), currently, only supports Chrome family browsers. Please refer to [this](https://github.com/NeuraLegion/cypress-har-generator#generating-a-har-file) section in order to run cypress for other browsers.


## Usage

- call the `install` function inside the `setupNodeEvents` in the cypress config file:
```typescript
const { defineConfig } = require("cypress");
const { install } = require("@currents/cypress-debugger");

module.exports = defineConfig({
e2e: {
...
setupNodeEvents(on, config) {
install(on, config);
return config;
},
},
...
});
```

- call the `support` function in the `cypress/support/e2e` file:
```typescript
import { support } from "@currents/cypress-debugger";
import "./commands";

support();
beforeEach(() => {
cy.visit("/");
});

```

You will see new `json` files created in `apps/web/dump`. Each file contains fields: `cy` and `rr`. Extract those field and replace the contents of https://codesandbox.io/s/rr-cy-alt-h01293?file=/src/App.js
51 changes: 51 additions & 0 deletions apps/web/components/Collapsible/Collapsible.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.collapsible {

&_button {
background-color: darkgray;
color: white;
cursor: pointer;
padding: 7px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 12px;

&__active,
&:hover {
background-color: lightgray;
}
}

&_button-content {
display: flex;
}

&_chevron {
min-width: 12px;
padding-right: 2px;
position: relative;

&__active {
img {
rotate: 90deg;
}
}
}

&_title {
width: 100%;
}

&_content {
width: 100%;
padding: 0;
display: none;
overflow: auto;
background-color: #f1f1f1;

&__active {
display: block;
}
}
}
66 changes: 66 additions & 0 deletions apps/web/components/Collapsible/Collapsible.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import Image from "next/image";
import { useState } from "react";
import styles from "./Collapsible.module.scss";

export type CollapsibleElement = {
title: JSX.Element | string;
content: JSX.Element;
};

export function Collapsible({ elements }: { elements: CollapsibleElement[] }) {
const [opened, setOpened] = useState<number[]>([]);

const handleClick = (i: number) => {
setOpened((o) => {
if (o.includes(i)) {
const copy = o.slice();
copy.splice(
o.findIndex((e) => e === i),
1
);
return copy;
}

return [...o, i];
});
};

return (
<ul className={styles.collapsible}>
{elements.map((e, i) => (
<li key={i} className={styles["collapsible_element"]}>
<button
type="button"
className={styles["collapsible_button"]}
onClick={() => handleClick(i)}
>
<div className={styles["collapsible_button-content"]}>
<div
className={`${styles["collapsible_chevron"]} ${
opened.includes(i)
? styles["collapsible_chevron__active"]
: ""
}`}
>
<Image
src="/chevron.svg"
alt="chevron"
width={12}
height={12}
/>
</div>
<div className={styles["collapsible_title"]}>{e.title}</div>
</div>
</button>
<div
className={`${styles["collapsible_content"]} ${
opened.includes(i) ? styles["collapsible_content__active"] : ""
}`}
>
{e.content}
</div>
</li>
))}
</ul>
);
}
37 changes: 37 additions & 0 deletions apps/web/components/CySteps/CyStepItem.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.step {
cursor: pointer;
padding-left: 5px 0;

&__active {
background-color: darkgray;
}

&:hover {
background-color: lightgrey;
}

&_state {
font-size: 12px;
}

&_name {
font-weight: bold;
}

&_message {
font-size: 10px;
}

&_actions {
display: flex;
}

&_button {
cursor: pointer;
}

&_button:disabled {
cursor: not-allowed;
}

}
67 changes: 67 additions & 0 deletions apps/web/components/CySteps/CyStepItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { MouseEventHandler } from "react";
import { CypressStep } from "../../types";
import styles from "./CyStepItem.module.scss";

export function CyStepItem({
step,
active,
onClick,
onBefore,
onAfter,
}: {
step: CypressStep;
active: boolean;
onClick: () => void;
onBefore: (e: any) => void;
onAfter: (e: any) => void;
}) {
const payload = step.payload;

return (
<li
className={`${styles.step} ${active ? styles["step__active"] : ""}`}
onClick={onClick}
>
<span className={styles["step_state"]}>[{payload.state}]&nbsp;</span>
{payload.type === "child" && <span> - </span>}
<span className={styles["step_name"]}>{payload.name}</span>
<div className={styles["step_message"]}>{payload.message}</div>
<div className={styles["step_actions"]}>
{!!step.meta.before.rrId && (
<CyStepItemButton onClick={onBefore} disabled={!active}>
Before
</CyStepItemButton>
)}
{!!step.meta.after.rrId && (
<>
&nbsp;
<CyStepItemButton onClick={onAfter} disabled={!active}>
After
</CyStepItemButton>
</>
)}
</div>
</li>
);
}

const CyStepItemButton = ({
children,
onClick,
disabled,
}: {
children: string | JSX.Element;
onClick: MouseEventHandler<HTMLButtonElement>;
disabled?: boolean;
}) => {
return (
<button
type="button"
className={styles["step_button"]}
onClick={onClick}
disabled={disabled}
>
{children}
</button>
);
};
4 changes: 4 additions & 0 deletions apps/web/components/CySteps/CySteps.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.steps {
height: 700px;
overflow: auto;
}
34 changes: 34 additions & 0 deletions apps/web/components/CySteps/CySteps.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { CypressStep } from "../../types";
import { CyStepItem } from "./CyStepItem";
import styles from "./CySteps.module.scss";

export function CySteps({
steps,
activeStep,
setActiveStep,
onBefore,
onAfter,
}: {
steps: CypressStep[];
activeStep: number;
setActiveStep: (i: number) => void;
onBefore: (e: any) => void;
onAfter: (e: any) => void;
}) {
if (!steps.length) return null;

return (
<ul className={styles.steps}>
{steps.map((s, i) => (
<CyStepItem
key={s.id}
step={s}
active={activeStep === i}
onClick={() => setActiveStep(i)}
onBefore={onBefore}
onAfter={onAfter}
/>
))}
</ul>
);
}
32 changes: 32 additions & 0 deletions apps/web/components/Layout/Layout.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.layout {
min-width: 1000px;
overflow: auto;

&_top-block {
height: 50px;
}

&_main-block {
display: flex;
}

&_content,
&_left-sidebar,
&_right-sidebar {
border: 1px solid #ccc;
display: flex;
}

&_left-sidebar {
max-width: 250px;
}

&_right-sidebar {
max-width: 250px;
}

&_content {
display: flex;
flex-grow: 1;
}
}
Loading