Skip to content

Commit 0ecb7f7

Browse files
Alan-ChaErikWittern
authored andcommitted
Tests in Typescript
Signed-off-by: Alan Cha <[email protected]>
1 parent 47c6b47 commit 0ecb7f7

11 files changed

+121
-96
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
"test": "cd packages/openapi-to-graphql/ && npm test"
66
},
77
"devDependencies": {
8+
"@types/jest": "^24.0.15",
89
"graphql": "^14.0.2",
9-
"lerna": "^3.4.3"
10+
"jest": "^24.8.0",
11+
"lerna": "^3.4.3",
12+
"ts-jest": "^24.0.2",
13+
"typescript": "^3.5.3"
1014
},
1115
"engines": {
1216
"node": ">=8"

packages/openapi-to-graphql/package.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@
5252
"pre-commit": "pretty-quick --staged"
5353
}
5454
},
55+
"jest": {
56+
"moduleFileExtensions": [
57+
"ts",
58+
"tsx",
59+
"js"
60+
],
61+
"transform": {
62+
"\\.(ts|tsx)$": "ts-jest"
63+
},
64+
"testRegex": "/test/.*\\.test\\.(ts|tsx|js)$"
65+
},
5566
"dependencies": {
5667
"@types/request": "^2.48.1",
5768
"debug": "^4.1.0",
@@ -68,23 +79,25 @@
6879
},
6980
"devDependencies": {
7081
"@types/graphql": "^14.0.3",
82+
"@types/jest": "^24.0.15",
7183
"@types/node": "^11.9.4",
7284
"body-parser": "^1.18.3",
7385
"express": "^4.16.4",
7486
"express-graphql": "^0.7.1",
7587
"glob": "^7.1.3",
7688
"husky": "^2.3.0",
7789
"isomorphic-git": "^0.51.6",
78-
"jest": "^24.0.0",
90+
"jest": "^24.8.0",
7991
"js-yaml": "^3.13.1",
8092
"nodemon": "^1.18.10",
8193
"prettier": "^1.17.1",
8294
"pretty-quick": "^1.11.0",
8395
"rimraf": "^2.6.1",
8496
"simple-statistics": "^7.0.0",
8597
"standard": "^12.0.1",
98+
"ts-jest": "^24.0.2",
8699
"tslint": "^5.11.0",
87100
"tslint-config-standard": "^8.0.1",
88-
"typescript": "^3.1.3"
101+
"typescript": "^3.5.3"
89102
}
90103
}

packages/openapi-to-graphql/test/authentication.test.js renamed to packages/openapi-to-graphql/test/authentication.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
/* globals beforeAll, test, expect */
99

10-
const openapiToGraphql = require('../lib/index.js')
11-
const { graphql } = require('graphql')
10+
import * as openapiToGraphql from '../lib/index.js'
11+
import { graphql } from 'graphql'
1212

13-
let oas = require('./fixtures/example_oas.json')
13+
const oas = require('./fixtures/example_oas.json')
1414
const PORT = 3003
1515
// update PORT for this test case:
1616
oas.servers[0].variables.port.default = String(PORT)
@@ -124,7 +124,7 @@ test('Get project using API key 1', () => {
124124
})
125125

