From aa3c1142c5d20d07580c3269f92e5bb50e1832ab Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Sun, 4 Oct 2020 03:16:35 +0300 Subject: [PATCH] Convert fixtures to be JS files --- .eslintrc.yml | 14 +++++++---- .prettierignore | 3 --- src/__fixtures__/index.js | 11 --------- .../kitchenSinkQuery.js} | 5 ++++ .../kitchenSinkSDL.js} | 24 +++++++++++-------- src/language/__tests__/parser-test.js | 3 +-- src/language/__tests__/printer-test.js | 3 +-- src/language/__tests__/schema-parser-test.js | 3 +-- src/language/__tests__/schema-printer-test.js | 3 +-- src/language/__tests__/visitor-test.js | 4 ++-- .../__tests__/stripIgnoredCharacters-test.js | 4 ++-- 11 files changed, 36 insertions(+), 41 deletions(-) delete mode 100644 src/__fixtures__/index.js rename src/{__fixtures__/kitchen-sink.graphql => __testUtils__/kitchenSinkQuery.js} (89%) rename src/{__fixtures__/schema-kitchen-sink.graphql => __testUtils__/kitchenSinkSDL.js} (81%) diff --git a/.eslintrc.yml b/.eslintrc.yml index ebedb41634..52982f6151 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -508,8 +508,6 @@ overrides: # `@typescript-eslint/eslint-plugin` rule list based on `v4.3.x` ########################################################################## - no-undef: off # FIXME: temporary disabled due to https://github.com/typescript-eslint/typescript-eslint/issues/2462 - # Supported Rules # https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules '@typescript-eslint/adjacent-overload-signatures': error @@ -657,18 +655,24 @@ overrides: '@typescript-eslint/semi': off '@typescript-eslint/space-before-function-paren': off '@typescript-eslint/type-annotation-spacing': off - - files: ['src/**/__*__/**', 'integrationTests/**'] + - files: 'src/**/__*__/**' rules: node/no-unpublished-import: off + import/no-restricted-paths: off + import/no-extraneous-dependencies: [error, { devDependencies: true }] + import/no-nodejs-modules: off # TODO remove + no-restricted-syntax: off + - files: 'integrationTests/*' + rules: node/no-unpublished-require: off node/no-sync: off - import/no-restricted-paths: off import/no-extraneous-dependencies: [error, { devDependencies: true }] import/no-nodejs-modules: off - no-restricted-syntax: off - files: 'integrationTests/*/**' rules: + node/no-sync: off node/no-missing-require: off + import/no-nodejs-modules: off no-console: off - files: 'benchmark/**' rules: diff --git a/.prettierignore b/.prettierignore index 4cdeda8d6d..475f5e22fd 100644 --- a/.prettierignore +++ b/.prettierignore @@ -6,6 +6,3 @@ /denoDist /npm /deno - -# Don't touch GraphQL files. -/src/**/*.graphql diff --git a/src/__fixtures__/index.js b/src/__fixtures__/index.js deleted file mode 100644 index bacbbe4833..0000000000 --- a/src/__fixtures__/index.js +++ /dev/null @@ -1,11 +0,0 @@ -import { join } from 'path'; -import { readFileSync } from 'fs'; - -function readLocalFile(filename: string): string { - return readFileSync(join(__dirname, filename), 'utf8'); -} - -export const kitchenSinkSDL: string = readLocalFile( - 'schema-kitchen-sink.graphql', -); -export const kitchenSinkQuery: string = readLocalFile('kitchen-sink.graphql'); diff --git a/src/__fixtures__/kitchen-sink.graphql b/src/__testUtils__/kitchenSinkQuery.js similarity index 89% rename from src/__fixtures__/kitchen-sink.graphql rename to src/__testUtils__/kitchenSinkQuery.js index 543307bb8a..2ccdc9dc92 100644 --- a/src/__fixtures__/kitchen-sink.graphql +++ b/src/__testUtils__/kitchenSinkQuery.js @@ -1,3 +1,5 @@ +// $FlowFixMe[incompatible-call] +const kitchenSinkQuery: string = String.raw` query queryName($foo: ComplexType, $site: Site = MOBILE) @onQuery { whoever123is: node(id: [123, 456]) { id @@ -62,3 +64,6 @@ fragment frag on Friend @onFragmentDefinition { query { __typename } +`; + +export default kitchenSinkQuery; diff --git a/src/__fixtures__/schema-kitchen-sink.graphql b/src/__testUtils__/kitchenSinkSDL.js similarity index 81% rename from src/__fixtures__/schema-kitchen-sink.graphql rename to src/__testUtils__/kitchenSinkSDL.js index 8ec1f2d8a6..7b171ac027 100644 --- a/src/__fixtures__/schema-kitchen-sink.graphql +++ b/src/__testUtils__/kitchenSinkSDL.js @@ -1,3 +1,4 @@ +const kitchenSinkSDL: string = ` """This is a description of the schema as a whole.""" schema { query: QueryType @@ -6,21 +7,21 @@ schema { """ This is a description -of the `Foo` type. +of the \`Foo\` type. """ type Foo implements Bar & Baz & Two { - "Description of the `one` field." + "Description of the \`one\` field." one: Type """ - This is a description of the `two` field. + This is a description of the \`two\` field. """ two( """ - This is a description of the `argument` argument. + This is a description of the \`argument\` argument. """ argument: InputType! ): Type - """This is a description of the `three` field.""" + """This is a description of the \`three\` field.""" three(argument: InputType, other: String): Int four(argument: String = "string"): String five(argument: [String] = ["string", "string"]): String @@ -86,14 +87,14 @@ extend scalar CustomScalar @onScalar enum Site { """ - This is a description of the `DESKTOP` value + This is a description of the \`DESKTOP\` value """ DESKTOP - """This is a description of the `MOBILE` value""" + """This is a description of the \`MOBILE\` value""" MOBILE - "This is a description of the `WEB` value" + "This is a description of the \`WEB\` value" WEB } @@ -128,10 +129,10 @@ extend input InputType { extend input InputType @onInputObject """ -This is a description of the `@skip` directive +This is a description of the \`@skip\` directive """ directive @skip( - """This is a description of the `if` argument""" + """This is a description of the \`if\` argument""" if: Boolean! @onArgumentDefinition ) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT @@ -154,3 +155,6 @@ extend schema @onSchema extend schema @onSchema { subscription: SubscriptionType } +`; + +export default kitchenSinkSDL; diff --git a/src/language/__tests__/parser-test.js b/src/language/__tests__/parser-test.js index 6271792e82..79c0795020 100644 --- a/src/language/__tests__/parser-test.js +++ b/src/language/__tests__/parser-test.js @@ -4,6 +4,7 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; import dedent from '../../__testUtils__/dedent'; +import kitchenSinkQuery from '../../__testUtils__/kitchenSinkQuery'; import inspect from '../../jsutils/inspect'; @@ -12,8 +13,6 @@ import { Source } from '../source'; import { TokenKind } from '../tokenKind'; import { parse, parseValue, parseType } from '../parser'; -import { kitchenSinkQuery } from '../../__fixtures__/index'; - import toJSONDeep from './toJSONDeep'; function expectSyntaxError(text: string) { diff --git a/src/language/__tests__/printer-test.js b/src/language/__tests__/printer-test.js index 0f259e5e63..55adc17a78 100644 --- a/src/language/__tests__/printer-test.js +++ b/src/language/__tests__/printer-test.js @@ -2,12 +2,11 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; import dedent from '../../__testUtils__/dedent'; +import kitchenSinkQuery from '../../__testUtils__/kitchenSinkQuery'; import { parse } from '../parser'; import { print } from '../printer'; -import { kitchenSinkQuery } from '../../__fixtures__/index'; - describe('Printer: Query document', () => { it('does not alter ast', () => { const ast = parse(kitchenSinkQuery); diff --git a/src/language/__tests__/schema-parser-test.js b/src/language/__tests__/schema-parser-test.js index 5206d64759..02dab56622 100644 --- a/src/language/__tests__/schema-parser-test.js +++ b/src/language/__tests__/schema-parser-test.js @@ -2,8 +2,7 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; import dedent from '../../__testUtils__/dedent'; - -import { kitchenSinkSDL } from '../../__fixtures__/index'; +import kitchenSinkSDL from '../../__testUtils__/kitchenSinkSDL'; import { parse } from '../parser'; diff --git a/src/language/__tests__/schema-printer-test.js b/src/language/__tests__/schema-printer-test.js index 115ca12730..8a9505939c 100644 --- a/src/language/__tests__/schema-printer-test.js +++ b/src/language/__tests__/schema-printer-test.js @@ -2,12 +2,11 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; import dedent from '../../__testUtils__/dedent'; +import kitchenSinkSDL from '../../__testUtils__/kitchenSinkSDL'; import { parse } from '../parser'; import { print } from '../printer'; -import { kitchenSinkSDL } from '../../__fixtures__/index'; - describe('Printer: SDL document', () => { it('prints minimal ast', () => { const ast = { diff --git a/src/language/__tests__/visitor-test.js b/src/language/__tests__/visitor-test.js index ab7e8b390e..1dfce965b8 100644 --- a/src/language/__tests__/visitor-test.js +++ b/src/language/__tests__/visitor-test.js @@ -1,6 +1,8 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; +import kitchenSinkQuery from '../../__testUtils__/kitchenSinkQuery'; + import invariant from '../../jsutils/invariant'; import type { ASTNode } from '../ast'; @@ -8,8 +10,6 @@ import { Kind } from '../kinds'; import { parse } from '../parser'; import { visit, visitInParallel, BREAK, QueryDocumentKeys } from '../visitor'; -import { kitchenSinkQuery } from '../../__fixtures__/index'; - function checkVisitorFnArgs(ast: any, args: any, isEdited: boolean = false) { const [node, key, parent, path, ancestors] = args; diff --git a/src/utilities/__tests__/stripIgnoredCharacters-test.js b/src/utilities/__tests__/stripIgnoredCharacters-test.js index 87ebd5b5e2..fdc7d907d6 100644 --- a/src/utilities/__tests__/stripIgnoredCharacters-test.js +++ b/src/utilities/__tests__/stripIgnoredCharacters-test.js @@ -3,6 +3,8 @@ import { describe, it } from 'mocha'; import dedent from '../../__testUtils__/dedent'; import inspectStr from '../../__testUtils__/inspectStr'; +import kitchenSinkSDL from '../../__testUtils__/kitchenSinkSDL'; +import kitchenSinkQuery from '../../__testUtils__/kitchenSinkQuery'; import invariant from '../../jsutils/invariant'; @@ -12,8 +14,6 @@ import { Source } from '../../language/source'; import { stripIgnoredCharacters } from '../stripIgnoredCharacters'; -import { kitchenSinkQuery, kitchenSinkSDL } from '../../__fixtures__/index'; - const ignoredTokens = [ // UnicodeBOM :: '\uFEFF', // Byte Order Mark (U+FEFF)