Skip to content

Commit

Permalink
run 'esm' against tc39/test262
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Aug 17, 2018
1 parent 459492d commit 891034c
Show file tree
Hide file tree
Showing 14 changed files with 627 additions and 1 deletion.
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/.repo
/test/_external/test262/.test
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ os:
node_js:
- 10
- 8
- 6.2.0
- 6

cache:
directories:
Expand Down
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.22.0",
"strip-ansi": "^4.0.0",
"test262-parser": "^2.0.7",
"trash": "^4.3.0",
"typescript": "^3.0.1",
"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))
18 changes: 18 additions & 0 deletions script/test262/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict"

const clone = require("./clone.js")
const copy = require("./copy.js")

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
}

module.exports = bootstrap
46 changes: 46 additions & 0 deletions script/test262/clone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"use strict"

const execa = require("execa")
const trash = require("trash")
const { resolve } = require( "path")

const rootPath = resolve(".")
const test262Path = resolve(rootPath, "test/_external/test262")
const test262RepoPath = resolve(test262Path, ".repo")
// const test262RepoGitPath = resolve(test262RepoPath, ".git")

function run(cwd, file, args) {
return execa(file, args, {
cwd,
reject: false
})
}

function clone() {
return trash(test262RepoPath)
.then(() =>
run(test262Path, "git", ["--version"])
)
.then(() =>
run(test262Path, "git", ["clone", "--depth", "1", "https://github.com/tc39/test262.git", ".repo"])
)
}

// 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
46 changes: 46 additions & 0 deletions script/test262/copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"use strict"

const trash = require("trash")
const { resolve } = require("path")
const { copy } = require("fs-extra")

const rootPath = resolve(".")
const test262RepoPath = resolve(rootPath, "test/_external/test262/.repo")
const testPath = resolve(rootPath, "test/_external/test262/.test")

const testDirs = [
"test/language/export",
"test/language/import",
"test/language/module-code",
"harness"
]

function copyTests() {
return trash(testPath)
.then(() =>
Promise.all(
testDirs.map((testDir) =>
copy(resolve(test262RepoPath, testDir), resolve(testPath, 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 () {
return Promise.all(
testDirsDynamicImport.map((testDirDynamicImport) =>
copy(resolve(test262RepoPath, testDirDynamicImport), resolve(testPath, testDirDynamicImport))
)
)
}
// -- END

module.exports = copyTests
32 changes: 32 additions & 0 deletions script/test262/files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict"

const globby = require("globby")
const { resolve } = require("path")

const testPath = resolve(__dirname, "../../test/_external/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
}
)
}
44 changes: 44 additions & 0 deletions test/_external/test262/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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/_external/test262/.test")

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)
})
}

0 comments on commit 891034c

Please sign in to comment.