Skip to content

Commit f3db4d9

Browse files
committed
test: init e2e composable vue3
1 parent 72d7402 commit f3db4d9

29 files changed

+1021
-38
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
> 1%
2+
last 2 versions
3+
not dead
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[*.{js,jsx,ts,tsx,vue}]
2+
indent_style = space
3+
indent_size = 2
4+
trim_trailing_whitespace = true
5+
insert_final_newline = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
node: true
5+
},
6+
extends: [
7+
'plugin:vue/vue3-essential',
8+
'@vue/standard',
9+
'@vue/typescript/recommended'
10+
],
11+
parserOptions: {
12+
ecmaVersion: 2020
13+
},
14+
rules: {
15+
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
16+
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
17+
'comma-dangle': ['error', 'always-multiline'],
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.DS_Store
2+
node_modules
3+
/dist
4+
5+
/tests/e2e/videos/
6+
/tests/e2e/screenshots/
7+
8+
9+
# local env files
10+
.env.local
11+
.env.*.local
12+
13+
# Log files
14+
npm-debug.log*
15+
yarn-debug.log*
16+
yarn-error.log*
17+
pnpm-debug.log*
18+
19+
# Editor directories and files
20+
.idea
21+
.vscode
22+
*.suo
23+
*.ntvs*
24+
*.njsproj
25+
*.sln
26+
*.sw?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# test-e2e-global-composable-vue3
2+
3+
## Project setup
4+
```
5+
yarn install
6+
```
7+
8+
### Compiles and hot-reloads for development
9+
```
10+
yarn serve
11+
```
12+
13+
### Compiles and minifies for production
14+
```
15+
yarn build
16+
```
17+
18+
### Run your end-to-end tests
19+
```
20+
yarn test:e2e
21+
```
22+
23+
### Lints and fixes files
24+
```
25+
yarn lint
26+
```
27+
28+
### Customize configuration
29+
See [Configuration Reference](https://cli.vuejs.org/config/).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
presets: [
3+
'@vue/cli-plugin-babel/preset'
4+
]
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"pluginsFile": "tests/e2e/plugins/index.js"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "test-e2e-global-composable-vue3",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"serve": "vue-cli-service serve",
7+
"build": "vue-cli-service build",
8+
"test:e2e": "vue-cli-service test:e2e",
9+
"lint": "vue-cli-service lint",
10+
"api": "node server.js"
11+
},
12+
"dependencies": {
13+
"@apollo/client": "^3.2.1",
14+
"@vue/apollo-composable": "^4.0.0-alpha.10",
15+
"apollo-server": "^2.18.2",
16+
"core-js": "^3.6.5",
17+
"graphql": "^15.3.0",
18+
"shortid": "^2.2.15",
19+
"vue": "^3.0.0",
20+
"vue-demi": "^0.4.0"
21+
},
22+
"devDependencies": {
23+
"@types/shortid": "^0.0.29",
24+
"@typescript-eslint/eslint-plugin": "^2.33.0",
25+
"@typescript-eslint/parser": "^2.33.0",
26+
"@vue/cli-plugin-babel": "~4.5.0",
27+
"@vue/cli-plugin-e2e-cypress": "~4.5.0",
28+
"@vue/cli-plugin-eslint": "~4.5.0",
29+
"@vue/cli-plugin-typescript": "~4.5.0",
30+
"@vue/cli-service": "~4.5.0",
31+
"@vue/compiler-sfc": "^3.0.0",
32+
"@vue/eslint-config-standard": "^5.1.2",
33+
"@vue/eslint-config-typescript": "^5.0.2",
34+
"eslint": "^6.7.2",
35+
"eslint-plugin-import": "^2.20.2",
36+
"eslint-plugin-node": "^11.1.0",
37+
"eslint-plugin-promise": "^4.2.1",
38+
"eslint-plugin-standard": "^4.0.0",
39+
"eslint-plugin-vue": "^7.0.0-0",
40+
"typescript": "^4.0.3"
41+
}
42+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
8+
<title><%= htmlWebpackPlugin.options.title %></title>
9+
</head>
10+
<body>
11+
<noscript>
12+
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
13+
</noscript>
14+
<div id="app"></div>
15+
<!-- built files will be auto injected -->
16+
</body>
17+
</html>
+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
const { gql, ApolloServer, ApolloError, PubSub, withFilter } = require('apollo-server')
2+
const shortid = require('shortid')
3+
4+
const typeDefs = gql`
5+
type Channel {
6+
id: ID!
7+
label: String!
8+
messages: [Message!]!
9+
}
10+
11+
type Message {
12+
id: ID!
13+
channel: Channel!
14+
text: String!
15+
}
16+
17+
type Query {
18+
channels: [Channel!]!
19+
channel (id: ID!): Channel
20+
}
21+
22+
type Mutation {
23+
addMessage (input: AddMessageInput!): Message
24+
updateMessage (input: UpdateMessageInput!): Message
25+
}
26+
27+
input AddMessageInput {
28+
channelId: ID!
29+
text: String!
30+
}
31+
32+
input UpdateMessageInput {
33+
id: ID!
34+
channelId: ID!
35+
text: String!
36+
}
37+
38+
type Subscription {
39+
messageAdded (channelId: ID!): Message!
40+
messageUpdated (channelId: ID!): Message!
41+
}
42+
`
43+
44+
const pubsub = new PubSub()
45+
46+
const channels = [
47+
{
48+
id: 'general',
49+
label: 'General',
50+
messages: [],
51+
},
52+
{
53+
id: 'random',
54+
label: 'Random',
55+
messages: [],
56+
},
57+
]
58+
59+
const resolvers = {
60+
Query: {
61+
channels: () => channels,
62+
channel: (root, { id }) => channels.find(c => c.id === id),
63+
},
64+
65+
Mutation: {
66+
addMessage: (root, { input }) => {
67+
const channel = channels.find(c => c.id === input.channelId)
68+
if (!channel) {
69+
throw new ApolloError(`Channel ${input.channelId} not found`, 'not-found')
70+
}
71+
const message = {
72+
id: shortid(),
73+
channel: channel,
74+
text: input.text,
75+
}
76+
channel.messages.push(message)
77+
pubsub.publish('messageAdded', { messageAdded: message })
78+
return message
79+
},
80+
81+
updateMessage: (root, { input }) => {
82+
const channel = channels.find(c => c.id === input.channelId)
83+
if (!channel) {
84+
throw new ApolloError(`Channel ${input.channelId} not found`, 'not-found')
85+
}
86+
const message = channel.messages.find(m => m.id === input.id)
87+
Object.assign(message, {
88+
text: input.text,
89+
})
90+
pubsub.publish('messageUpdated', { messageUpdated: message })
91+
return message
92+
}
93+
},
94+
95+
Subscription: {
96+
messageAdded: {
97+
subscribe: withFilter(
98+
() => pubsub.asyncIterator('messageAdded'),
99+
(payload, variables) => payload.messageAdded.channel.id === variables.channelId,
100+
),
101+
},
102+
103+
messageUpdated: {
104+
subscribe: withFilter(
105+
() => pubsub.asyncIterator('messageUpdated'),
106+
(payload, variables) => payload.messageUpdated.channel.id === variables.channelId,
107+
),
108+
},
109+
},
110+
}
111+
112+
const server = new ApolloServer({
113+
typeDefs,
114+
resolvers,
115+
})
116+
117+
server.listen({
118+
port: 4042,
119+
}).then(({ url }) => {
120+
console.log(`🚀 Server ready at ${url}`);
121+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<ChannelList />
3+
</template>
4+
5+
<script lang="ts">
6+
import { defineComponent } from 'vue'
7+
import ChannelList from './components/ChannelList.vue'
8+
9+
export default defineComponent({
10+
name: 'App',
11+
12+
components: {
13+
ChannelList,
14+
},
15+
})
16+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ApolloClient, InMemoryCache } from '@apollo/client/core'
2+
3+
const cache = new InMemoryCache()
4+
5+
export const apolloClient = new ApolloClient({
6+
cache,
7+
uri: 'http://localhost:4042',
8+
})
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<script lang="ts">
2+
import { gql } from '@apollo/client/core'
3+
import { useQuery, useResult } from '@vue/apollo-composable'
4+
import { defineComponent } from 'vue'
5+
6+
interface Channel {
7+
id: string;
8+
label: string;
9+
}
10+
11+
export default defineComponent({
12+
setup () {
13+
const { result, loading } = useQuery<{ channels: Channel[] }>(gql`
14+
query channels {
15+
channels {
16+
id
17+
label
18+
}
19+
}
20+
`)
21+
const channels = useResult(result, [])
22+
23+
return {
24+
loading,
25+
channels,
26+
}
27+
},
28+
})
29+
</script>
30+
31+
<template>
32+
<div v-if="loading">
33+
Loading channels...
34+
</div>
35+
36+
<template v-else>
37+
<button
38+
v-for="channel of channels"
39+
:key="channel.id"
40+
class="block"
41+
>
42+
{{ channel.label }}
43+
</button>
44+
</template>
45+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { createApp, h, provide } from 'vue'
2+
import { DefaultApolloClient } from '../../vue-apollo-composable/dist'
3+
import { apolloClient } from './apollo'
4+
import App from './App.vue'
5+
6+
createApp({
7+
setup () {
8+
provide(DefaultApolloClient, apolloClient)
9+
},
10+
render: () => h(App),
11+
}).mount('#app')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare module '*.vue' {
2+
import type { DefineComponent } from 'vue'
3+
const component: DefineComponent
4+
export default component
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
plugins: [
3+
'cypress'
4+
],
5+
env: {
6+
mocha: true,
7+
'cypress/globals': true
8+
},
9+
rules: {
10+
strict: 'off'
11+
}
12+
}

0 commit comments

Comments
 (0)