From b5872b4c7e823cd9b6cfb99f1299553f2d8daf53 Mon Sep 17 00:00:00 2001 From: n1ru4l Date: Thu, 11 Feb 2021 09:02:14 +0100 Subject: [PATCH] chore: add missing test typings; configure tsconfig.json to also include the tests; add tsconfig.build.json for the actual lib only build. --- package.json | 4 ++-- test/FindGraphQLTags-test.ts | 2 +- test/TypeScriptGenerator-test.ts | 10 +++------- test/ambient.d.ts | 17 +++++++++++++++++ test/formatGeneratedModule-test.ts | 3 --- tsconfig.build.json | 4 ++++ tsconfig.json | 2 +- 7 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 tsconfig.build.json diff --git a/package.json b/package.json index c97206d9..7390306e 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "lib" ], "scripts": { - "build": "rm -rf lib && tsc", + "build": "rm -rf lib && tsc --project tsconfig.build.json", "lint": "tslint -c tslint.json --project tsconfig.json", "pr-check": "scripts/pr-check.sh", "prettier": "prettier --write '{src,types,test}/**/*.ts'", @@ -41,7 +41,7 @@ "sync-fixtures": "ts-node ./syncFixtures.ts", "test": "npm run type-check && jest", "type-check": "tsc --noEmit --pretty", - "watch": "concurrently 'tsc --watch' 'chokidar \"lib/**/*.js\" -c \"yalc publish --force --push\"'" + "watch": "concurrently 'tsc --watch --project tsconfig.build.json' 'chokidar \"lib/**/*.js\" -c \"yalc publish --force --push\"'" }, "husky": { "hooks": { diff --git a/test/FindGraphQLTags-test.ts b/test/FindGraphQLTags-test.ts index 5b06e090..c8e2a021 100644 --- a/test/FindGraphQLTags-test.ts +++ b/test/FindGraphQLTags-test.ts @@ -21,7 +21,7 @@ describe("FindGraphQLTags", () => { ).toEqual([ { keyName: null, - template: ` + template: /* GraphQL */ ` fragment TestModule_artist on Artist { name } diff --git a/test/TypeScriptGenerator-test.ts b/test/TypeScriptGenerator-test.ts index d6e6798a..bc3aa0f5 100644 --- a/test/TypeScriptGenerator-test.ts +++ b/test/TypeScriptGenerator-test.ts @@ -1,13 +1,9 @@ -import { CompilerContext, IRTransforms, Root } from "relay-compiler"; -// @ts-ignore +import { CompilerContext, IRTransforms, Root, } from "relay-compiler"; import { TypeGeneratorOptions } from "relay-compiler/lib/language/RelayLanguagePluginInterface"; -// @ts-ignore import { generateTestsFromFixtures } from "relay-test-utils-internal/lib/generateTestsFromFixtures"; -// @ts-ignore -import * as parseGraphQLText from "relay-test-utils-internal/lib/parseGraphQLText"; -// @ts-ignore import { TestSchema } from "relay-test-utils-internal/lib/TestSchema"; import * as TypeScriptGenerator from "../src/TypeScriptGenerator"; +import parseGraphQLText = require("relay-test-utils-internal/lib/parseGraphQLText"); function generate( text: string, @@ -16,7 +12,7 @@ function generate( ) { const schema = TestSchema.extend([ ...IRTransforms.schemaExtensions, - ` + /* GraphQL */ ` scalar Color extend type User { color: Color diff --git a/test/ambient.d.ts b/test/ambient.d.ts index 24887638..987ef697 100644 --- a/test/ambient.d.ts +++ b/test/ambient.d.ts @@ -4,3 +4,20 @@ declare namespace jest { toMatchFile(width: string): void; } } + + +declare module "relay-test-utils-internal/lib/generateTestsFromFixtures" { + + export function generateTestsFromFixtures(path: string, callback: (text: string) => void): void +} + +declare module "relay-test-utils-internal/lib/parseGraphQLText" { + import type {Fragment, Root, Schema} from 'relay-compiler'; + function parseGraphQLText(schema: Schema, text: string): { definitions: ReadonlyArray, schema: Schema } + export = parseGraphQLText +} + +declare module "relay-test-utils-internal/lib/TestSchema" { + import type {Schema} from 'relay-compiler'; + export const TestSchema: Schema +} diff --git a/test/formatGeneratedModule-test.ts b/test/formatGeneratedModule-test.ts index 92d49286..724a5ae3 100644 --- a/test/formatGeneratedModule-test.ts +++ b/test/formatGeneratedModule-test.ts @@ -50,7 +50,6 @@ describe("formatGeneratedModule", () => { relayRuntimeModule: "relay-runtime", sourceHash: "edcba" }) - // @ts-ignore ).toMatchFile( join(__dirname, "fixtures/generated-module/complete-example.ts") ); @@ -69,7 +68,6 @@ describe("formatGeneratedModule", () => { hash: "@relayHash abcde", sourceHash: "edcba" }) - // @ts-ignore ).toMatchFile( join(__dirname, "fixtures/generated-module/complete-example.ts") ); @@ -88,7 +86,6 @@ describe("formatGeneratedModule", () => { hash: null, sourceHash: "edcba" }) - // @ts-ignore ).toMatchFile( join(__dirname, "fixtures/generated-module/complete-example-no-cast.ts") ); diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 00000000..2c4a787f --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["./test/**/*"] +} diff --git a/tsconfig.json b/tsconfig.json index 99d1206d..3803ea7f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -53,5 +53,5 @@ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ }, - "include": ["./src/**/*", "./types/**/*"] + "include": ["./src/**/*", "./types/**/*", "./test/**/*"] }