test: sending messages

This commit is contained in:
Guillaume Chau
2020-10-17 13:03:30 +02:00
parent 9825e47ac2
commit dbcff5eb5f
8 changed files with 126 additions and 40 deletions
@@ -15,5 +15,6 @@ module.exports = {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'comma-dangle': ['error', 'always-multiline'],
'@typescript-eslint/no-var-requires': 'off',
}
}
@@ -15,8 +15,10 @@
"dependencies": {
"@apollo/client": "^3.2.1",
"@vue/apollo-composable": "^4.0.0-alpha.10",
"apollo-server": "^2.18.2",
"apollo-server-express": "^2.18.2",
"core-js": "^3.6.5",
"cors": "^2.8.5",
"express": "^4.17.1",
"graphql": "^15.3.0",
"shortid": "^2.2.15",
"vue": "^3.0.0",
@@ -35,6 +37,7 @@
"@vue/compiler-sfc": "^3.0.0",
"@vue/eslint-config-standard": "^5.1.2",
"@vue/eslint-config-typescript": "^5.0.2",
"axios": "^0.20.0",
"eslint": "^6.7.2",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
+35 -18
View File
@@ -1,6 +1,6 @@
/* eslint-disable */
const { gql, ApolloServer, ApolloError, PubSub, withFilter } = require('apollo-server')
const express = require('express')
const cors = require('cors')
const { gql, ApolloServer, ApolloError, PubSub, withFilter } = require('apollo-server-express')
const shortid = require('shortid')
const typeDefs = gql`
@@ -45,18 +45,24 @@ type Subscription {
const pubsub = new PubSub()
const channels = [
{
id: 'general',
label: 'General',
messages: [],
},
{
id: 'random',
label: 'Random',
messages: [],
},
]
let channels = []
function resetDatabase () {
channels = [
{
id: 'general',
label: 'General',
messages: [],
},
{
id: 'random',
label: 'Random',
messages: [],
},
]
}
resetDatabase()
const resolvers = {
Query: {
@@ -111,13 +117,24 @@ const resolvers = {
},
}
const app = express()
app.use(cors('*'))
app.get('/_reset', (req, res) => {
resetDatabase()
res.status(200).end()
})
const server = new ApolloServer({
typeDefs,
resolvers,
})
server.listen({
server.applyMiddleware({ app })
app.listen({
port: 4042,
}).then(({ url }) => {
console.log(`🚀 Server ready at ${url}`)
}, () => {
console.log('🚀 Server ready at http://localhost:4042')
})
@@ -4,5 +4,5 @@ const cache = new InMemoryCache()
export const apolloClient = new ApolloClient({
cache,
uri: 'http://localhost:4042',
uri: 'http://localhost:4042/graphql',
})
@@ -13,7 +13,7 @@ export default defineComponent({
<template>
<div>
<div class="inline-block bg-green-100 border border-green-200 rounded-2xl px-4 py-2">
<div class="message inline-block bg-green-100 border border-green-200 rounded-2xl px-4 py-2">
{{ message.text }}
</div>
</div>
@@ -9,12 +9,21 @@
// /* eslint-disable import/no-extraneous-dependencies, global-require */
// const webpack = require('@cypress/webpack-preprocessor')
const axios = require('axios')
module.exports = (on, config) => {
// on('file:preprocessor', webpack({
// webpackOptions: require('@vue/cli-service/webpack.config'),
// watchOptions: {}
// }))
on('task', {
async 'db:reset' () {
await axios.get('http://localhost:4042/_reset')
return true
},
})
return Object.assign({}, config, {
fixturesFolder: 'tests/e2e/fixtures',
integrationFolder: 'tests/e2e/specs',
@@ -1,5 +1,8 @@
/// <reference types="Cypress" />
describe('Vue 3 + Apollo Composable', () => {
beforeEach(() => {
cy.task('db:reset')
cy.visit('/')
})
@@ -14,4 +17,38 @@ describe('Vue 3 + Apollo Composable', () => {
cy.get('.channel-link').eq(0).click()
cy.contains('#app', 'Currently viewing # General')
})
it('sends a message', () => {
cy.get('.channel-link').eq(0).click()
cy.get('input').type('Hello{enter}')
cy.get('.message').should('have.lengthOf', 1)
cy.contains('.message', 'Hello')
cy.get('input').should('have', 'value', '')
cy.get('.channel-link').eq(1).click()
cy.get('.message').should('have.lengthOf', 0)
cy.reload()
cy.get('.channel-link').eq(0).click()
cy.get('.message').should('have.lengthOf', 1)
cy.contains('.message', 'Hello')
})
it('sends multiple messages', () => {
cy.get('.channel-link').eq(1).click()
cy.get('input').type('Message 1{enter}')
.type('Message 2{enter}')
.type('Message 3{enter}')
cy.get('.message').should('have.lengthOf', 3)
cy.contains('.message', 'Message 1')
cy.contains('.message', 'Message 2')
cy.contains('.message', 'Message 3')
cy.get('input').should('have', 'value', '')
cy.get('.channel-link').eq(0).click()
cy.get('.message').should('have.lengthOf', 0)
cy.reload()
cy.get('.channel-link').eq(1).click()
cy.get('.message').should('have.lengthOf', 3)
cy.contains('.message', 'Message 1')
cy.contains('.message', 'Message 2')
cy.contains('.message', 'Message 3')
})
})
+38 -19
View File
@@ -4239,17 +4239,6 @@ apollo-server-types@^0.6.0:
apollo-server-caching "^0.5.2"
apollo-server-env "^2.4.5"
apollo-server@^2.18.2:
version "2.18.2"
resolved "https://registry.yarnpkg.com/apollo-server/-/apollo-server-2.18.2.tgz#de55a8b7e90e6ddaba29331ecc9469d6945fff23"
integrity sha512-I8B7Zd7WrqUhOWAVMQRmKhgJkvdTlCY7C74WToCdkeOyHl1/myiA7tERKedgv111xOTpIMZHyBzcCRX5CH/oqQ==
dependencies:
apollo-server-core "^2.18.2"
apollo-server-express "^2.18.2"
express "^4.0.0"
graphql-subscriptions "^1.0.0"
graphql-tools "^4.0.0"
apollo-tracing@^0.11.4:
version "0.11.4"
resolved "https://registry.yarnpkg.com/apollo-tracing/-/apollo-tracing-0.11.4.tgz#e953547064bc50dfa337cbe56836271bfd2d2efc"
@@ -4604,6 +4593,13 @@ axios@^0.19.2:
dependencies:
follow-redirects "1.5.10"
axios@^0.20.0:
version "0.20.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.20.0.tgz#057ba30f04884694993a8cd07fa394cff11c50bd"
integrity sha512-ANA4rr2BDcmmAQLOKft2fufrtuvlqR+cXNNinUmvfeSNCOF98PZL+7M/v1zIdGo7OLjEA9J2gXJL+j4zGsl0bA==
dependencies:
follow-redirects "^1.10.0"
babel-code-frame@^6.22.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
@@ -6185,7 +6181,7 @@ core-util-is@1.0.2, core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
cors@^2.8.4:
cors@^2.8.4, cors@^2.8.5:
version "2.8.5"
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
@@ -7547,7 +7543,23 @@ eslint-plugin-vue@^7.0.0-0:
semver "^7.3.2"
vue-eslint-parser "^7.1.0"
eslint-scope@^3.7.1, eslint-scope@^4.0.0, eslint-scope@^4.0.3, eslint-scope@^5.0.0:
eslint-scope@^3.7.1:
version "3.7.3"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-3.7.3.tgz#bb507200d3d17f60247636160b4826284b108535"
integrity sha512-W+B0SvF4gamyCTmUc+uITPY0989iXVfKvhwtmJocTaYoc/3khEHmEmvfY/Gn9HA9VV75jrQECsHizkNw1b68FA==
dependencies:
esrecurse "^4.1.0"
estraverse "^4.1.1"
eslint-scope@^4.0.0, eslint-scope@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-4.0.3.tgz#ca03833310f6889a3264781aa82e63eb9cfe7848"
integrity sha512-p7VutNr1O/QrxysMo3E45FjYDTeXBy0iTltPFNSqKAIfjDSXC+4dj+qfyuD8bfAXrW/y6lW3O76VaYNPKfpKrg==
dependencies:
esrecurse "^4.1.0"
estraverse "^4.1.1"
eslint-scope@^5.0.0:
version "5.1.1"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c"
integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==
@@ -7755,7 +7767,7 @@ esquery@^1.0.0, esquery@^1.0.1:
dependencies:
estraverse "^5.1.0"
esrecurse@^4.3.0:
esrecurse@^4.1.0, esrecurse@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/esrecurse/-/esrecurse-4.3.0.tgz#7ad7964d679abb28bee72cec63758b1c5d2c9921"
integrity sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==
@@ -7965,7 +7977,7 @@ expect@^24.9.0:
jest-message-util "^24.9.0"
jest-regex-util "^24.9.0"
express@^4.0.0, express@^4.16.3, express@^4.17.1:
express@^4.16.3, express@^4.17.1:
version "4.17.1"
resolved "https://registry.yarnpkg.com/express/-/express-4.17.1.tgz#4491fc38605cf51f8629d39c2b5d026f98a4c134"
integrity sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==
@@ -8373,7 +8385,7 @@ follow-redirects@1.5.10:
dependencies:
debug "=3.1.0"
follow-redirects@^1.0.0:
follow-redirects@^1.0.0, follow-redirects@^1.10.0:
version "1.13.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db"
integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==
@@ -9034,11 +9046,18 @@ graphql-upload@^8.0.2:
http-errors "^1.7.3"
object-path "^0.11.4"
graphql@*, "graphql@14.0.2 - 14.2.0 || ^14.3.1 || ^15.0.0", graphql@15.3.0, graphql@^14.0.2, graphql@^14.5.8, graphql@^15.3.0:
graphql@*, "graphql@14.0.2 - 14.2.0 || ^14.3.1 || ^15.0.0", graphql@^15.3.0:
version "15.3.0"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-15.3.0.tgz#3ad2b0caab0d110e3be4a5a9b2aa281e362b5278"
integrity sha512-GTCJtzJmkFLWRfFJuoo9RWWa/FfamUHgiFosxi/X1Ani4AVWbeyBenZTNX6dM+7WSbbFfTo/25eh0LLkwHMw2w==
graphql@^14.0.2, graphql@^14.5.8:
version "14.7.0"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-14.7.0.tgz#7fa79a80a69be4a31c27dda824dc04dac2035a72"
integrity sha512-l0xWZpoPKpppFzMfvVyFmp9vLN7w/ZZJPefUicMCepfJeQ8sMcztloGYY9DfjVPo6tIUDzU5Hw3MUbIjj9AVVA==
dependencies:
iterall "^1.2.2"
gray-matter@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/gray-matter/-/gray-matter-4.0.2.tgz#9aa379e3acaf421193fce7d2a28cebd4518ac454"
@@ -10281,7 +10300,7 @@ istanbul-reports@^2.2.6:
dependencies:
html-escaper "^2.0.0"
iterall@^1.1.3, iterall@^1.2.1:
iterall@^1.1.3, iterall@^1.2.1, iterall@^1.2.2:
version "1.3.0"
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.3.0.tgz#afcb08492e2915cbd8a0884eb93a8c94d0d72fea"
integrity sha512-QZ9qOMdF+QLHxy1QIpUHUU1D5pS2CG2P69LF6L6CPjPYA/XMOmKV3PZpawHoAjHNyB0swdVTRxdYT4tbBbxqwg==
@@ -15693,7 +15712,7 @@ stylus@^0.54.5, stylus@^0.54.8:
semver "^6.3.0"
source-map "^0.7.3"
subscriptions-transport-ws@0.9.18, subscriptions-transport-ws@^0.9.11, subscriptions-transport-ws@^0.9.16:
subscriptions-transport-ws@^0.9.11, subscriptions-transport-ws@^0.9.16:
version "0.9.18"
resolved "https://registry.yarnpkg.com/subscriptions-transport-ws/-/subscriptions-transport-ws-0.9.18.tgz#bcf02320c911fbadb054f7f928e51c6041a37b97"
integrity sha512-tztzcBTNoEbuErsVQpTN2xUNN/efAZXyCyL5m3x4t6SKrEiTL2N8SaKWBFWM4u56pL79ULif3zjyeq+oV+nOaA==