Skip to content

Commit c73e24e

Browse files
authored
Add CI checks for formatting and typecheck
Add github CI workflow that triggers on any PRs and verifies: * Formatting is okay (via prettier) * Code typechecks (via typescript)
1 parent 0c06cc2 commit c73e24e

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: [master]
7+
8+
jobs:
9+
verify:
10+
name: Verify Files
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-node@v1
15+
- name: Install Packages
16+
run: yarn install --ignore-scripts
17+
- name: Check Formatting
18+
run: yarn prettier
19+
- name: Typecheck Files
20+
run: yarn tsc --noEmit

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "es5"
4+
}

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ setOptions({
111111
});
112112
```
113113

114-
115114
## Why not use `apollo-server-testing`?
116115

117116
You can't really write _real_ integration tests with `apollo-server-testing`, because it doesn't support servers which rely on the `context` option being a function that uses the `req` object ([see this issue for more information](https://github.com/apollographql/apollo-server/issues/2277)).
@@ -148,7 +147,7 @@ If you want to help out, here's a TODO list:
148147
- [x] Strip flow types before publishing (or switch to Typescript?)
149148
- [x] Compile to non-es6 module syntax
150149
- [ ] Add tests
151-
- [ ] Add auto-formatting
150+
- [x] Add auto-formatting
152151

153152
## Support
154153

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"clean": "rm -rf dist/",
2121
"compile": "tsc",
2222
"prepublish": "yarn clean && yarn compile",
23-
"dev": "tsc --watch"
23+
"dev": "tsc --watch",
24+
"prettier": "prettier --check src"
2425
},
2526
"dependencies": {
2627
"apollo-server-core": "^2.9.13",
@@ -31,7 +32,7 @@
3132
"devDependencies": {
3233
"husky": "^4.2.5",
3334
"lint-staged": "^10.2.11",
34-
"prettier": "^2.0.5",
35+
"prettier": "^2.1.2",
3536
"typescript": "^3.7.3"
3637
},
3738
"peerDependencies": {

src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import httpMocks, { RequestOptions, ResponseOptions } from 'node-mocks-http';
99
const mockRequest = (options: RequestOptions = {}) =>
1010
httpMocks.createRequest({
1111
method: 'POST',
12-
...options
12+
...options,
1313
});
1414

1515
const mockResponse = (options: ResponseOptions = {}) =>
@@ -71,7 +71,7 @@ export type TestSetOptions = (options: {
7171
export function createTestClient({
7272
apolloServer,
7373
extendMockRequest = {},
74-
extendMockResponse = {}
74+
extendMockResponse = {},
7575
}: TestClientConfig) {
7676
const app = express();
7777
apolloServer.applyMiddleware({ app });
@@ -86,7 +86,7 @@ export function createTestClient({
8686

8787
const setOptions: TestSetOptions = ({
8888
request,
89-
response
89+
response,
9090
}: {
9191
request?: RequestOptions;
9292
response?: ResponseOptions;
@@ -117,9 +117,9 @@ export function createTestClient({
117117
query: {
118118
// operation can be a string or an AST, but `runHttpQuery` only accepts a string
119119
query: typeof operation === 'string' ? operation : print(operation),
120-
variables
120+
variables,
121121
},
122-
request: convertNodeHttpToRequest(req)
122+
request: convertNodeHttpToRequest(req),
123123
});
124124

125125
return JSON.parse(graphqlResponse) as T;
@@ -128,6 +128,6 @@ export function createTestClient({
128128
return {
129129
query: test,
130130
mutate: test,
131-
setOptions
131+
setOptions,
132132
};
133133
}

yarn.lock

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,9 +1256,10 @@ please-upgrade-node@^3.2.0:
12561256
dependencies:
12571257
semver-compare "^1.0.0"
12581258

1259-
prettier@^2.0.5:
1260-
version "2.0.5"
1261-
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
1259+
prettier@^2.1.2:
1260+
version "2.1.2"
1261+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
1262+
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
12621263

12631264
proxy-addr@~2.0.5:
12641265
version "2.0.5"

0 commit comments

Comments
 (0)