-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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. |
||
} | ||
|
||
// Import all the regular tests first | ||
import "./setup-globals"; | ||
|
||
import "../index"; | ||
|
||
import "./analytics"; | ||
import "./clean-exit"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2020 Realm Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
/* eslint-disable no-restricted-globals */ | ||
|
||
import { inspect } from "node:util"; | ||
import { existsSync } from "node:fs"; | ||
import { dirname, resolve } from "node:path"; | ||
import v8 from "node:v8"; | ||
import vm from "node:vm"; | ||
|
||
// Set the default depth of objects logged with console.log to improve DX when debugging | ||
inspect.defaultOptions.depth = null; | ||
|
||
v8.setFlagsFromString("--expose_gc"); | ||
|
||
Object.assign(globalThis, { | ||
fs: { | ||
exists(path: string) { | ||
return existsSync(path); | ||
}, | ||
}, | ||
path: { | ||
dirname(path: string) { | ||
return dirname(path); | ||
}, | ||
resolve(...paths: string[]) { | ||
return resolve(...paths); | ||
}, | ||
}, | ||
gc: vm.runInNewContext("gc"), | ||
}); | ||
|
||
// Indicate that the tests are running in Node | ||
environment.node = true; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,10 @@ chai.use(chaiRealmObjects); | |
const DEFAULT_LONG_TIMEOUT = 30 * 1000; // 30s | ||
|
||
describe("Test Harness", function (this: Mocha.Suite) { | ||
// Inject the root suite title from the global | ||
if (typeof title === "string" && this.parent?.root) { | ||
this.parent.title = title; | ||
} | ||
Comment on lines
+58
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
/** | ||
* @see [typings.d.ts](./typings.d.ts) for documentation. | ||
*/ | ||
|
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).