Skip to content

Commit b7279f1

Browse files
committed
test: add Playwright and Cypress E2E tests for iframe preview testing
1 parent dff2ce0 commit b7279f1

11 files changed

Lines changed: 1964 additions & 1 deletion

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ duplicates.json
2323

2424
coverage
2525

26-
*.tsbuildinfo
26+
*.tsbuildinfo
27+
test-results/
28+
cypress/videos/
29+
cypress/screenshots/

cypress.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from 'cypress';
2+
3+
export default defineConfig({
4+
allowCypressEnv: false,
5+
e2e: {
6+
baseUrl: 'http://localhost:8000',
7+
setupNodeEvents(on, config) {
8+
// implement node event listeners here
9+
}
10+
}
11+
});

cypress/.eslintrc.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"env": {
3+
"browser": true
4+
},
5+
"globals": {
6+
"cy": "readonly",
7+
"describe": "readonly",
8+
"it": "readonly",
9+
"beforeEach": "readonly",
10+
"before": "readonly",
11+
"after": "readonly",
12+
"afterEach": "readonly",
13+
"expect": "readonly",
14+
"Cypress": "readonly",
15+
"context": "readonly"
16+
}
17+
}

cypress/e2e/editor.cy.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
describe('p5.js Editor - Cypress', () => {
2+
function dismissCookies() {
3+
cy.get('button').then(($buttons) => {
4+
const dismiss = [...$buttons].find((b) =>
5+
/accept|ok|got it|agree|close|dismiss|continue/i.test(
6+
b.textContent || ''
7+
)
8+
);
9+
if (dismiss) cy.wrap(dismiss).click({ force: true });
10+
});
11+
}
12+
13+
function clickPlayButton() {
14+
cy.get('[aria-label="Play sketch"]').click({ force: true });
15+
}
16+
17+
it('editor loads and has a sketch iframe', () => {
18+
cy.visit('/');
19+
dismissCookies();
20+
clickPlayButton();
21+
cy.get('iframe', { timeout: 15000 }).should('exist');
22+
});
23+
24+
it('can access iframe content frame', () => {
25+
cy.visit('/');
26+
dismissCookies();
27+
cy.get('iframe').then(($iframe) => {
28+
// Cypress iframe workaround — needs .contents() jQuery hack
29+
const body = $iframe.contents().find('body');
30+
cy.wrap(body).should('exist');
31+
});
32+
});
33+
34+
it('run button triggers sketch, checks iframe src', () => {
35+
cy.visit('/');
36+
dismissCookies();
37+
clickPlayButton();
38+
cy.get('iframe', { timeout: 15000 })
39+
.should('have.attr', 'src')
40+
.and('include', 'localhost:8002');
41+
});
42+
});

cypress/fixtures/example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "hello@cypress.io",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

cypress/support/commands.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************
3+
// This example commands.ts shows you how to
4+
// create various custom commands and overwrite
5+
// existing commands.
6+
//
7+
// For more comprehensive examples of custom
8+
// commands please read more here:
9+
// https://on.cypress.io/custom-commands
10+
// ***********************************************
11+
//
12+
//
13+
// -- This is a parent command --
14+
// Cypress.Commands.add('login', (email, password) => { ... })
15+
//
16+
//
17+
// -- This is a child command --
18+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19+
//
20+
//
21+
// -- This is a dual command --
22+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23+
//
24+
//
25+
// -- This will overwrite an existing command --
26+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27+
//
28+
// declare global {
29+
// namespace Cypress {
30+
// interface Chainable {
31+
// login(email: string, password: string): Chainable<void>
32+
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
33+
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
34+
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
35+
// }
36+
// }
37+
// }

cypress/support/e2e.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// ***********************************************************
2+
// This example support/e2e.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 './commands';

0 commit comments

Comments
 (0)