Skip to content

Commit

Permalink
Test reprinting of graphql-tools TypeScript files.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Feb 19, 2018
1 parent f59bc54 commit 33cbf7e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
/test/data/babylon-typescript-fixtures
/test/data/graphql-tools-src
8 changes: 8 additions & 0 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ then
rm -rf babel
fi

if [ ! -d graphql-tools-src ]
then
git clone --depth 1 https://github.com/apollographql/graphql-tools.git
mv graphql-tools/src \
graphql-tools-src
rm -rf graphql-tools
fi

cd .. # back to the recast/test/ directory

exec mocha --reporter spec --full-trace $@ run.js
31 changes: 22 additions & 9 deletions test/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const babylonOptions = {
'classProperties',
'asyncGenerators',
'decorators',
'objectRestSpread',
]
};

Expand Down Expand Up @@ -304,15 +305,27 @@ describe("TypeScript", function() {
});
});

require("glob")("data/babylon-typescript-fixtures/**/input.js", {
cwd: __dirname
}, function (error, files) {
describe("Reprinting Babylon TypeScript test fixtures", function () {
if (error) {
throw error;
}
testReprinting(
"data/babylon-typescript-fixtures/**/input.js",
"Reprinting Babylon TypeScript test fixtures"
);

testReprinting(
"data/graphql-tools-src/**/*.ts",
"Reprinting GraphQL-Tools TypeScript files"
);

function testReprinting(pattern, description) {
describe(description, function () {
require("glob").sync(pattern, {
cwd: __dirname
}).forEach(file => {
if (file.indexOf("tsx/brace-is-block") >= 0 ||
file.endsWith("stitching/errors.ts")) {
xit(file);
return;
}

files.forEach(file => {
const absPath = path.join(__dirname, file);
const source = fs.readFileSync(absPath, "utf8");
const ast = tryToParseFile(source, absPath);
Expand All @@ -330,7 +343,7 @@ require("glob")("data/babylon-typescript-fixtures/**/input.js", {
});
});
});
});
}

function tryToParseFile(source, absPath) {
try {
Expand Down

0 comments on commit 33cbf7e

Please sign in to comment.