-
Notifications
You must be signed in to change notification settings - Fork 0
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
testの準備 #11
Merged
Merged
testの準備 #11
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:jest/recommended", | ||
"airbnb-base" | ||
] | ||
} |
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,3 @@ | ||
node_modules/ | ||
lib/ | ||
coverage/ |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
transform: { | ||
'^.+\\.js$': '<rootDir>/node_modules/babel-jest', | ||
'.*\\.(ts)$': '<rootDir>/node_modules/ts-jest', | ||
}, | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
rules: { | ||
'import/no-extraneous-dependencies': ['error', { | ||
devDependencies: true, | ||
optionalDependencies: false, | ||
}], | ||
} | ||
}; |
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,40 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Mutations returns user 1`] = ` | ||
Object { | ||
"data": Object { | ||
"login": Object { | ||
"accessToken": "69:q1aXhT-onz4sWejxcV1s", | ||
"createdAt": "2018-03-31T07:35:05.000Z", | ||
"email": "[email protected]", | ||
"icon": null, | ||
"id": 69, | ||
"name": "MyString", | ||
"selfIntroduction": null, | ||
"updatedAt": "2018-03-31T07:35:05.000Z", | ||
}, | ||
}, | ||
"errors": undefined, | ||
"extensions": undefined, | ||
"http": Object { | ||
"headers": Headers { | ||
Symbol(map): Object {}, | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`Queries returns pong 1`] = ` | ||
Object { | ||
"data": Object { | ||
"ping": "pong", | ||
}, | ||
"errors": undefined, | ||
"extensions": undefined, | ||
"http": Object { | ||
"headers": Headers { | ||
Symbol(map): Object {}, | ||
}, | ||
}, | ||
} | ||
`; |
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,45 @@ | ||
import { createTestClient } from 'apollo-server-testing'; | ||
import { gql } from 'apollo-server-express'; | ||
|
||
import server from '..'; | ||
|
||
const PING = gql` | ||
query { | ||
ping | ||
} | ||
`; | ||
|
||
const LOGIN = gql` | ||
mutation login($email: String!, $password: String!) { | ||
login(email: $email, password: $password) { | ||
id | ||
icon | ||
name | ||
accessToken | ||
createdAt | ||
updatedAt | ||
selfIntroduction | ||
} | ||
} | ||
`; | ||
|
||
describe('Queries', () => { | ||
it('returns pong ', async () => { | ||
const { query } = createTestClient(server); | ||
const res = await query({ query: PING }); | ||
expect(res).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('Mutations', () => { | ||
it('returns user', async () => { | ||
const { mutate } = createTestClient(server); | ||
const res = await mutate({ | ||
query: undefined, | ||
mutation: LOGIN, | ||
variables: { email: '[email protected]', password: 'password' }, | ||
} as any); | ||
expect(res).toMatchSnapshot(); | ||
}); | ||
}); |
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,17 @@ | ||
import { resolvers } from '../..'; | ||
|
||
describe('[Query.ping]', () => { | ||
it('returns user', async () => { | ||
const res = await resolvers.Mutation.login(); | ||
expect(res).toEqual({ | ||
id: 69, | ||
icon: null, | ||
email: '[email protected]', | ||
name: 'MyString', | ||
accessToken: '69:q1aXhT-onz4sWejxcV1s', | ||
createdAt: '2018-03-31T07:35:05.000Z', | ||
updatedAt: '2018-03-31T07:35:05.000Z', | ||
selfIntroduction: null, | ||
}); | ||
}); | ||
}); |
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,8 @@ | ||
import { resolvers } from '../..'; | ||
|
||
describe('[Query.ping]', () => { | ||
it('returns pong', async () => { | ||
const res = await resolvers.Query.ping(); | ||
expect(res).toEqual('pong'); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -380,7 +380,16 @@ const server = new ApolloServer({ | |
|
||
server.applyMiddleware({ app, cors: { credentials: true, origin: CLIENT_HOST } }); | ||
|
||
app.listen({ port: PORT }, () => { | ||
// eslint-disable-next-line no-console | ||
console.log(`🚀 Server ready at localhost:${PORT}${server.graphqlPath}`); | ||
}); | ||
if (process.env.NODE_ENV !== 'test') { | ||
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. 📝 fileを分けた時にこの分岐をなくす |
||
app.listen({ port: PORT }, () => { | ||
// eslint-disable-next-line no-console | ||
console.log(`🚀 Server ready at localhost:${PORT}${server.graphqlPath}`); | ||
}); | ||
} | ||
|
||
export default server; | ||
|
||
export { | ||
typeDefs, | ||
resolvers, | ||
}; |
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.
typescriptの型情報が間違ってるっぽいので、とりあえずanyで突っ込んでます。(良い解決策求む)
apollographql/apollo-server#2172
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.
ねえ、型って知ってる?
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.
別PRで対応