Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate all tests code to TypeScript #2609

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions .eslintrc.yml
Expand Up @@ -632,12 +632,25 @@ overrides:
'@typescript-eslint/type-annotation-spacing': off
- files: '**/__*__/**'
rules:
'@typescript-eslint/consistent-type-assertions':
[error, { assertionStyle: as, objectLiteralTypeAssertions: allow }]
'@typescript-eslint/no-non-null-assertion': off
'@typescript-eslint/restrict-plus-operands': off
'@typescript-eslint/no-floating-promises': off
'@typescript-eslint/no-invalid-this': off
'@typescript-eslint/no-throw-literal': off
'@typescript-eslint/require-await': off
'@typescript-eslint/await-thenable': off
'prefer-promise-reject-errors': 0
'no-new-wrappers': 0
'no-throw-literal': 0
node/no-unpublished-import: off
node/no-unpublished-require: off
import/no-restricted-paths: off
import/no-extraneous-dependencies: [error, { devDependencies: true }]
import/no-nodejs-modules: off
no-restricted-syntax: off
flowtype/type-import-style: off
- files: 'resources/**'
parserOptions:
sourceType: script
Expand Down
1 change: 0 additions & 1 deletion .flowconfig
Expand Up @@ -36,7 +36,6 @@ module.use_strict=true
babel_loose_array_spread=true
esproposal.optional_chaining=enable
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$DisableFlowOnNegativeTest

[version]
^0.126.0
1 change: 1 addition & 0 deletions .mocharc.yml
Expand Up @@ -2,3 +2,4 @@ throw-deprecation: true
check-leaks: true
require:
- '@babel/register'
dotansimha marked this conversation as resolved.
Show resolved Hide resolved
- ts-node/register
3 changes: 3 additions & 0 deletions cspell.json
Expand Up @@ -18,6 +18,9 @@
"Alderaan",
"Tatooine",
"astromech",
"structs",
"geocode",
"behaviour",

// TODO: remove bellow words
"Graphi", // GraphiQL
Expand Down
63 changes: 60 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Expand Up @@ -26,8 +26,8 @@
"scripts": {
"test": "npm run prettier:check && npm run lint && npm run check && npm run testonly && npm run check:ts && npm run check:spelling",
"test:ci": "npm run prettier:check && npm run lint -- --no-cache && npm run check && npm run testonly:cover && npm run check:ts && npm run check:spelling && npm run build",
"fuzzonly": "mocha --full-trace src/**/__tests__/**/*-fuzz.js",
"testonly": "mocha --full-trace src/**/__tests__/**/*-test.js",
"fuzzonly": "mocha --full-trace src/**/__tests__/**/*-fuzz.ts",
"testonly": "mocha --full-trace src/**/__tests__/**/*-test.ts",
"testonly:cover": "nyc npm run testonly",
"lint": "eslint --cache --ext .js,.ts src resources",
"benchmark": "node --noconcurrent_sweeping --expose-gc --predictable ./resources/benchmark.js",
Expand All @@ -46,6 +46,9 @@
"dependencies": {},
"devDependencies": {
"@babel/core": "7.10.2",
"@types/node": "14.0.9",
"@types/mocha": "7.0.2",
"@types/chai": "4.2.11",
"@babel/plugin-transform-flow-strip-types": "7.10.1",
"@babel/preset-env": "7.10.2",
"@babel/register": "7.10.1",
Expand All @@ -65,6 +68,7 @@
"mocha": "7.2.0",
"nyc": "15.1.0",
"prettier": "2.0.5",
"ts-node": "8.10.2",
"typescript": "3.9.3"
}
}
4 changes: 4 additions & 0 deletions src/__fixtures__/index.d.ts
@@ -0,0 +1,4 @@
export declare const bigSchemaSDL: string;
export declare const bigSchemaIntrospectionResult: Record<string, any>;
export declare const kitchenSinkSDL: string;
export declare const kitchenSinkQuery: string;
21 changes: 12 additions & 9 deletions src/__fixtures__/index.js
@@ -1,18 +1,21 @@
/* eslint-disable import/no-commonjs */
// @flow strict

import { join } from 'path';
dotansimha marked this conversation as resolved.
Show resolved Hide resolved
import { readFileSync } from 'fs';
// FIXME: This file should remain as JS file, and has a supporting `d.ts` file,
// because it's in use by other areas of that repo (like benchmark tests).
// I should be converted to `.ts` after migrating the entire build system to TS.

function readLocalFile(filename: string): string {
const { join } = require('path');
const { readFileSync } = require('fs');

function readLocalFile(filename) {
return readFileSync(join(__dirname, filename), 'utf8');
}

export const bigSchemaSDL: string = readLocalFile('github-schema.graphql');
export const bigSchemaIntrospectionResult: any = JSON.parse(
export const bigSchemaSDL = readLocalFile('github-schema.graphql');
export const bigSchemaIntrospectionResult = JSON.parse(
readLocalFile('github-schema.json'),
);

export const kitchenSinkSDL: string = readLocalFile(
'schema-kitchen-sink.graphql',
);
export const kitchenSinkQuery: string = readLocalFile('kitchen-sink.graphql');
export const kitchenSinkSDL = readLocalFile('schema-kitchen-sink.graphql');
export const kitchenSinkQuery = readLocalFile('kitchen-sink.graphql');
@@ -1,5 +1,3 @@
// @flow strict

import { expect } from 'chai';
import { describe, it } from 'mocha';

Expand Down
@@ -1,11 +1,12 @@
// @flow strict

import { expect } from 'chai';
import { describe, it } from 'mocha';

import genFuzzStrings from '../genFuzzStrings';

function expectFuzzStrings(options) {
function expectFuzzStrings(options: {
allowedChars: Array<string>;
maxLength: number;
}) {
return expect(Array.from(genFuzzStrings(options)));
}

Expand Down
@@ -1,5 +1,3 @@
// @flow strict

import { expect } from 'chai';
import { describe, it } from 'mocha';

Expand Down
6 changes: 2 additions & 4 deletions src/__testUtils__/dedent.js → src/__testUtils__/dedent.ts
@@ -1,5 +1,3 @@
// @flow strict

/**
* An ES6 string tag that fixes indentation. Also removes leading newlines
* and trailing spaces and tabs, but keeps trailing newlines.
Expand All @@ -13,8 +11,8 @@
* str === "{\n test\n}\n";
*/
export default function dedent(
strings: $ReadOnlyArray<string>,
...values: $ReadOnlyArray<string>
strings: string | ReadonlyArray<string>,
...values: ReadonlyArray<string>
): string {
let str = '';

Expand Down
@@ -1,12 +1,10 @@
// @flow strict

/**
* Generator that produces all possible combinations of allowed characters.
*/
export default function* genFuzzStrings(options: {|
allowedChars: Array<string>,
maxLength: number,
|}): Generator<string, void, void> {
export default function* genFuzzStrings(options: {
allowedChars: Array<string>;
maxLength: number;
}): Generator<string, void, void> {
dotansimha marked this conversation as resolved.
Show resolved Hide resolved
const { allowedChars, maxLength } = options;
const numAllowedChars = allowedChars.length;

Expand Down
@@ -1,9 +1,9 @@
// @flow strict
import { Maybe } from '../jsutils/Maybe';

/**
* Special inspect function to produce readable string literal for error messages in tests
*/
export default function inspectStr(str: ?string): string {
export default function inspectStr(str: Maybe<string>): string {
if (str == null) {
return 'null';
}
Expand Down