126126
test('Get project using API key passed as option - viewer is disabled', async () => {
127-
let { schema } = await openapiToGraphql.createGraphQlSchema(oas, {
127+
const { schema } = await openapiToGraphql.createGraphQlSchema(oas, {
128128
viewer: false,
129129
headers: {
130130
access_token: 'abcdef'
@@ -147,12 +147,13 @@ test('Get project using API key passed as option - viewer is disabled', async ()
147147
})
148148

149149
test('Get project using API key passed in the requestOptions - viewer is disabled', async () => {
150-
let { schema } = await openapiToGraphql.createGraphQlSchema(oas, {
150+
const { schema } = await openapiToGraphql.createGraphQlSchema(oas, {
151151
viewer: false,
152152
requestOptions: {
153153
headers: {
154154
access_token: 'abcdef'
155-
}
155+
},
156+
url: undefined
156157
}
157158
})
158159
const query = `{
@@ -270,7 +271,7 @@ test('Get project using API key 3', async () => {
270271
})
271272

272273
test('Get project using API key 3 passed as option - viewer is disabled', async () => {
273-
let { schema } = await openapiToGraphql.createGraphQlSchema(oas, {
274+
const { schema } = await openapiToGraphql.createGraphQlSchema(oas, {
274275
viewer: false,
275276
headers: {
276277
cookie: 'access_token=abcdef'
@@ -293,12 +294,13 @@ test('Get project using API key 3 passed as option - viewer is disabled', async
293294
})
294295

295296
test('Get project using API key 3 passed in the requestOptions - viewer is disabled', async () => {
296-
let { schema } = await openapiToGraphql.createGraphQlSchema(oas, {
297+
const { schema } = await openapiToGraphql.createGraphQlSchema(oas, {
297298
viewer: false,
298299
requestOptions: {
299300
headers: {
300301
cookie: 'access_token=abcdef'
301-
}
302+
},
303+
url: undefined
302304
}
303305
})
304306
const query = `{

packages/openapi-to-graphql/test/cloudfunction_oas.test.js renamed to packages/openapi-to-graphql/test/cloudfunction_oas.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77

88
/* globals beforeAll, test, expect */
99

10-
const openapiToGraphql = require('../lib/index.js')
10+
import * as openapiToGraphql from '../lib/index.js'
1111
const { parse, validate } = require('graphql')
1212

13-
let oas = require('./fixtures/cloudfunction_oas.json')
13+
const oas = require('./fixtures/cloudfunction_oas.json')
14+
1415
let createdSchema
1516

1617
beforeAll(async () => {
17-
let { schema } = await openapiToGraphql.createGraphQlSchema(oas)
18+
const { schema } = await openapiToGraphql.createGraphQlSchema(oas)
1819
createdSchema = schema
1920
})
2021

@@ -28,7 +29,7 @@ test('Get response', async () => {
2829
}
2930
}`
3031
// validate that 'limit' parameter is covered by options:
31-
let ast = parse(query)
32-
let errors = validate(createdSchema, ast)
32+
const ast = parse(query)
33+
const errors = validate(createdSchema, ast)
3334
expect(errors).toEqual([])
3435
})

packages/openapi-to-graphql/test/docusign.test.js renamed to packages/openapi-to-graphql/test/docusign.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
/* globals test, expect */
99

10-
const openapiToGraphql = require('../lib/index.js')
10+
import * as openapiToGraphql from '../lib/index.js'
1111

12-
let oas = require('./fixtures/docusign_oas.json')
12+
const oas = require('./fixtures/docusign_oas.json')
1313

1414
test('Generate schema without problems', () => {
15-
let options = {
15+
const options = {
1616
strict: false
1717
}
1818
return openapiToGraphql

packages/openapi-to-graphql/test/example_api.test.js renamed to packages/openapi-to-graphql/test/example_api.test.ts

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77

88
/* globals beforeAll, test, expect */
99

10-
const openapiToGraphql = require('../lib/index.js')
10+
import * as openapiToGraphql from '../lib/index.js'
1111
const { graphql, parse, validate } = require('graphql')
1212
const { startServer, stopServer } = require('./example_api_server')
1313

14-
let createdSchema
15-
let oas = require('./fixtures/example_oas.json')
14+
const oas = require('./fixtures/example_oas.json')
1615
const PORT = 3002
1716
// update PORT for this test case:
1817
oas.servers[0].variables.port.default = String(PORT)
1918

19+
let createdSchema
20+
2021
/**
2122
* Set up the schema first and run example API server
2223
*/
@@ -841,12 +842,12 @@ test('Capitalized enum values can be returned', () => {
841842
})
842843

843844
test('Define header and query options', () => {
844-
let options = {
845+
const options = {
845846
headers: {
846847
exampleHeader: 'some-value'
847848
},
848849
qs: {
849-
limit: 30
850+
limit: '30'
850851
}
851852
}
852853
const query = `{
@@ -856,8 +857,8 @@ test('Define header and query options', () => {
856857
.createGraphQlSchema(oas, options)
857858
.then(({ schema }) => {
858859
// validate that 'limit' parameter is covered by options:
859-
let ast = parse(query)
860-
let errors = validate(schema, ast)
860+
const ast = parse(query)
861+
const errors = validate(schema, ast)
861862
expect(errors).toEqual([])
862863
return graphql(schema, query).then(result => {
863864
expect(result).toEqual({
@@ -922,7 +923,7 @@ test('Error contains extension', () => {
922923
})
923924

924925
test('Option provideErrorExtensions should prevent error extensions from being created', () => {
925-
let options = {
926+
const options = {
926927
provideErrorExtensions: false
927928
}
928929
const query = `query {
@@ -933,8 +934,8 @@ test('Option provideErrorExtensions should prevent error extensions from being c
933934
return openapiToGraphql
934935
.createGraphQlSchema(oas, options)
935936
.then(({ schema }) => {
936-
let ast = parse(query)
937-
let errors = validate(schema, ast)
937+
const ast = parse(query)
938+
const errors = validate(schema, ast)
938939
expect(errors).toEqual([])
939940
return graphql(schema, query).then(result => {
940941
expect(result).toEqual({
@@ -959,7 +960,7 @@ test('Option provideErrorExtensions should prevent error extensions from being c
959960
})
960961

961962
test('Option customResolver', () => {
962-
let options = {
963+
const options = {
963964
customResolvers: {
964965
'Example API': {
965966
'/users/{username}': {
@@ -980,8 +981,8 @@ test('Option customResolver', () => {
980981
return openapiToGraphql
981982
.createGraphQlSchema(oas, options)
982983
.then(({ schema }) => {
983-
let ast = parse(query)
984-
let errors = validate(schema, ast)
984+
const ast = parse(query)
985+
const errors = validate(schema, ast)
985986
expect(errors).toEqual([])
986987
return graphql(schema, query).then(result => {
987988
expect(result).toEqual({
@@ -996,7 +997,7 @@ test('Option customResolver', () => {
996997
})
997998

998999
test('Option customResolver with links', () => {
999-
let options = {
1000+
const options = {
10001001
customResolvers: {
10011002
'Example API': {
10021003
'/users/{username}': {
@@ -1026,8 +1027,8 @@ test('Option customResolver with links', () => {
10261027
return openapiToGraphql
10271028
.createGraphQlSchema(oas, options)
10281029
.then(({ schema }) => {
1029-
let ast = parse(query)
1030-
let errors = validate(schema, ast)
1030+
const ast = parse(query)
1031+
const errors = validate(schema, ast)
10311032
expect(errors).toEqual([])
10321033
return graphql(schema, query).then(result => {
10331034
expect(result).toEqual({
@@ -1050,7 +1051,7 @@ test('Option customResolver with links', () => {
10501051
})
10511052

10521053
test('Option customResolver using resolver arguments', () => {
1053-
let options = {
1054+
const options = {
10541055
customResolvers: {
10551056
'Example API': {
10561057
'/users/{username}': {
@@ -1071,8 +1072,8 @@ test('Option customResolver using resolver arguments', () => {
10711072
return openapiToGraphql
10721073
.createGraphQlSchema(oas, options)
10731074
.then(({ schema }) => {
1074-
let ast = parse(query)
1075-
let errors = validate(schema, ast)
1075+
const ast = parse(query)
1076+
const errors = validate(schema, ast)
10761077
expect(errors).toEqual([])
10771078
return graphql(schema, query).then(result => {
10781079
expect(result).toEqual({
@@ -1087,7 +1088,7 @@ test('Option customResolver using resolver arguments', () => {
10871088
})
10881089

10891090
test('Option customResolver using resolver arguments that are sanitized', () => {
1090-
let options = {
1091+
const options = {
10911092
customResolvers: {
10921093
'Example API': {
10931094
'/products/{product-id}': {
@@ -1110,8 +1111,8 @@ test('Option customResolver using resolver arguments that are sanitized', () =>
11101111
return openapiToGraphql
11111112
.createGraphQlSchema(oas, options)
11121113
.then(({ schema }) => {
1113-
let ast = parse(query)
1114-
let errors = validate(schema, ast)
1114+
const ast = parse(query)
1115+
const errors = validate(schema, ast)
11151116
expect(errors).toEqual([])
11161117
return graphql(schema, query).then(result => {
11171118
expect(result).toEqual({
@@ -1126,7 +1127,7 @@ test('Option customResolver using resolver arguments that are sanitized', () =>
11261127
})
11271128

11281129
test('Option addLimitArgument', () => {
1129-
let options = {
1130+
const options = {
11301131
addLimitArgument: true
11311132
}
11321133
const query = `query {
@@ -1146,8 +1147,8 @@ test('Option addLimitArgument', () => {
11461147
return openapiToGraphql
11471148
.createGraphQlSchema(oas, options)
11481149
.then(({ schema }) => {
1149-
let ast = parse(query)
1150-
let errors = validate(schema, ast)
1150+
const ast = parse(query)
1151+
const errors = validate(schema, ast)
11511152
expect(errors).toEqual([])
11521153
return graphql(schema, query).then(result => {
11531154
expect(result).toEqual({
@@ -1288,7 +1289,7 @@ test('Stringify objects without defined properties', () => {
12881289
})
12891290

12901291
test('Generate "Equivalent to..." messages', () => {
1291-
let options = {
1292+
const options = {
12921293
// Used to simplify test. Otherwise viewers will polute query/mutation fields.
12931294
viewer: false
12941295
}
@@ -1318,8 +1319,8 @@ test('Generate "Equivalent to..." messages', () => {
13181319
const promise = openapiToGraphql
13191320
.createGraphQlSchema(oas, options)
13201321
.then(({ schema }) => {
1321-
let ast = parse(query)
1322-
let errors = validate(schema, ast)
1322+
const ast = parse(query)
1323+
const errors = validate(schema, ast)
13231324
expect(errors).toEqual([])
13241325
return graphql(schema, query).then(result => {
13251326
// Make sure all query fields have the message
@@ -1381,7 +1382,7 @@ test('Generate "Equivalent to..." messages', () => {
13811382
})
13821383

13831384
test('Withhold "Equivalent to..." messages', () => {
1384-
let options = {
1385+
const options = {
13851386
// Used to simplify test. Otherwise viewers will polute query/mutation fields.
13861387
viewer: false,
13871388
equivalentToMessages: false
@@ -1412,8 +1413,8 @@ test('Withhold "Equivalent to..." messages', () => {
14121413
const promise = openapiToGraphql
14131414
.createGraphQlSchema(oas, options)
14141415
.then(({ schema }) => {
1415-
let ast = parse(query)
1416-
let errors = validate(schema, ast)
1416+
const ast = parse(query)
1417+
const errors = validate(schema, ast)
14171418
expect(errors).toEqual([])
14181419
return graphql(schema, query).then(result => {
14191420
expect(
@@ -1445,8 +1446,8 @@ test('Withhold "Equivalent to..." messages', () => {
14451446
const promise2 = openapiToGraphql
14461447
.createGraphQlSchema(oas, options)
14471448
.then(({ schema }) => {
1448-
let ast = parse(query)
1449-
let errors = validate(schema, ast)
1449+
const ast = parse(query)
1450+
const errors = validate(schema, ast)
14501451
expect(errors).toEqual([])
14511452
return graphql(schema, query2).then(result => {
14521453
expect(

0 commit comments

Comments
 (0)