Skip to content

Commit 2e9e488

Browse files
committed
add new test, fixed error validator and add ext gql support
1 parent d53d20b commit 2e9e488

File tree

12 files changed

+286
-196
lines changed

12 files changed

+286
-196
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"jest/valid-expect-in-promise": 1,
2424
"jest/no-conditional-expect": 1,
2525
"no-mixed-spaces-and-tabs": 0,
26-
"no-unneeded-ternary": 0
26+
"no-unneeded-ternary": 0,
27+
"array-callback-return": 0
2728
},
2829
"env": {
2930
"node": true,

__test__/index.test.ts

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import { gtl } from '../src'
2-
import fs from 'fs-extra'
1+
import fs from 'fs'
32
import path from 'path'
3+
import { gtl } from '../src'
4+
import { matchProperty } from './../src/utils/matchProperty'
5+
import { fileCheck } from './../src/utils/fileCheck'
6+
import { fileValidator, optionsValidator, propertyValidator } from './../src/utils/validatorCheck'
47

58
describe('GTL Testing Group', function () {
69
beforeAll(function () {
@@ -15,21 +18,88 @@ describe('GTL Testing Group', function () {
1518

1619
it('Should be gtl read file inside multiple directory success', function () {
1720
const graphqlLoader = gtl({ directory: 'src', pattern: '**/*', fileName: 'isf.graphql' })
21+
22+
expect(graphqlLoader).toBeDefined()
1823
expect(graphqlLoader).toBeInstanceOf(Array)
1924
})
2025

2126
it('Should be gtl read file outside multiple directory success', function () {
2227
const graphqlLoader = gtl({ pattern: '**/*', fileName: 'osf.graphql' })
28+
29+
expect(graphqlLoader).toBeDefined()
2330
expect(graphqlLoader).toBeInstanceOf(Array)
2431
})
2532

2633
it('Should be gtl read file inside single directory success', function () {
2734
const graphqlLoader = gtl({ directory: 'src', fileName: 'isf.graphql' })
35+
36+
expect(graphqlLoader).toBeDefined()
2837
expect(graphqlLoader).toBeInstanceOf(Array)
2938
})
3039

3140
it('Should be gtl read file outside directory success', function () {
3241
const graphqlLoader = gtl({ fileName: 'osf.graphql' })
42+
43+
expect(graphqlLoader).toBeDefined()
44+
expect(graphqlLoader).toBeInstanceOf(Array)
45+
})
46+
47+
it('Should be gtl matchProperty success', function () {
48+
const defaultProperty = { directory: null, pattern: null, fileName: null, extension: null }
49+
const graphqlLoader = matchProperty(defaultProperty, { directory: null, pattern: null, fileName: null, extension: null })
50+
51+
expect(graphqlLoader).toBeDefined()
52+
expect(graphqlLoader).toBeTruthy()
53+
})
54+
55+
it('Should be gtl matchProperty error', function () {
56+
const defaultProperty = { directory: null, pattern: null, fileName: null, extension: null }
57+
const graphqlLoader = matchProperty(defaultProperty, { directoryx: null, patternx: null, fileNamex: null, extensionx: null })
58+
59+
expect(graphqlLoader).toBeDefined()
60+
expect(graphqlLoader).toBeFalsy()
61+
})
62+
63+
it('Should be gtl fileCheck success', function () {
64+
const gtlPRoperty = { directory: 'src', fileName: 'isf.graphql' }
65+
const graphqlLoader = fileCheck(gtlPRoperty)
66+
67+
expect(graphqlLoader).toBeDefined()
3368
expect(graphqlLoader).toBeInstanceOf(Array)
3469
})
70+
71+
it('Should be gtl fileValidator success', function () {
72+
const graphqlLoader = fileValidator({ extension: 'graphql' })
73+
74+
expect(graphqlLoader).toBeDefined()
75+
expect(graphqlLoader).toBeTruthy()
76+
})
77+
78+
it('Should be gtl fileValidator error', function () {
79+
const graphqlLoader = fileValidator({ extension: 'ts' })
80+
81+
expect(graphqlLoader).toBeDefined()
82+
expect(graphqlLoader).toBeInstanceOf(Promise)
83+
})
84+
85+
it('Should be gtl optionsValidator success', function () {
86+
const graphqlLoader = optionsValidator({ directory: 'src', pattern: '**/*', fileName: 'isf.graphql' })
87+
88+
expect(graphqlLoader).toBeDefined()
89+
expect(graphqlLoader).toBeTruthy()
90+
})
91+
92+
it('Should be gtl optionsValidator error', function () {
93+
const graphqlLoader = optionsValidator({ directoryx: 'src', patternx: '**/*', fileNamex: 'isf.graphql' })
94+
95+
expect(graphqlLoader).toBeDefined()
96+
expect(graphqlLoader).toBeInstanceOf(Promise)
97+
})
98+
99+
it('Should be gtl propertyValidator success', function () {
100+
const graphqlLoader = propertyValidator({ directory: 'src', pattern: '**/*', fileName: 'isf.graphql' })
101+
102+
expect(graphqlLoader).toBeDefined()
103+
expect(graphqlLoader).toBeTruthy()
104+
})
35105
})

demo/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ const { applyMiddleware } = require('graphql-middleware')
44
const { makeExecutableSchema } = require('@graphql-tools/schema')
55
const graphqlPlayground = require('graphql-playground-middleware-express').default
66
const express = require('express')
7-
const { gtl } = require('gtl')
7+
const { gtl } = require('gtl-node')
88

9-
const typeDefs = gtl({ directory: 'graphql/typeDefs', pattern: '**/*', extension: 'graphql' })
9+
const typeDefs = gtl({ directory: 'graphql/typeDefs/', pattern: '**/*', extension: 'graphql'})
1010
const { resolvers } = require('./graphql/resolvers')
1111

1212
;(async function () {

demo/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)