-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial test262 support to test optional chaining
For now, we only run two subdirectories and ignore various tests (sloppy mode, tests expecting syntax error, and TCO tests). This reveals a few issues with the current implementation, which will be addressed later. Since it's not a passing build yet, I'll leave it out of CI for now. Also drop the Travis build for Node 8 since one of the new dependencies requires Node 10. I won't officially drop Node 8 support just yet, but will soon, and it's at end-of-life now.
- Loading branch information
1 parent
ed3995f
commit ed268c5
Showing
9 changed files
with
588 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!./node_modules/.bin/sucrase-node | ||
/* eslint-disable no-console */ | ||
import chalk from "chalk"; | ||
import {exec} from "mz/child_process"; | ||
import {exists} from "mz/fs"; | ||
|
||
import run from "../script/run"; | ||
|
||
const TEST262_HARNESS = "./node_modules/.bin/test262-harness"; | ||
const TEST262_DIR = "./test262/test262-checkout"; | ||
const TEST262_REPO_URL = "https://github.com/tc39/test262.git"; | ||
const TEST262_REVISION = "157b18d16b5d52501c4d75ac422d3a80bfad1c17"; | ||
|
||
/** | ||
* Run the test262 suite on some tests that we know are useful. | ||
*/ | ||
async function main(): Promise<void> { | ||
if (!(await exists(TEST262_DIR))) { | ||
console.log(`Directory ${TEST262_DIR} not found, cloning a new one.`); | ||
await run(`git clone ${TEST262_REPO_URL} ${TEST262_DIR}`); | ||
} | ||
|
||
// Force a specific revision so we don't get a breakage from changes to the master branch. | ||
const originalCwd = process.cwd(); | ||
try { | ||
process.chdir(TEST262_DIR); | ||
await run(`git reset --hard ${TEST262_REVISION}`); | ||
await run(`git clean -f`); | ||
} catch (e) { | ||
await run("git fetch"); | ||
await run(`git reset --hard ${TEST262_REVISION}`); | ||
await run(`git clean -f`); | ||
} finally { | ||
process.chdir(originalCwd); | ||
} | ||
|
||
console.log("Running test262..."); | ||
const harnessStdout = ( | ||
await exec(`${TEST262_HARNESS} \ | ||
--preprocessor "./test262/test262Preprocessor.js" \ | ||
--reporter "json" \ | ||
"${TEST262_DIR}/test/language/expressions/coalesce/**/*.js" \ | ||
"${TEST262_DIR}/test/language/expressions/optional-chaining/**/*.js"`) | ||
)[0].toString(); | ||
|
||
const harnessOutput = JSON.parse(harnessStdout); | ||
let numPassed = 0; | ||
let numFailed = 0; | ||
for (const result of harnessOutput) { | ||
if (!result.result.pass) { | ||
numFailed++; | ||
console.error(`${chalk.bold(chalk.bgRed("FAIL"))} ${chalk.bold(result.file)}`); | ||
console.error(result.result.message); | ||
console.error(`stdout:\n${result.rawResult.stdout}`); | ||
console.error(`stderr:\n${result.rawResult.stderr}`); | ||
console.error(); | ||
} else { | ||
numPassed++; | ||
} | ||
} | ||
console.log(`${numPassed} passed, ${numFailed} failed`); | ||
if (numFailed > 0) { | ||
process.exitCode = 1; | ||
} | ||
} | ||
|
||
main().catch((e) => { | ||
console.error("Unhandled error:"); | ||
console.error(e); | ||
process.exitCode = 1; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const sucrase = require(".."); | ||
|
||
/** | ||
* test262-harness preprocessor documented here: | ||
https://github.com/bterlson/test262-harness#preprocessor | ||
*/ | ||
module.exports = function(test) { | ||
// Sucrase doesn't attempt to throw SyntaxError on bad syntax, so skip those tests. | ||
if (test.attrs.negative) { | ||
return null; | ||
} | ||
|
||
// Sucrase assumes strict mode, so skip sloppy mode tests. | ||
if (test.scenario === "default") { | ||
return null; | ||
} | ||
|
||
// TCO tests seem to fail in V8 normally, so skip those. | ||
if (test.attrs.features.includes("tail-call-optimization")) { | ||
return null; | ||
} | ||
|
||
try { | ||
test.contents = sucrase.transform(test.contents, {transforms: []}).code; | ||
} catch (error) { | ||
test.result = { | ||
stderr: `${error.name}: ${error.message}\n`, | ||
stdout: "", | ||
error, | ||
}; | ||
} | ||
|
||
return test; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,8 @@ | |
"generator", | ||
"script", | ||
"src", | ||
"test" | ||
"test", | ||
"test262" | ||
], | ||
"exclude": [ | ||
"benchmark/sample", | ||
|
Oops, something went wrong.