Skip to content

Commit 702d6f6

Browse files
authored
Merge pull request #2 from hellocomet/add-tests
🪖 Add tests
2 parents f6b7bd4 + 68b6fa6 commit 702d6f6

19 files changed

+10868
-151
lines changed

.eslintignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
api/tests
2+
build
3+
.next
4+
dist
5+
migrations
6+
node_modules
7+
generated
8+
coverage

.eslintrc.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
es2021: true,
6+
node: true,
7+
},
8+
overrides: [
9+
{
10+
files: ['*.js'],
11+
extends: ['eslint:recommended', 'prettier'],
12+
},
13+
{
14+
files: ['**/*.ts'],
15+
parser: '@typescript-eslint/parser',
16+
parserOptions: {
17+
tsconfigRootDir: __dirname,
18+
},
19+
settings: {
20+
'import/resolver': {
21+
typescript: {
22+
alwaysTryTypes: true,
23+
},
24+
},
25+
},
26+
plugins: ['import'],
27+
extends: [
28+
'plugin:@typescript-eslint/recommended',
29+
'plugin:import/errors',
30+
'plugin:import/warnings',
31+
'plugin:import/typescript',
32+
33+
// prettier config will turn rules off according to prettier, it should always be at the end
34+
'prettier',
35+
],
36+
rules: {
37+
'@typescript-eslint/explicit-module-boundary-types': 'off',
38+
'@typescript-eslint/no-inferrable-types': 'off',
39+
},
40+
},
41+
],
42+
}

.github/workflows/tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ jobs:
1919
run: |
2020
npm ci
2121
npm run build
22-
npm test
22+
npm run codegen
23+
npm run lint
24+
npm test

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build
2+
dist
3+
node_modules
4+
generated.ts
5+
.vscode

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"printWidth": 100
5+
}

.vscode/extensions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"dbaeumer.vscode-eslint",
4+
"esbenp.prettier-vscode",
5+
]
6+
}

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"editor.defaultFormatter": "esbenp.prettier-vscode",
3+
"editor.formatOnSave": true
4+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
[![Version](https://img.shields.io/npm/v/graphql-codegen-typescript-operations-tester.svg)](https://www.npmjs.com/package/graphql-codegen-typescript-operations-tester)
44
![Test workflow](https://github.com/hellocomet/graphql-codegen-typescript-operations-tester/workflows/Tests/badge.svg?branch=main)
5-
![Release workflow](https://github.com/hellocomet/graphql-codegen-typescript-operations-tester/workflows/Release%20package/badge.svg)
5+
![Release workflow](https://github.com/hellocomet/graphql-codegen-typescript-operations-tester/workflows/Release%20package/badge.svg)

jest.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
globals: {
4+
'ts-jest': {
5+
tsconfig: './test/tsconfig.json',
6+
},
7+
},
8+
testEnvironment: 'node',
9+
testMatch: ['**/*.spec.ts'],
10+
}

lib/index.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { PluginFunction } from '@graphql-codegen/plugin-helpers'
2-
import { visit, concatAST, FragmentDefinitionNode, print, OperationDefinitionNode, DocumentNode } from 'graphql'
2+
import {
3+
concatAST,
4+
DocumentNode,
5+
FragmentDefinitionNode,
6+
OperationDefinitionNode,
7+
print,
8+
visit,
9+
} from 'graphql'
310

411
function getOperationFragments(
512
node: OperationDefinitionNode | FragmentDefinitionNode,
@@ -27,12 +34,14 @@ function getOperationFragments(
2734
export const plugin: PluginFunction = (schema, documents) => {
2835
const imports = [`import { graphql, ExecutionResult } from 'graphql'`]
2936

30-
const allAst = concatAST(documents.reduce<DocumentNode[]>((acc, source) => {
31-
if (source.document) {
32-
acc.push(source.document)
33-
}
34-
return acc
35-
}, []))
37+
const allAst = concatAST(
38+
documents.reduce<DocumentNode[]>((acc, source) => {
39+
if (source.document) {
40+
acc.push(source.document)
41+
}
42+
return acc
43+
}, [])
44+
)
3645
const allFragments = new Map<string, FragmentDefinitionNode>()
3746
visit(allAst, {
3847
FragmentDefinition(node) {

0 commit comments

Comments
 (0)