Skip to content

Commit

Permalink
initial attempt to run 'esm' against tc39/test262
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Aug 6, 2018
1 parent 9a3f1e5 commit a1ac262
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
/test/fixture/main-hook/symlink/symlink.js
/test/fixture/main-hook/symlink/symlink.mjs
/test/fixture/scenario/ava-nyc-tsc/*.js

/test/_external/test262/temp
/test262
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"sleep": "^5.2.3",
"sqreen": "^1.21.0",
"strip-ansi": "^4.0.0",
"test262-parser": "^2.0.7",
"trash": "^4.3.0",
"typescript": "^2.9.2",
"uglify-es": "^3.3.10",
Expand Down
2 changes: 2 additions & 0 deletions script/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const ignorePaths = require("./ignore-paths.js")
const path = require("path")
const trash = require("./trash.js")
const uglify = require("uglify-es").minify
const bootstrapTest262 = require("./test262/bootstrap.js")

const argv = require("yargs")
.boolean("prod")
Expand Down Expand Up @@ -114,5 +115,6 @@ Promise
cleanRepo(),
setupNode()
])
.then(bootstrapTest262)
.then(() => runTests())
.then(() => runTests(true))
13 changes: 13 additions & 0 deletions script/test262/bootstrap.js
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
34 changes: 34 additions & 0 deletions script/test262/clone.js
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
27 changes: 27 additions & 0 deletions script/test262/copy.js
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
87 changes: 87 additions & 0 deletions script/test262/inject.js
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
19 changes: 19 additions & 0 deletions script/test262/tests.js
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
1 change: 1 addition & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import "./main-hook-tests.mjs"
import "./require-hook-tests.js"
import "./repl-hook-tests.mjs"
import "./scenario-tests.mjs"
import "./_external/test262/index.js"

const extensions = Object.assign({}, require.extensions)

Expand Down

0 comments on commit a1ac262

Please sign in to comment.