Use regular imports instead of require where possible (#59017)

This commit is contained in:
Jake Bailey
2024-06-25 13:56:05 -07:00
committed by GitHub
parent e70904a24f
commit ef339af128
11 changed files with 47 additions and 122 deletions

View File

@@ -1,3 +1,11 @@
import { fork } from "child_process";
import { statSync } from "fs";
import Mocha from "mocha";
import ms from "ms";
import os from "os";
import path from "path";
import readline from "readline";
import tty from "tty";
import {
configOption,
globalTimeout,
@@ -26,20 +34,12 @@ import * as ts from "../_namespaces/ts.js";
import * as Utils from "../_namespaces/Utils.js";
export function start(importTests: () => Promise<unknown>) {
const Mocha = require("mocha") as typeof import("mocha");
const Base = Mocha.reporters.Base;
const color = Base.color;
const cursor = Base.cursor;
const ms = require("ms") as typeof import("ms");
const readline = require("readline") as typeof import("readline");
const os = require("os") as typeof import("os");
const tty = require("tty") as typeof import("tty");
const isatty = tty.isatty(1) && tty.isatty(2);
const path = require("path") as typeof import("path");
const { fork } = require("child_process") as typeof import("child_process");
const { statSync } = require("fs") as typeof import("fs");
// NOTE: paths for module and types for FailedTestReporter _do not_ line up due to our use of --outFile for run.js
// NOTE: paths for module and types for FailedTestReporter _do not_ line up when bundled
const FailedTestReporter = require(Utils.findUpFile("scripts/failed-tests.cjs")) as typeof import("../../../scripts/failed-tests.cjs");
const perfdataFileNameFragment = ".parallelperf";

View File

@@ -1,3 +1,4 @@
import Mocha from "mocha";
import {
createRunner,
globalTimeout,
@@ -39,9 +40,6 @@ export function start(importTests: () => Promise<unknown>) {
let exceptionsHooked = false;
hookUncaughtExceptions();
// Capitalization is aligned with the global `Mocha` namespace for typespace/namespace references.
const Mocha = require("mocha") as typeof import("mocha");
/**
* Mixin helper.
* @param base The base class constructor.

View File

@@ -1,10 +1,9 @@
import * as Diff from "diff";
import * as Harness from "../_namespaces/Harness.js";
import * as ts from "../_namespaces/ts.js";
import * as Utils from "../_namespaces/Utils.js";
describe("unittests:: skipJSDocParsing", () => {
const Diff = require("diff");
const kinds = [
ts.JSDocParsingMode.ParseAll,
ts.JSDocParsingMode.ParseForTypeErrors,