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

Integration tests for TS #2647

Merged
merged 1 commit into from Jun 13, 2020
Merged
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
11 changes: 11 additions & 0 deletions .eslintrc.yml
Expand Up @@ -483,6 +483,7 @@ rules:
wrap-regex: off
yield-star-spacing: off

ignorePatterns: 'integrationTests/ts/*.ts'
overrides:
- files: '**/*.ts'
parser: '@typescript-eslint/parser'
Expand Down Expand Up @@ -640,6 +641,16 @@ overrides:
import/no-extraneous-dependencies: [error, { devDependencies: true }]
import/no-nodejs-modules: off
no-restricted-syntax: off
- files: 'integrationTests/**'
parserOptions:
sourceType: script
rules:
node/no-unpublished-import: off
node/no-unpublished-require: off
node/no-sync: off
import/no-extraneous-dependencies: [error, { devDependencies: true }]
import/no-nodejs-modules: off
no-console: off
- files: 'resources/**'
parserOptions:
sourceType: script
Expand Down
30 changes: 28 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -49,12 +49,38 @@ jobs:
- name: Spellcheck
run: npm run check:spelling

integrationTests:
name: Run integration tests
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ env.NODE_VERSION_USED_FOR_DEVELOPMENT }}

- name: Cache Node.js modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-

- name: Install Dependencies
run: npm ci

- name: Build NPM package
run: npm run build:npm

- name: Build Deno package
run: npm run build:deno

- name: Run Integration Tests
run: npm run check:integrations

fuzz:
name: Run fuzzing tests
runs-on: ubuntu-latest
Expand Down Expand Up @@ -178,7 +204,7 @@ jobs:
github.event_name == 'push' &&
github.repository == 'graphql/graphql-js' &&
github.ref == 'refs/heads/master'
needs: [test, fuzz, lint]
needs: [test, fuzz, lint, integrationTests]
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand Down Expand Up @@ -214,7 +240,7 @@ jobs:
github.event_name == 'push' &&
github.repository == 'graphql/graphql-js' &&
github.ref == 'refs/heads/master'
needs: [test, fuzz, lint]
needs: [test, fuzz, lint, integrationTests]
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -11,5 +11,6 @@ coverage
npmDist
denoDist
benchmarkDist
integrationTmp
npm
deno
1 change: 1 addition & 0 deletions integrationTests/README.md
@@ -0,0 +1 @@
# TBD
30 changes: 30 additions & 0 deletions integrationTests/integration-test.js
@@ -0,0 +1,30 @@
// @noflow

'use strict';

const fs = require('fs');
const path = require('path');
const childProcess = require('child_process');

const { describe, it } = require('mocha');

function exec(command, options = {}) {
return childProcess.execSync(command, {
stdio: 'inherit',
...options,
});
}

describe('Integration Tests', () => {
const tmpDir = path.resolve('./integrationTmp');
fs.rmdirSync(tmpDir, { recursive: true });
fs.mkdirSync(tmpDir);

it('Should compile with all supported TS versions', () => {
exec(`cp -R ${path.join(__dirname, 'ts')} ${tmpDir}`);

const cwd = path.join(tmpDir, 'ts');
exec('npm ci', { cwd });
exec('npm test', { cwd });
}).timeout(40000);
});
30 changes: 30 additions & 0 deletions integrationTests/ts/index.ts
@@ -0,0 +1,30 @@
import { GraphQLString, GraphQLSchema, GraphQLObjectType } from 'graphql/type';
import { ExecutionResult } from 'graphql/execution';
import { graphqlSync } from 'graphql';

const queryType: GraphQLObjectType = new GraphQLObjectType({
name: 'Query',
fields: {
sayHi: {
type: GraphQLString,
args: {
who: { type: GraphQLString },
},
resolve: (_root, args) => 'Hello ' + (args.who || 'World'),
},
},
});

const schema: GraphQLSchema = new GraphQLSchema({
query: queryType,
});

const result: ExecutionResult = graphqlSync({
schema,
source: `
query helloWho($who: String){
test(who: $who)
}
`,
variableValues: { who: 'Dolly' },
});
85 changes: 85 additions & 0 deletions integrationTests/ts/package-lock.json

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

26 changes: 26 additions & 0 deletions integrationTests/ts/package.json
@@ -0,0 +1,26 @@
{
"version": "1.0.0",
"scripts": {
"test": "node test.js",
"test-3.8": "tsc test.ts",
"test-3.9": "tsc test.ts"
},
"dependencies": {
"@types/node": "10.12.21",
"graphql": "file:../../npmDist",
"typescript-2.6": "npm:typescript@2.6.x",
"typescript-2.7": "npm:typescript@2.7.x",
"typescript-2.8": "npm:typescript@2.8.x",
"typescript-2.9": "npm:typescript@2.9.x",
"typescript-3.0": "npm:typescript@3.0.x",
"typescript-3.1": "npm:typescript@3.1.x",
"typescript-3.2": "npm:typescript@3.2.x",
"typescript-3.3": "npm:typescript@3.3.x",
"typescript-3.4": "npm:typescript@3.4.x",
"typescript-3.5": "npm:typescript@3.5.x",
"typescript-3.6": "npm:typescript@3.6.x",
"typescript-3.7": "npm:typescript@3.7.x",
"typescript-3.8": "npm:typescript@3.8.x",
"typescript-3.9": "npm:typescript@3.9.x"
}
}
19 changes: 19 additions & 0 deletions integrationTests/ts/test.js
@@ -0,0 +1,19 @@
// @noflow

'use strict';

const path = require('path');
const childProcess = require('child_process');

const { dependencies } = require('./package.json');

const tsVersions = Object.keys(dependencies)
.filter((pkg) => pkg.startsWith('typescript-'))
.sort((a, b) => b.localeCompare(a));

for (const version of tsVersions) {
console.log(`Testing on ${version} ...`);

const tscPath = path.join(__dirname, 'node_modules', version, 'bin/tsc');
childProcess.execSync(tscPath, { stdio: 'inherit' });
}
9 changes: 9 additions & 0 deletions integrationTests/ts/tsconfig.json
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6", "esnext.asynciterable"],
"strict": true,
"noEmit": true,
"types": []
}
}
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -32,14 +32,15 @@
"fuzzonly": "mocha --full-trace src/**/__tests__/**/*-fuzz.js",
"testonly": "mocha --full-trace src/**/__tests__/**/*-test.js",
"testonly:cover": "nyc npm run testonly",
"lint": "eslint --cache --ext .js,.ts src resources",
"lint": "eslint --cache --ext .js,.ts src resources integrationTests",
"benchmark": "node --noconcurrent_sweeping --expose-gc --predictable ./resources/benchmark.js",
"prettier": "prettier --ignore-path .gitignore --write --list-different \"**/*.{js,ts,md,json,yml}\"",
"prettier:check": "prettier --ignore-path .gitignore --check \"**/*.{js,ts,md,json,yml}\"",
"check": "flow check",
"check:ts": "dtslint src",
"check:cover": "node resources/check-cover.js && nyc report --nycrc-path .nycflowrc.yml",
"check:spelling": "cspell \"./{src/**/,resources/**/}*.{js,ts,md,graphql}\"",
"check:spelling": "cspell \"./{src/**/,resources/**/,integrationTests/**/}*.{js,ts,md,graphql}\"",
"check:integrations": "mocha --full-trace integrationTests/*-test.js",
"build:npm": "node resources/build-npm.js",
"build:deno": "node resources/build-deno.js",
"changelog": "node resources/gen-changelog.js",
Expand Down