-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
[WIP] test: setup cypress for e2e testing #120
Open
elianiva
wants to merge
14
commits into
master
Choose a base branch
from
test/e2e-cypress
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
33babdf
test: setup cypress for e2e testing
elianiva b6db96a
lol why is this even here
elianiva b312f01
i forgot to make my code pretty
elianiva d881b40
backend was missing @vitest/c8
elianiva 2ae2a01
add cypress type reference to prevent errors
elianiva 6d6f612
initial cypress CI setup
elianiva cb12a6b
fix cypress action path
elianiva 655cecd
sadpepe
elianiva ca4c2f2
もう一回
elianiva 02acb25
this is why I don't like this stuff
elianiva 18850bb
try separating install and tests step
elianiva c40d809
gatau deh
elianiva da31aa8
gw maling
elianiva 919a59d
arrghhh
elianiva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ jobs: | |
with: | ||
version: 7 | ||
run_install: false | ||
|
||
- name: Get pnpm store directory | ||
id: pnpm-cache | ||
run: | | ||
|
@@ -43,16 +43,30 @@ jobs: | |
- name: Format with prettier | ||
run: pnpm run -r fmt:check | ||
|
||
- name: Test | ||
- name: Unit Test (Backend) | ||
run: pnpm --filter "{packages/backend}" test | ||
env: | ||
NODE_ENV: test | ||
|
||
- name: Collect coverage | ||
- name: Collect coverage (Backend) | ||
run: pnpm --filter "{packages/backend}" test:coverage | ||
env: | ||
NODE_ENV: test | ||
|
||
- name: Cypress pnpm patch | ||
run: cp pnpm-lock.yaml package-lock.json | ||
|
||
- name: E2E Test (Frontend) | ||
uses: cypress-io/[email protected] | ||
with: | ||
browser: chrome | ||
working-directory: src/packages/frontend/cypress | ||
install-command: echo | ||
build: pnpm --dir .. build | ||
start: pnpm --dir .. start | ||
wait-on: 'http://localhost:4173' | ||
component: false | ||
|
||
- name: Send coverage report to Codecov | ||
uses: codecov/codecov-action@v2 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,16 +43,30 @@ jobs: | |
- name: Format with prettier | ||
run: pnpm run -r fmt:check | ||
|
||
- name: Test | ||
- name: Unit Test (Backend) | ||
run: pnpm --filter "{packages/backend}" test | ||
env: | ||
NODE_ENV: test | ||
|
||
- name: Collect coverage | ||
- name: Collect coverage (Backend) | ||
run: pnpm --filter "{packages/backend}" test:coverage | ||
env: | ||
NODE_ENV: test | ||
|
||
- name: Cypress pnpm patch | ||
run: cp pnpm-lock.yaml package-lock.json | ||
|
||
- name: E2E Test (Frontend) | ||
uses: cypress-io/[email protected] | ||
with: | ||
browser: chrome | ||
working-directory: src/packages/frontend/cypress | ||
install-command: echo | ||
build: pnpm --dir .. build | ||
start: pnpm --dir .. start | ||
wait-on: 'http://localhost:4173' | ||
component: false | ||
|
||
- name: Send coverage report to Codecov | ||
uses: codecov/codecov-action@v2 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules | ||
dist | ||
dist | ||
cypress/videos | ||
cypress/screenshots |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from 'cypress'; | ||
|
||
export default defineConfig({ | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
config.baseUrl = 'http://localhost:5173'; | ||
return config; | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/// <reference types="cypress" /> | ||
|
||
beforeEach(() => { | ||
cy.visit('/'); | ||
}); | ||
|
||
describe('Documentation', () => { | ||
it('shows documentation title', () => { | ||
cy.get('#documentation').contains('Documentation for Graphene API'); | ||
}); | ||
|
||
it('shows several API options documentation', () => { | ||
cy.get('.OptionItem').should('have.length.gt', 0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/// <reference types="cypress" /> | ||
|
||
beforeEach(() => { | ||
cy.visit('/'); | ||
}); | ||
|
||
describe('Editor', () => { | ||
it('shows the Editor component', () => { | ||
cy.get('.Editor').should('be.visible'); | ||
}); | ||
|
||
it('shows the preview placeholder', () => { | ||
cy.get('.preview-placeholder').should('be.visible'); | ||
}); | ||
|
||
it('shows setting popup toggle button', () => { | ||
cy.get('.SettingsPopup').should('be.visible'); | ||
}); | ||
|
||
it('shows popup menu when toggle button is clicked', () => { | ||
cy.get('.SettingsPopup > button').click(); | ||
cy.get('.popup').should('be.visible'); | ||
}); | ||
|
||
it('should be able to use the textarea to type the code', () => { | ||
cy.get('.editor-input').type("console.log('foo');"); | ||
}); | ||
}); | ||
|
||
describe('Autocomplete', () => { | ||
it('shows autocomplete menu when dropdown is clicked', () => { | ||
cy.get('.Options .input').first().click(); | ||
cy.get('.candidates li').should('have.length.gt', 1); | ||
}); | ||
|
||
it('should be able to select one of the option', () => { | ||
cy.get('.Options .input').first().should('have.attr', 'placeholder', 'github dark dimmed').click(); | ||
cy.get('.candidates > li').first().click(); | ||
cy.get('.Options .input').first().should('have.attr', 'placeholder', 'css variables'); | ||
}); | ||
|
||
it('should be able to select one of the suggested option', () => { | ||
cy.get('.Options .input').first().should('have.attr', 'placeholder', 'github dark dimmed').click().type('github'); | ||
cy.get('.candidates li').last().click(); | ||
cy.get('.Options .input').first().should('have.attr', 'placeholder', 'github light'); | ||
}); | ||
|
||
it('shows suggestions when some text is inserted', () => { | ||
const incompleteTexts = [ | ||
// theme | ||
'github', | ||
// language | ||
'script', | ||
// font family | ||
'mono', | ||
// output format | ||
'png', | ||
]; | ||
|
||
// desktop | ||
cy.viewport('macbook-13'); | ||
for (const [index, text] of incompleteTexts.entries()) { | ||
const input = cy.get('.Options .input').eq(index); | ||
input.focus().type(text); | ||
cy.get('.candidates li') | ||
.should('have.length.at.least', 1) | ||
.each(($li) => cy.wrap($li).contains(text)); | ||
input.blur(); | ||
} | ||
|
||
// mobile | ||
cy.viewport('iphone-xr'); | ||
cy.get('.SettingsPopup > button').click(); | ||
for (const [index, text] of incompleteTexts.entries()) { | ||
const input = cy.get('.Options .input').eq(index); | ||
input.focus().type(text); | ||
cy.get('.candidates li') | ||
.should('have.length.at.least', 1) | ||
.each(($li) => cy.wrap($li).contains(text)); | ||
input.blur(); | ||
} | ||
}); | ||
|
||
it('should not show any suggestion on garbled input', () => { | ||
cy.get('.Options .input').first().type('alksjdlaksjdlkajsdlkaj'); | ||
cy.get('.candidate li').should('have.length.lt', 1); | ||
}); | ||
}); | ||
|
||
describe('Responsive Dropdown', () => { | ||
type Screen = { width: number; height: number; optionAmount: number }; | ||
|
||
it('shows different amount of dropdown inputs based on screen size', () => { | ||
const screens: Screen[] = [ | ||
// desktop 1080p / FHD screen | ||
{ width: 1920, height: 1080, optionAmount: 4 }, | ||
// desktop 768p / HD screen | ||
{ width: 1366, height: 768, optionAmount: 4 }, | ||
// large screen | ||
{ width: 1100, height: 720, optionAmount: 3 }, | ||
// medium screen | ||
{ width: 1000, height: 720, optionAmount: 2 }, | ||
// small screen | ||
{ width: 800, height: 600, optionAmount: 1 }, | ||
// extra small screen | ||
{ width: 600, height: 400, optionAmount: 0 }, | ||
]; | ||
|
||
for (const screen of screens) { | ||
cy.viewport(screen.width, screen.height); | ||
cy.get('.Options').should('have.length', screen.optionAmount); | ||
} | ||
}); | ||
|
||
it('shows different amount of dropdown inside the popup menu based on screen size', () => { | ||
const screens: Screen[] = [ | ||
// desktop 1080p / FHD screen | ||
{ width: 1920, height: 1080, optionAmount: 0 }, | ||
// desktop 768p / HD screen | ||
{ width: 1366, height: 768, optionAmount: 0 }, | ||
// large screen | ||
{ width: 1100, height: 720, optionAmount: 1 }, | ||
// medium screen | ||
{ width: 1000, height: 720, optionAmount: 2 }, | ||
// small screen | ||
{ width: 800, height: 600, optionAmount: 3 }, | ||
// extra small screen | ||
{ width: 600, height: 400, optionAmount: 4 }, | ||
]; | ||
|
||
cy.get('.SettingsPopup > button').click(); | ||
for (const screen of screens) { | ||
cy.viewport(screen.width, screen.height); | ||
cy.get('.popup > .Options').should('have.length', screen.optionAmount); | ||
} | ||
}); | ||
}); | ||
|
||
describe('Popup menu', () => { | ||
it('should be able to select upscale option', () => { | ||
cy.get('.SettingsPopup > button').click(); | ||
const upscaleItem = cy.get('.upscale > .upscale-item').last(); | ||
upscaleItem.last().should('have.css', 'opacity', '0.5'); | ||
upscaleItem.last().click(); | ||
upscaleItem.last().should('have.css', 'opacity', '1'); | ||
}); | ||
|
||
it('should be able to input border thickness and radius', () => { | ||
cy.get('.SettingsPopup > button').click(); | ||
cy.get('.border-input').each(($input) => { | ||
cy.wrap($input).type('12'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/// <reference types="cypress" /> | ||
|
||
beforeEach(() => { | ||
cy.visit('/'); | ||
}); | ||
|
||
describe('Header', () => { | ||
it('shows the app title and subtitle', () => { | ||
cy.get('.title').contains('GRAPHENE'); | ||
cy.get('.subtitle').contains('Create and share beautiful code snippets!'); | ||
}); | ||
|
||
it('shows a github button to graphene repository', () => { | ||
cy.get('.button') | ||
.contains('See on Github') | ||
.should('have.attr', 'href', 'https://github.com/teknologi-umum/graphene'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "Using fixtures to represent data", | ||
"email": "[email protected]", | ||
"body": "Fixtures are a great way to mock data for responses to routes" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
// } | ||
// } | ||
// } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong yaml indentation