Skip to content

Commit 9c9d5c6

Browse files
committed
Add tests for the interceptor & version endpoints
1 parent f4e20ed commit 9c9d5c6

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

custom-typings/graphql.js.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module 'graphql.js';

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"build:src": "rm -rf lib && tsc -b",
1919
"build:pack": "oclif-dev manifest && oclif-dev pack",
2020
"prepack": "npm run build:src && oclif-dev manifest",
21-
"test": "mocha -r ts-node/register 'test/**/*.spec.ts'"
21+
"test": "TS_NODE_FILES=true mocha -r ts-node/register 'test/**/*.spec.ts'"
2222
},
2323
"repository": "httptoolkit/httptoolkit-server",
2424
"homepage": "https://github.com/httptoolkit/httptoolkit-server",
@@ -52,6 +52,7 @@
5252
"@types/tmp": "0.0.33",
5353
"@types/ws": "^6.0.1",
5454
"chai": "^4.2.0",
55+
"graphql.js": "^0.6.1",
5556
"mocha": "^5.2.0",
5657
"request": "^2.88.0",
5758
"request-promise-native": "^1.0.5",

test/integration-test.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import * as path from 'path';
33
import { getRemote } from 'mockttp';
44
import * as request from 'request-promise-native';
55

6+
import * as getGraphQL from 'graphql.js';
7+
68
import { delay } from '../src/util';
79
import { expect } from 'chai';
810

911
describe('Integration test', function () {
12+
// Timeout needs to be long, as first test runs (e.g. in CI) generate
13+
// fresh certificates, which can take a little while.
1014
this.timeout(30000);
1115

1216
let serverProcess: ChildProcess;
@@ -59,4 +63,46 @@ describe('Integration test', function () {
5963

6064
expect(response).to.equal('Mock response');
6165
});
66+
67+
it('exposes the version over HTTP', async () => {
68+
const graphql = getGraphQL('http://localhost:45457/', { asJSON: true });
69+
70+
const response = await graphql(`
71+
query getVersion {
72+
version
73+
}
74+
`)();
75+
76+
expect(response.version).to.equal(require('../package.json').version);
77+
});
78+
79+
it('exposes interceptors over HTTP', async () => {
80+
const graphql = getGraphQL('http://localhost:45457/', { asJSON: true });
81+
82+
const response = await graphql(`
83+
query getInterceptors($proxyPort: Int!) {
84+
interceptors {
85+
id
86+
version
87+
isActive(proxyPort: $proxyPort)
88+
isActivable
89+
}
90+
}
91+
`)({ proxyPort: 8000 });
92+
93+
expect(response.interceptors).to.deep.equal([
94+
{
95+
"id": "fresh-chrome",
96+
"isActivable": true,
97+
"isActive": false,
98+
"version": "1.0.0"
99+
},
100+
{
101+
"id": "fresh-firefox",
102+
"isActivable": true,
103+
"isActive": false,
104+
"version": "1.0.0"
105+
}
106+
]);
107+
});
62108
});

0 commit comments

Comments
 (0)