-
Notifications
You must be signed in to change notification settings - Fork 1
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
Adicionar Cypress #8
Changes from all commits
d222cb7
05d9efc
a672de8
3a556a2
c5bac99
241c08c
6e7d246
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules/ | ||
*.swp | ||
public/dist.js | ||
public/dist.js | ||
cypress/videos |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const cypress = require('cypress') | ||
const serverManager = require('./test-server-manager') | ||
|
||
serverManager | ||
.start() | ||
.then((runningServer) => { | ||
cypress | ||
.run() | ||
.then(runningServer.stop) | ||
}) | ||
.catch(error => console.log(error.message)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const server = require('../server') | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Existe uma variável de ambiente chamada NODE_PATH que serve para que o node saiba onde buscar suas libs. O que acham disso? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Faz sentido. Eu estava receoso de que o Outro ponto é o de que estamos usando Jest, que possui seu próprio mecanismo de configuração do path, talvez faça sentido ver isso também. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Criei uma issue para trabalharmos nisso: #13 |
||
const serverStopper = (runningServer) => ({ | ||
stop: () => { | ||
runningServer.close() | ||
console.log('Test server stopped') | ||
} | ||
}) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Acho que essa closure ficou um pouco complexa. Talvez seja mais simples só fazer: const stopServer = (server) => {
server.close();
console.log('Test server stopped');
return server;
} Mais duas coisas:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Faz todo sentido, criei uma nova PR para simplifcar essa treta ☝️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Eu desconheço essa prática, pelo menos em JavaScript. Entendo que esta é uma prática muito relevante em Java, onde retornar um Acho que é seguro não retornar "nada" (funções retornam undefined quando não há There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Não é um problema grave não retornar nada, mas existem algumas razões do porque desta prática ser adotada:
E quanto a questão do Não é nada muito grave, mas aqui tem alguns exemplos do porque que é uma boa prática sempre retornar algo :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Não havia pensado por esse lado, faz todo sentido! Vejo muito valor nos pontos que tu citou, inclusive, uma função que não retorna nada geralmente indica sinais de side effects (que é o que acontece nessa situação aqui, por exemplo). Acho que talvez essa seja uma situação mais específica, já que estamos fazendo um "wrapping" do express, que não é lá muito funcional hehehe. Valeu pela explicação! 😃 |
||
const serverStarter = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mesmo comentário que ali em cima There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
start: () => new Promise((resolve, reject) => { | ||
const runningServer = server().listen(3000, () => { | ||
console.log('Test server started at ', 3000) | ||
|
||
return resolve(serverStopper(runningServer)) | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = serverStarter |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"videoRecording": false, | ||
"baseUrl": "http://localhost:3000" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
describe('Project List', () => { | ||
it('loads successfully', () => { | ||
cy.visit('/') | ||
}) | ||
|
||
it('has a title', () => { | ||
cy.get('h1').should('contain', 'Projetos') | ||
}) | ||
|
||
it('has the hardcoded project', () => { | ||
cy.get('ul > li:first').should('contain', 'Projeto 01') | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// *********************************************************** | ||
// This example plugins/index.js can be used to load plugins | ||
// | ||
// You can change the location of this file or turn off loading | ||
// the plugins file with the 'pluginsFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/plugins-guide | ||
// *********************************************************** | ||
|
||
// This function is called when a project is opened or re-opened (e.g. due to | ||
// the project's config changing) | ||
|
||
module.exports = (on, config) => { | ||
// `on` is used to hook into various events Cypress emits | ||
// `config` is the resolved Cypress config | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// *********************************************** | ||
// This example commands.js 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 is will overwrite an existing command -- | ||
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// *********************************************************** | ||
// This example support/index.js is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import './commands' | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
const express = require('express') | ||
const path = require('path') | ||
const server = require('./server') | ||
|
||
const PORT = process.env.PORT || 3000 | ||
|
||
express() | ||
.use(express.static(path.join(__dirname, 'public'))) | ||
.listen(PORT, () => console.log('Up on port', PORT)) | ||
server() | ||
.listen(PORT, () => console.log('Up on port', PORT)) |
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.
Qual versão do node estamos utilizando? Acho que seria interessante utilizar a última versão + plugins do babel para que possamos utilizar a syntax full ES6. Ficaria muito mais idiomático e fácil de entender isso aqui:
import cypress from 'cypress'
.O que pensam disso?
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.
Acho que o overhead (tempo de transpilação, muitos pacotes adicionais e configurações) adicionado pelo Babel não compensa o seu uso.
Sobre a questão da versão do node, é uma ótima pergunta! 😃 .
Idealmente, deveríamos configurar o npm e nossas demais dependências (Circle e Heroku, por exemplo) para reforçar o uso de uma versão recente e específica do node (talvez a 8 ou a 9).
Creio que seria uma boa criar uma issue para isso.
Acredito que estas versões mais recentes do node suportem praticamente todas as features do ES6, com exceção de
import/export
easync/await
, se não me engano.Eu acredito que usar
require
em vez deimport
seja menos doloroso do que configurar o Babel no momento.Faz sentido?