-
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.
initial attempt to run 'esm' against tc39/test262
- Loading branch information
1 parent
9a3f1e5
commit a1ac262
Showing
10 changed files
with
197 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,13 @@ | ||
"use strict" | ||
|
||
const clone = require("./clone.js") | ||
const copy = require("./copy.js") | ||
const inject = require("./inject.js") | ||
|
||
function bootstrap() { | ||
return clone() | ||
.then(copy) | ||
.then(inject) | ||
} | ||
|
||
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,34 @@ | ||
"use strict" | ||
|
||
const execa = require("execa") | ||
const trash = require("trash") | ||
const { resolve } = require( "path") | ||
|
||
const rootPath = resolve(".") | ||
|
||
function run(file, args) { | ||
return execa(file, args, { | ||
cwd: rootPath, | ||
reject: false | ||
}) | ||
} | ||
|
||
const test262RepoPath = resolve(rootPath, "test262") | ||
|
||
function clone() { | ||
return trash(test262RepoPath) | ||
.then(() => | ||
run("git", ["--version"]) | ||
) | ||
.then(({ stdout }) => | ||
console.log("git version: ", stdout) | ||
) | ||
.then(() => | ||
run("git", ["clone", "--depth", "1", "https://github.com/tc39/test262.git"]) | ||
) | ||
.catch((e) => { | ||
console.log(e) | ||
}) | ||
} | ||
|
||
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,27 @@ | ||
"use strict" | ||
|
||
const trash = require("trash") | ||
const { resolve } = require("path") | ||
const { copy } = require("fs-extra") | ||
|
||
const rootPath = resolve(".") | ||
const test262Path = resolve(rootPath, "test262") | ||
const testPath = resolve(rootPath, "test/_external/test262/temp") | ||
|
||
const testDirs = [ | ||
"test/language/module-code", | ||
"harness" | ||
] | ||
|
||
function copyTests() { | ||
return trash(testPath) | ||
.then(() => | ||
Promise.all( | ||
testDirs.map((testDir) => | ||
copy(resolve(test262Path, testDir), resolve(testPath, testDir)) | ||
) | ||
) | ||
) | ||
} | ||
|
||
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,87 @@ | ||
"use strict" | ||
|
||
const test262Parser = require("test262-parser") | ||
const tests = require("./tests") | ||
const { resolve } = require("path") | ||
const { readFile, writeFile } = require("fs-extra") | ||
|
||
const rootPath = resolve(".") | ||
const testPath = resolve(rootPath, "test/_external/test262/temp") | ||
const harnessPath = resolve(testPath, "harness") | ||
|
||
let test262Assert | ||
|
||
function loadTest262Assert() { | ||
return readFile(resolve(harnessPath, "assert.js"), "utf-8") | ||
.then((rawTest) => { | ||
const { contents } = test262Parser.parseFile(rawTest) | ||
test262Assert = contents | ||
}) | ||
} | ||
|
||
const testIncludes = new Map() | ||
|
||
function getInclude(name) { | ||
|
||
const include = testIncludes.get(name) | ||
|
||
if (include) { | ||
return Promise.resolve(include) | ||
} | ||
|
||
return readFile(resolve(harnessPath, name), "utf-8") | ||
.then((rawTest) => { | ||
const { contents } = test262Parser.parseFile(rawTest) | ||
|
||
testIncludes.set(name, contents) | ||
|
||
return contents | ||
}) | ||
} | ||
|
||
function injectIncludes(filepath) { | ||
return readFile(filepath, "utf-8") | ||
.then((rawTest) => { | ||
|
||
const parsedFile = test262Parser.parseFile(rawTest) | ||
|
||
let includes = [] | ||
|
||
if (Reflect.has(parsedFile.attrs, "includes")) { | ||
includes = parsedFile.attrs.includes.map((name) => | ||
getInclude(name) | ||
) | ||
} | ||
|
||
return Promise.all(includes) | ||
.then((includesContent) => | ||
includesContent.join("\n") + "\n" + rawTest | ||
) | ||
}) | ||
.catch((e) => | ||
console.log(e) | ||
) | ||
} | ||
|
||
function inject() { | ||
return loadTest262Assert() | ||
.then(tests) | ||
.then((tests) => | ||
Promise.all( | ||
tests.map((filepath) => | ||
injectIncludes(filepath) | ||
.then((testCode) => | ||
'"use module"\n' + test262Assert + "\n" + testCode | ||
) | ||
.then((testCodeInjected) => | ||
writeFile(filepath, testCodeInjected) | ||
) | ||
) | ||
) | ||
) | ||
.catch((e) => | ||
console.log(e) | ||
) | ||
} | ||
|
||
module.exports = inject |
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,19 @@ | ||
"use strict" | ||
|
||
const globby = require("globby") | ||
const { resolve } = require("path") | ||
|
||
const rootPath = resolve(".") | ||
const testPath = resolve(rootPath, "test/_external/test262/temp") | ||
|
||
function tests() { | ||
return globby( | ||
["test/language/module-code/*.js"], | ||
{ | ||
absolute: true, | ||
cwd: testPath | ||
} | ||
) | ||
} | ||
|
||
module.exports = tests |
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