-
Notifications
You must be signed in to change notification settings - Fork 572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactored Node test environments to share more #6798
Conversation
cbb3e02
to
b0f3dd7
Compare
const fs = require("fs-extra"); | ||
const path = require("path"); | ||
const v8 = require("v8"); | ||
const vm = require("vm"); | ||
|
||
v8.setFlagsFromString("--expose_gc"); | ||
|
||
const client = new Client({ | ||
title: `Node.js v${process.versions.node} on ${os.platform()} (via CommonJS)`, | ||
tests(context) { | ||
// Exposing the Realm constructor as a global | ||
global.fs = fs; | ||
global.path = path; | ||
global.environment = { ...context, node: true }; | ||
global.gc = vm.runInNewContext("gc"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main idea behind this refactor is to move this into a shared "node/src/setup-globals.ts" used across these two "runners" and the test ran with bare mocha (without mocha-remote - used when debugging native code).
@@ -16,7 +16,14 @@ | |||
// | |||
//////////////////////////////////////////////////////////////////////////// | |||
|
|||
// NOTE: This file is only supposed to be imported from a Node.js environment | |||
if (typeof process.versions.node !== "string") { | |||
throw new Error("This file is only supposed to be imported from a Node.js environment!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asserting that this gets imported from node instead of simply commenting the intent.
if (typeof title === "string" && this.parent?.root) { | ||
this.parent.title = title; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was needed to get the title from "inject-dev-environment.ts" to propagate as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What, How & Why?
This is a refactor of the node test environment + the node-based dev environment (running tests without mocha-remote).