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 15407be
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 46 deletions.
2 changes: 0 additions & 2 deletions integrationTests/ts/.gitignore

This file was deleted.

Expand Up @@ -13,7 +13,8 @@ const example: SomeExtension = {
};

// The following code block requires a newer version of TypeScript
/*! >=3.2 !*/
/*! >=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
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:typescript@2.6.x",
"typescript-2.7": "npm:typescript@2.7.x",
"typescript-2.8": "npm:typescript@2.8.x",
Expand Down
40 changes: 0 additions & 40 deletions integrationTests/ts/test.js
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 15407be

Please sign in to comment.