...

Text file src/github.com/99designs/gqlgen/TESTING.md

Documentation: github.com/99designs/gqlgen

     1How to write tests for gqlgen
     2===
     3
     4Testing generated code is a little tricky, heres how its currently set up.
     5
     6### Testing responses from a server
     7
     8There is a server in `codegen/testserver` that is generated as part
     9of `go generate ./...`, and tests written against it.
    10
    11There are also a bunch of tests in against the examples, feel free to take examples from there.
    12
    13
    14### Testing the errors generated by the binary
    15
    16These tests are **really** slow, because they need to run the whole codegen step. Use them very sparingly. If you can, find a way to unit test it instead.
    17
    18Take a look at `codegen/testserver/input_test.go` for an example.
    19
    20### Testing introspection
    21
    22Introspection is tested by diffing the output of `graphql get-schema` against an expected output.
    23
    24Setting up the integration environment is a little tricky:
    25```bash
    26cd integration
    27go generate ./...
    28go run ./server/cmd/integration/server.go
    29```
    30in another terminal
    31```bash
    32cd integration
    33npm install
    34./node_modules/.bin/graphql-codegen
    35```
    36
    37will write the schema to `integration/schema-fetched.graphql`, compare that with `schema-expected.graphql`
    38
    39CI will run this and fail the build if the two files don't match.

View as plain text