Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Yagudaev yagudaev

View GitHub Profile
@yagudaev
yagudaev / elasticsearch.sh
Created Aug 26, 2020
Install a specific version of elastic search using Homebrew
View elasticsearch.sh
brew tap elastic/tap
# picks a specific version
cd /usr/local/Homebrew/Library/Taps/elastic/homebrew-tap
git fetch --tags
git checkout tags/v7.2.0
cd -
HOMEBREW_NO_AUTO_UPDATE=1 brew install elastic/tap/elasticsearch-full
@yagudaev
yagudaev / cypress_support_hooks.js
Last active Sep 16, 2021
Cypress Fetch Support Workaround - replaces fetch request with traditional XHR so cypress can track them
View cypress_support_hooks.js
// cypress/support/hooks.js
// Cypress does not support listening to the fetch method
// Therefore, as a workaround we polyfill `fetch` with traditional XHR which
// are supported. See: https://github.com/cypress-io/cypress/issues/687
enableFetchWorkaround()
// private helpers
function enableFetchWorkaround() {
let polyfill
View files_controller.rb
class Api::V1::FilesController < ActiveStorage::DirectUploadsController
skip_forgery_protection
end
@yagudaev
yagudaev / cypress-taking-shortcuts.js
Created Jan 21, 2019
Testing Your Frontend with Cypress.io Framework
View cypress-taking-shortcuts.js
// cypress/support/commands.js
Cypress.Commands.add('login', (email, password) => {
cy.request({
method: 'POST',
url: 'http://localhost:300/api/v1/users/login',
body: {
user: {
email,
password
}
@yagudaev
yagudaev / cypress-resetting-state-do.js
Created Jan 21, 2019
Testing Your Frontend with Cypress.io Framework
View cypress-resetting-state-do.js
// This is what you want...
describe('Shopping Cart', () => {
before(() => {
cy.login('michael@example.com', 'password')
})
beforeEach(() => {
resetShoppingCart()
})
@yagudaev
yagudaev / resetting-state-dont.js
Created Jan 21, 2019
Testing Your Frontend with Cypress.io Framework
View resetting-state-dont.js
// not great...
describe('Shopping Cart', () => {
before(() => {
cy.login('michael@example.com', 'password')
})
it('add item to cart', () => {
cy.visit('/products/fidget-spinner-1')
cy.contains('Add To Cart').click()
cy.contains('Show Cart').click()
@yagudaev
yagudaev / error.js
Created Jan 21, 2019
Testing Your Frontend with Cypress.io Framework
View error.js
renderWelcome() {
// oooppps, did we mean logins?
if (props.user.pro && props.user.login.length === 1) {
return <p>Thank you for supporting us!</p>
} else {
return <p>Welcome back {props.user.firstName}</p>
}
}
@yagudaev
yagudaev / cypress_integration_login.pro.spec.js
Last active Feb 25, 2019
Testing Your Frontend with Cypress.io Framework
View cypress_integration_login.pro.spec.js
it('A Pro User logs in and sees a thank you message for the first time', () => {
loginWith('new-pro@example.com', 'passsword')
expect(cy.contains('Thank you for supporting us!')).to.exist
})
it('A Pro User logs in and sees and sees a welcome message', () => {
loginWith('old-pro@example.com', 'passsword')
expect(cy.contains('Welcome back John')).to.exist
})
@yagudaev
yagudaev / cypress_integration_login.spec.js
Last active Feb 25, 2019
Testing Your Frontend with Cypress.io Framework
View cypress_integration_login.spec.js
// cypress/integration/login.spec.js
describe('login', () => {
beforeEach(() => {
visitLoginPage()
})
it('A User logs in and sees a welcome message', () => {
loginWith('michael@example.com', 'passsword')
expect(cy.contains('Welcome back Michael')).to.exist
@yagudaev
yagudaev / login.spec.js
Last active Feb 25, 2019
Testing Your Frontend with Cypress.io Framework
View login.spec.js
// cypress/integration/login.spec.js
describe('login', () => {
beforeEach(() => {
visitLoginPage()
})
it('A User logs in and sees a welcome message', () => {
loginWith('michael@example.com', 'passsword')
expect(cy.contains('Welcome back Michael')).to.exist