jest-runner-graphql-schema-linter v1.0.0
Usage
This library is a jest-runner for the graphql-schema-linter library.
Install
Install jest(it needs Jest 21+) and jest-runner-graphql-schema-linter
yarn add --dev jest jest-runner-graphql-schema-linter
# or with NPM
npm install --save-dev jest jest-runner-graphql-schema-linterAdd it to your Jest config
Standalone
In your package.json
{
"jest": {
"runner": "jest-runner-graphql-schema-linter",
"displayName": "lint:gql",
"moduleFileExtensions": ["gql", "graphql"],
"testMatch": ["<rootDir>/src/**/*.gql"]
}
}Or in jest.config.js
module.exports = {
runner: "jest-runner-graphql-schema-linter",
displayName: "gql lint",
moduleFileExtensions: ["gql", "graphql"],
testMatch: ["<rootDir>/src/**/*.gql"]
};Please update testMatch to match your project folder structure
Alongside other runners
It is recommended to use the projects configuration option to run multiple Jest runners simultaneously.
If you are using Jest <22.0.5, you can use multiple Jest configuration files and supply the paths to those files in the projects option. For example:
// jest-test.config.js
module.exports = {
// your Jest test options
displayName: "test"
};
// jest-grapqhl-schema-linter.config.js
module.exports = {
// your jest-runner-graphql-schema-linter options
runner: "jest-runner-graphql-schema-linter",
displayName: "gql lint",
moduleFileExtensions: ["gql", "graphql"],
testMatch: ["<rootDir>/src/**/*.gql"]
};In your package.json:
{
"jest": {
"projects": [
"<rootDir>/jest-test.config.js",
"<rootDir>/jest-graphql-schema-linter.config.js"
]
}
}Or in jest.config.js:
module.exports = {
projects: [
"<rootDir>/jest-test.config.js",
"<rootDir>/jest-graphql-schema-linter.config.js"
]
};If you are using Jest >=22.0.5, you can supply an array of project configuration objects instead. In your package.json:
{
"jest": {
"projects": [
{
"displayName": "test"
},
{
"runner": "jest-runner-graphql-schema-linter",
"displayName": "lint:gql",
"moduleFileExtensions": ["gql", "graphql"],
"testMatch": ["<rootDir>/src/**/*.gql"]
}
]
}
}Or in jest.config.js:
module.exports = {
projects: [
{
displayName: "test"
},
{
runner: "jest-runner-graphql-schema-linter",
displayName: "gql lint",
moduleFileExtensions: ["gql", "graphql"],
testMatch: ["<rootDir>/src/**/*.gql"]
}
]
};Run Jest
yarn testOptions
This project uses cosmiconfig, so you can provide config via:
- a
jest-runner-eslintproperty in yourpackage.json - a
jest-runner-eslint.config.jsJS file - a
.jest-runner-eslintrcJSON file
In package.json
{
"jest-runner-eslint": {
"cliOptions": {
// Options here
}
}
}or in jest-runner-eslint.config.js
module.exports = {
cliOptions: {
// Options here
}
};cliOptions
The listed options are the ones provided by the graphql-schema-linter CLI.
| option | default | values | example |
|---|---|---|---|
| rules | [] | "rules": ["fields-have-descriptions", "types-have-descriptions"] | |
| format | text | text|json | "format": "json" |
| configDirection | null | "configDirection": "./src" | |
| customRulePaths | null | "customRulePaths": "./rules/*.js" | |
| commentDescriptions | false | false|true | "commentDescriptions": true |
| oldImplementSyntax | false | false|true | "oldImplementSyntax": true |
8 years ago