Skip to content

Commit

Permalink
Revert "Allow testing certain code blocks on only specific TypeScript…
Browse files Browse the repository at this point in the history
… versions"

This reverts commit 04c837a.
  • Loading branch information
benjie committed Jun 25, 2020
1 parent 04c837a commit b33e65f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 47 deletions.
2 changes: 0 additions & 2 deletions integrationTests/ts/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ const example: SomeExtension = {
string: 'Meaning of life',
};

// The following code block requires a newer version of TypeScript
/*! >=3.2 !*/
// FIXME: The following code block requires a version of TypeScript >= 3.2
/*
declare module 'graphql' {
interface GraphQLObjectTypeExtensions<TSource = any, TContext = any> {
someObjectExtension?: SomeExtension;
Expand All @@ -29,7 +30,7 @@ declare module 'graphql' {
someArgumentExtension?: SomeExtension;
}
}
/*!!*/
*/

const queryType: GraphQLObjectType = new GraphQLObjectType({
name: 'Query',
Expand Down
2 changes: 0 additions & 2 deletions integrationTests/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"test": "node test.js"
},
"dependencies": {
"glob": "^7.1.6",
"graphql": "file:../../npmDist",
"semver": "^7.3.2",
"typescript-2.6": "npm:[email protected]",
"typescript-2.7": "npm:[email protected]",
"typescript-2.8": "npm:[email protected]",
Expand Down
40 changes: 0 additions & 40 deletions integrationTests/ts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,16 @@

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

const glob = require('glob');
const semver = require('semver');

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

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

// To allow omitting certain code from older versions of TypeScript, we have a
// "magic" comment syntax. We precede a block of code with:
//
// /*! SEMVER_RANGE !*/
//
// replacing SEMVER_RANGE with a semver range spec, such as '>=3.2'; we
// terminate the block of code with:
//
// /*!!*/
//
// We will only include the code between these comments if the TypeScript
// version being tested satisfies the semver range that was specified. NOTE: We
// currently do not allow nesting of these blocks.
const templates = glob.sync('./*.ts.template').map((filename) => {
const content = fs.readFileSync(filename, 'utf8');
const targetFilename = filename.replace(/\.template$/, '');
assert.notEqual(filename, targetFilename);
const writeFileSync = (version) => {
// Captures our magic comment syntax: `/*!(CAPTURE1)!*/(CAPTURE 2)/*!!*/`
const regex = /\/\*!([^!]+)!\*\/([\s\S]*?)\/\*!!\*\//g;
const finalContent = content.replace(regex, (_, versionRange, payload) => {
if (semver.satisfies(version, versionRange)) {
return payload;
}
return '';
});
fs.writeFileSync(targetFilename, finalContent);
};
return { writeFileSync };
});

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

for (const template of templates) {
template.writeFileSync(version);
}

const tscPath = path.join(__dirname, 'node_modules', version, 'bin/tsc');
childProcess.execSync(tscPath, { stdio: 'inherit' });
}

0 comments on commit b33e65f

Please sign in to comment.