-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run 'esm' against tc39/test262 (#550)
- Loading branch information
1 parent
20a42cf
commit c6b082c
Showing
14 changed files
with
852 additions
and
0 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,26 @@ | ||
"use strict" | ||
|
||
const { resolve } = require("path") | ||
const clone = require("./clone.js") | ||
const copy = require("./copy.js") | ||
const renameFileExtension = require("./file-extension.js") | ||
|
||
const rootPath = resolve(".") | ||
const mjsTestPath = resolve(rootPath, "test/vendor/test262/.mjs-tests") | ||
|
||
function bootstrap() { | ||
return ( | ||
clone() | ||
.then(copy) | ||
// TODO remove: | ||
// temporary measure and can be safily removed once | ||
// the `dynamic import` test PR is merged into test262 | ||
// -- BEGIN | ||
.then(clone.dynamicImport) | ||
.then(copy.dynamicImport) | ||
// -- END | ||
.then(() => renameFileExtension(mjsTestPath, "js", "mjs")) | ||
) | ||
} | ||
|
||
module.exports = bootstrap |
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,51 @@ | ||
"use strict" | ||
|
||
const { resolve } = require("path") | ||
const execa = require("execa") | ||
const { removeSync } = require("fs-extra") | ||
|
||
const rootPath = resolve(".") | ||
const test262Path = resolve(rootPath, "test/vendor/test262") | ||
const test262RepoPath = resolve(test262Path, ".repo-clone") | ||
// const test262RepoGitPath = resolve(test262RepoPath, ".git") | ||
|
||
function run(cwd, file, args) { | ||
return execa(file, args, { | ||
cwd, | ||
reject: false | ||
}) | ||
} | ||
|
||
function clone() { | ||
removeSync(test262RepoPath) | ||
|
||
return run(test262Path, "git", ["--version"]).then(() => | ||
run(test262Path, "git", [ | ||
"clone", | ||
"--depth", | ||
"1", | ||
"https://github.com/tc39/test262.git", | ||
".repo-clone" | ||
]) | ||
) | ||
} | ||
|
||
// TODO remove: | ||
// this is just a temporary measure and can be safily removed once | ||
// the `dynamic import` test PR is merged into test262 | ||
// -- BEGIN | ||
clone.dynamicImport = function () { | ||
return run(test262RepoPath, "git", [ | ||
"fetch", | ||
"origin", | ||
"--depth", | ||
"1", | ||
"pull/1588/head:dynamic-import" | ||
]).then(() => run(test262RepoPath, "git", ["checkout", "dynamic-import"])) | ||
// .then(() => | ||
// trash(test262RepoGitPath) | ||
// ) | ||
// -- END | ||
} | ||
|
||
module.exports = clone |
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,48 @@ | ||
"use strict" | ||
|
||
const { resolve } = require("path") | ||
const { copySync, removeSync } = require("fs-extra") | ||
|
||
const rootPath = resolve(".") | ||
const test262RepoPath = resolve(rootPath, "test/vendor/test262/.repo-clone") | ||
const jsTestPath = resolve(rootPath, "test/vendor/test262/.js-tests") | ||
const mjsTestPath = resolve(rootPath, "test/vendor/test262/.mjs-tests") | ||
|
||
const testDirs = [ | ||
"test/language/export", | ||
"test/language/import", | ||
"test/language/module-code", | ||
"harness" | ||
] | ||
|
||
function copyTests() { | ||
removeSync(jsTestPath) | ||
removeSync(mjsTestPath) | ||
|
||
testDirs.map((testDir) => { | ||
copySync(resolve(test262RepoPath, testDir), resolve(jsTestPath, testDir)) | ||
copySync(resolve(test262RepoPath, testDir), resolve(mjsTestPath, testDir)) | ||
}) | ||
} | ||
|
||
// TODO remove: | ||
// temporary measure and can be safily removed once | ||
// the `dynamic import` test PR is merged into test262 | ||
// -- BEGIN | ||
const testDirsDynamicImport = ["test/language/module-code/dynamic-import"] | ||
|
||
copyTests.dynamicImport = function () { | ||
testDirsDynamicImport.map((testDirDynamicImport) => { | ||
copySync( | ||
resolve(test262RepoPath, testDirDynamicImport), | ||
resolve(jsTestPath, testDirDynamicImport) | ||
) | ||
copySync( | ||
resolve(test262RepoPath, testDirDynamicImport), | ||
resolve(mjsTestPath, testDirDynamicImport) | ||
) | ||
}) | ||
} | ||
// -- END | ||
|
||
module.exports = copyTests |
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,33 @@ | ||
const { sep } = require("path") | ||
const { readFileSync, renameSync, writeFileSync } = require("fs-extra") | ||
const globby = require("globby") | ||
|
||
function renameFileExtension(test262Path, fromExt, toExt) { | ||
const test262Files = globby.sync( | ||
[ | ||
`test/language/export/**/*.${fromExt}`, | ||
`test/language/import/**/*.${fromExt}`, | ||
`test/language/module-code/**/*.${fromExt}` | ||
], | ||
{ | ||
absolute: true, | ||
cwd: test262Path, | ||
// https://github.com/sindresorhus/globby/issues/38 | ||
transform: (entry) => (sep === "\\" ? entry.replace(/\//g, "\\") : entry) | ||
} | ||
) | ||
|
||
test262Files.forEach((file) => { | ||
const raw = readFileSync(file, "utf-8") | ||
|
||
const content = raw.replace(new RegExp("." + fromExt, "g"), "." + toExt) | ||
|
||
writeFileSync(file, content) | ||
}) | ||
|
||
test262Files.forEach((file) => | ||
renameSync(file, file.replace("." + fromExt, "." + toExt)) | ||
) | ||
} | ||
|
||
module.exports = renameFileExtension |
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,27 @@ | ||
"use strict" | ||
|
||
const globby = require("globby") | ||
const { resolve } = require("path") | ||
|
||
const testPath = resolve(__dirname, "../../test/vendor/test262/.test") | ||
|
||
exports.getTestFiles = function getTestFiles() { | ||
return globby( | ||
[ | ||
"test/language/export/**/*.js", | ||
"test/language/import/**/*.js", | ||
"test/language/module-code/**/*.js" | ||
], | ||
{ | ||
absolute: true, | ||
cwd: testPath | ||
} | ||
) | ||
} | ||
|
||
exports.getHarnessFiles = function getHarnessFiles() { | ||
return globby(["harness/*.js"], { | ||
absolute: true, | ||
cwd: testPath | ||
}) | ||
} |
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,35 @@ | ||
import { createContext, Script } from "vm" | ||
import { basename, resolve } from "path" | ||
import test262Parser from "test262-parser" | ||
import fs from "fs-extra" | ||
import globby from "globby" | ||
import { stdout } from "process" | ||
|
||
// TODO: | ||
const testPath = resolve("../test/vendor/test262/.js-tests") | ||
|
||
const harnessFiles = [ | ||
"assert.js", | ||
"sta.js", | ||
"doneprintHandle.js", | ||
"fnGlobalObject.js" | ||
] | ||
|
||
function getHarnessFiles() { | ||
return globby.sync(["harness/*.js"], { | ||
absolute: true, | ||
cwd: testPath | ||
}) | ||
} | ||
|
||
const sandbox = createContext(global) | ||
|
||
export default function harnessContext() { | ||
getHarnessFiles() | ||
.filter((file) => harnessFiles.includes(basename(file))) | ||
.map((filename) => fs.readFileSync(filename, "utf-8")) | ||
.forEach((rawHarness) => { | ||
const { contents } = test262Parser.parseFile(rawHarness) | ||
new Script(contents).runInContext(sandbox) | ||
}) | ||
} |
Oops, something went wrong.