diff --git a/test/cli.test.ts b/test/unit/cli.test.ts similarity index 99% rename from test/cli.test.ts rename to test/unit/cli.test.ts index 6a0cfd7b..94c72205 100644 --- a/test/cli.test.ts +++ b/test/unit/cli.test.ts @@ -3,8 +3,8 @@ import * as fs from "fs-extra" import * as net from "net" import * as os from "os" import * as path from "path" -import { Args, parse, setDefaults, shouldOpenInExistingInstance } from "../src/node/cli" -import { paths, tmpdir } from "../src/node/util" +import { Args, parse, setDefaults, shouldOpenInExistingInstance } from "../../src/node/cli" +import { paths, tmpdir } from "../../src/node/util" type Mutable = { -readonly [P in keyof T]: T[P] diff --git a/test/constants.test.ts b/test/unit/constants.test.ts similarity index 90% rename from test/constants.test.ts rename to test/unit/constants.test.ts index 0cb33f2f..e4b14a6c 100644 --- a/test/constants.test.ts +++ b/test/unit/constants.test.ts @@ -1,8 +1,8 @@ -import { commit, getPackageJson, version } from "../src/node/constants" -import { loggerModule } from "./helpers" +import { commit, getPackageJson, version } from "../../src/node/constants" +import { loggerModule } from "../utils/helpers" // jest.mock is hoisted above the imports so we must use `require` here. -jest.mock("@coder/logger", () => require("./helpers").loggerModule) +jest.mock("@coder/logger", () => require("../utils/helpers").loggerModule) describe("constants", () => { describe("getPackageJson", () => { diff --git a/test/emitter.test.ts b/test/unit/emitter.test.ts similarity index 95% rename from test/emitter.test.ts rename to test/unit/emitter.test.ts index 3ea72ae2..ebc6491b 100644 --- a/test/emitter.test.ts +++ b/test/unit/emitter.test.ts @@ -1,8 +1,8 @@ // Note: we need to import logger from the root // because this is the logger used in logError in ../src/common/util -import { logger } from "../node_modules/@coder/logger" +import { logger } from "../../node_modules/@coder/logger" -import { Emitter } from "../src/common/emitter" +import { Emitter } from "../../src/common/emitter" describe("emitter", () => { let spy: jest.SpyInstance diff --git a/test/health.test.ts b/test/unit/health.test.ts similarity index 91% rename from test/health.test.ts rename to test/unit/health.test.ts index 4eae9c60..a8bdfb19 100644 --- a/test/health.test.ts +++ b/test/unit/health.test.ts @@ -1,5 +1,5 @@ -import * as httpserver from "./httpserver" -import * as integration from "./integration" +import * as httpserver from "../utils/httpserver" +import * as integration from "../utils/integration" describe("health", () => { let codeServer: httpserver.HttpServer | undefined diff --git a/test/http.test.ts b/test/unit/http.test.ts similarity index 94% rename from test/http.test.ts rename to test/unit/http.test.ts index 234fca0d..5275adc8 100644 --- a/test/http.test.ts +++ b/test/unit/http.test.ts @@ -1,4 +1,4 @@ -import { HttpCode, HttpError } from "../src/common/http" +import { HttpCode, HttpError } from "../../src/common/http" describe("http", () => { describe("HttpCode", () => { diff --git a/test/plugin.test.ts b/test/unit/plugin.test.ts similarity index 92% rename from test/plugin.test.ts rename to test/unit/plugin.test.ts index 24326ded..7df360df 100644 --- a/test/plugin.test.ts +++ b/test/unit/plugin.test.ts @@ -2,11 +2,11 @@ import { logger } from "@coder/logger" import * as express from "express" import * as fs from "fs" import * as path from "path" -import { HttpCode } from "../src/common/http" -import { AuthType } from "../src/node/cli" -import { codeServer, PluginAPI } from "../src/node/plugin" -import * as apps from "../src/node/routes/apps" -import * as httpserver from "./httpserver" +import { HttpCode } from "../../src/common/http" +import { AuthType } from "../../src/node/cli" +import { codeServer, PluginAPI } from "../../src/node/plugin" +import * as apps from "../../src/node/routes/apps" +import * as httpserver from "../utils/httpserver" const fsp = fs.promises // Jest overrides `require` so our usual override doesn't work. diff --git a/test/proxy.test.ts b/test/unit/proxy.test.ts similarity index 96% rename from test/proxy.test.ts rename to test/unit/proxy.test.ts index 84a2c35b..c5969ebf 100644 --- a/test/proxy.test.ts +++ b/test/unit/proxy.test.ts @@ -1,7 +1,7 @@ import bodyParser from "body-parser" import * as express from "express" -import * as httpserver from "./httpserver" -import * as integration from "./integration" +import * as httpserver from "../utils/httpserver" +import * as integration from "../utils/integration" describe("proxy", () => { const nhooyrDevServer = new httpserver.HttpServer() diff --git a/test/register.test.ts b/test/unit/register.test.ts similarity index 93% rename from test/register.test.ts rename to test/unit/register.test.ts index a80c2034..d19f6300 100644 --- a/test/register.test.ts +++ b/test/unit/register.test.ts @@ -1,5 +1,5 @@ import { JSDOM } from "jsdom" -import { loggerModule } from "./helpers" +import { loggerModule } from "../utils/helpers" describe("register", () => { describe("when navigator and serviceWorker are defined", () => { @@ -40,7 +40,7 @@ describe("register", () => { it("should register a ServiceWorker", () => { // Load service worker like you would in the browser - require("../src/browser/register") + require("../../src/browser/register") expect(mockRegisterFn).toHaveBeenCalled() expect(mockRegisterFn).toHaveBeenCalledTimes(1) }) @@ -54,7 +54,7 @@ describe("register", () => { }) // Load service worker like you would in the browser - require("../src/browser/register") + require("../../src/browser/register") expect(mockRegisterFn).toHaveBeenCalled() expect(loggerModule.logger.error).toHaveBeenCalled() @@ -78,7 +78,7 @@ describe("register", () => { it("should log an error to the console", () => { // Load service worker like you would in the browser - require("../src/browser/register") + require("../../src/browser/register") expect(spy).toHaveBeenCalled() expect(spy).toHaveBeenCalledTimes(1) expect(spy).toHaveBeenCalledWith("[Service Worker] navigator is undefined") diff --git a/test/serviceWorker.test.ts b/test/unit/serviceWorker.test.ts similarity index 91% rename from test/serviceWorker.test.ts rename to test/unit/serviceWorker.test.ts index 7933d1f4..c8b0a625 100644 --- a/test/serviceWorker.test.ts +++ b/test/unit/serviceWorker.test.ts @@ -58,7 +58,7 @@ describe("serviceWorker", () => { }) it("should add 3 listeners: install, activate and fetch", () => { - require("../src/browser/serviceWorker.ts") + require("../../src/browser/serviceWorker.ts") const listenerEventNames = listeners.map((listener) => listener.event) expect(listeners).toHaveLength(3) @@ -68,20 +68,20 @@ describe("serviceWorker", () => { }) it("should call the proper callbacks for 'install'", async () => { - require("../src/browser/serviceWorker.ts") + require("../../src/browser/serviceWorker.ts") emit("install") expect(spy).toHaveBeenCalledWith("[Service Worker] installed") expect(spy).toHaveBeenCalledTimes(1) }) it("should do nothing when 'fetch' is called", async () => { - require("../src/browser/serviceWorker.ts") + require("../../src/browser/serviceWorker.ts") emit("fetch") expect(spy).not.toHaveBeenCalled() }) it("should call the proper callbacks for 'activate'", async () => { - require("../src/browser/serviceWorker.ts") + require("../../src/browser/serviceWorker.ts") emit("activate") // Activate serviceWorker diff --git a/test/socket.test.ts b/test/unit/socket.test.ts similarity index 96% rename from test/socket.test.ts rename to test/unit/socket.test.ts index e614e94d..da0b404a 100644 --- a/test/socket.test.ts +++ b/test/unit/socket.test.ts @@ -3,9 +3,9 @@ import * as fs from "fs-extra" import * as net from "net" import * as path from "path" import * as tls from "tls" -import { Emitter } from "../src/common/emitter" -import { SocketProxyProvider } from "../src/node/socket" -import { generateCertificate, tmpdir } from "../src/node/util" +import { Emitter } from "../../src/common/emitter" +import { SocketProxyProvider } from "../../src/node/socket" +import { generateCertificate, tmpdir } from "../../src/node/util" describe("SocketProxyProvider", () => { const provider = new SocketProxyProvider() diff --git a/test/unit/test-plugin/.eslintrc.yaml b/test/unit/test-plugin/.eslintrc.yaml new file mode 100644 index 00000000..67a20fa6 --- /dev/null +++ b/test/unit/test-plugin/.eslintrc.yaml @@ -0,0 +1,5 @@ +settings: + import/resolver: + alias: + map: + - [code-server, ./typings/pluginapi.d.ts] diff --git a/test/unit/test-plugin/.gitignore b/test/unit/test-plugin/.gitignore new file mode 100644 index 00000000..1fcb1529 --- /dev/null +++ b/test/unit/test-plugin/.gitignore @@ -0,0 +1 @@ +out diff --git a/test/unit/test-plugin/Makefile b/test/unit/test-plugin/Makefile new file mode 100644 index 00000000..d01aa80a --- /dev/null +++ b/test/unit/test-plugin/Makefile @@ -0,0 +1,6 @@ +out/index.js: src/index.ts + # Typescript always emits, even on errors. + yarn build || rm out/index.js + +node_modules: package.json yarn.lock + yarn diff --git a/test/unit/test-plugin/package.json b/test/unit/test-plugin/package.json new file mode 100644 index 00000000..2fe72378 --- /dev/null +++ b/test/unit/test-plugin/package.json @@ -0,0 +1,16 @@ +{ + "private": true, + "name": "test-plugin", + "version": "1.0.0", + "engines": { + "code-server": "^3.7.0" + }, + "main": "out/index.js", + "devDependencies": { + "@types/express": "^4.17.8", + "typescript": "^4.0.5" + }, + "scripts": { + "build": "tsc" + } +} diff --git a/test/unit/test-plugin/public/icon.svg b/test/unit/test-plugin/public/icon.svg new file mode 100644 index 00000000..25b9cf04 --- /dev/null +++ b/test/unit/test-plugin/public/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/unit/test-plugin/public/index.html b/test/unit/test-plugin/public/index.html new file mode 100644 index 00000000..3485f18e --- /dev/null +++ b/test/unit/test-plugin/public/index.html @@ -0,0 +1,10 @@ + + + + + Test Plugin + + +

Welcome to the test plugin!

+ + diff --git a/test/unit/test-plugin/src/index.ts b/test/unit/test-plugin/src/index.ts new file mode 100644 index 00000000..772b59d8 --- /dev/null +++ b/test/unit/test-plugin/src/index.ts @@ -0,0 +1,52 @@ +import * as cs from "code-server" +import * as fspath from "path" + +export const plugin: cs.Plugin = { + displayName: "Test Plugin", + routerPath: "/test-plugin", + homepageURL: "https://example.com", + description: "Plugin used in code-server tests.", + + init(config) { + config.logger.debug("test-plugin loaded!") + }, + + router() { + const r = cs.express.Router() + r.get("/test-app", (_, res) => { + res.sendFile(fspath.resolve(__dirname, "../public/index.html")) + }) + r.get("/goland/icon.svg", (_, res) => { + res.sendFile(fspath.resolve(__dirname, "../public/icon.svg")) + }) + r.get("/error", () => { + throw new cs.HttpError("error", cs.HttpCode.LargePayload) + }) + return r + }, + + wsRouter() { + const wr = cs.WsRouter() + wr.ws("/test-app", (req) => { + cs.wss.handleUpgrade(req, req.ws, req.head, (ws) => { + req.ws.resume() + ws.send("hello") + }) + }) + return wr + }, + + applications() { + return [ + { + name: "Test App", + version: "4.0.0", + iconPath: "/icon.svg", + path: "/test-app", + + description: "This app does XYZ.", + homepageURL: "https://example.com", + }, + ] + }, +} diff --git a/test/unit/test-plugin/tsconfig.json b/test/unit/test-plugin/tsconfig.json new file mode 100644 index 00000000..5afea81b --- /dev/null +++ b/test/unit/test-plugin/tsconfig.json @@ -0,0 +1,71 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, + "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, + // "lib": [], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "./out" /* Redirect output structure to the directory. */, + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true /* Enable all strict type-checking options. */, + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + "baseUrl": "./" /* Base directory to resolve non-absolute module names. */, + "paths": { + "code-server": ["../../typings/pluginapi"] + } /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */, + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "skipLibCheck": true /* Skip type checking of declaration files. */, + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +} diff --git a/test/unit/test-plugin/yarn.lock b/test/unit/test-plugin/yarn.lock new file mode 100644 index 00000000..f295de1e --- /dev/null +++ b/test/unit/test-plugin/yarn.lock @@ -0,0 +1,70 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@types/body-parser@*": + version "1.19.0" + resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.19.0.tgz#0685b3c47eb3006ffed117cdd55164b61f80538f" + integrity sha512-W98JrE0j2K78swW4ukqMleo8R7h/pFETjM2DQ90MF6XK2i4LO4W3gQ71Lt4w3bfm2EvVSyWHplECvB5sK22yFQ== + dependencies: + "@types/connect" "*" + "@types/node" "*" + +"@types/connect@*": + version "3.4.33" + resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.33.tgz#31610c901eca573b8713c3330abc6e6b9f588546" + integrity sha512-2+FrkXY4zllzTNfJth7jOqEHC+enpLeGslEhpnTAkg21GkRrWV4SsAtqchtT4YS9/nODBU2/ZfsBY2X4J/dX7A== + dependencies: + "@types/node" "*" + +"@types/express-serve-static-core@*": + version "4.17.13" + resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.13.tgz#d9af025e925fc8b089be37423b8d1eac781be084" + integrity sha512-RgDi5a4nuzam073lRGKTUIaL3eF2+H7LJvJ8eUnCI0wA6SNjXc44DCmWNiTLs/AZ7QlsFWZiw/gTG3nSQGL0fA== + dependencies: + "@types/node" "*" + "@types/qs" "*" + "@types/range-parser" "*" + +"@types/express@^4.17.8": + version "4.17.8" + resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.8.tgz#3df4293293317e61c60137d273a2e96cd8d5f27a" + integrity sha512-wLhcKh3PMlyA2cNAB9sjM1BntnhPMiM0JOBwPBqttjHev2428MLEB4AYVN+d8s2iyCVZac+o41Pflm/ZH5vLXQ== + dependencies: + "@types/body-parser" "*" + "@types/express-serve-static-core" "*" + "@types/qs" "*" + "@types/serve-static" "*" + +"@types/mime@*": + version "2.0.3" + resolved "https://registry.yarnpkg.com/@types/mime/-/mime-2.0.3.tgz#c893b73721db73699943bfc3653b1deb7faa4a3a" + integrity sha512-Jus9s4CDbqwocc5pOAnh8ShfrnMcPHuJYzVcSUU7lrh8Ni5HuIqX3oilL86p3dlTrk0LzHRCgA/GQ7uNCw6l2Q== + +"@types/node@*": + version "14.14.6" + resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.6.tgz#146d3da57b3c636cc0d1769396ce1cfa8991147f" + integrity sha512-6QlRuqsQ/Ox/aJEQWBEJG7A9+u7oSYl3mem/K8IzxXG/kAGbV1YPD9Bg9Zw3vyxC/YP+zONKwy8hGkSt1jxFMw== + +"@types/qs@*": + version "6.9.5" + resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.5.tgz#434711bdd49eb5ee69d90c1d67c354a9a8ecb18b" + integrity sha512-/JHkVHtx/REVG0VVToGRGH2+23hsYLHdyG+GrvoUGlGAd0ErauXDyvHtRI/7H7mzLm+tBCKA7pfcpkQ1lf58iQ== + +"@types/range-parser@*": + version "1.2.3" + resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.3.tgz#7ee330ba7caafb98090bece86a5ee44115904c2c" + integrity sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA== + +"@types/serve-static@*": + version "1.13.6" + resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.6.tgz#866b1b8dec41c36e28c7be40ac725b88be43c5c1" + integrity sha512-nuRJmv7jW7VmCVTn+IgYDkkbbDGyIINOeu/G0d74X3lm6E5KfMeQPJhxIt1ayQeQB3cSxvYs1RA/wipYoFB4EA== + dependencies: + "@types/mime" "*" + "@types/node" "*" + +typescript@^4.0.5: + version "4.0.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389" + integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ== diff --git a/test/update.test.ts b/test/unit/update.test.ts similarity index 95% rename from test/update.test.ts rename to test/unit/update.test.ts index d275be4a..0f5d55a6 100644 --- a/test/update.test.ts +++ b/test/unit/update.test.ts @@ -1,9 +1,9 @@ import * as fs from "fs-extra" import * as http from "http" import * as path from "path" -import { SettingsProvider, UpdateSettings } from "../src/node/settings" -import { LatestResponse, UpdateProvider } from "../src/node/update" -import { tmpdir } from "../src/node/util" +import { SettingsProvider, UpdateSettings } from "../../src/node/settings" +import { LatestResponse, UpdateProvider } from "../../src/node/update" +import { tmpdir } from "../../src/node/util" describe.skip("update", () => { let version = "1.0.0" diff --git a/test/util.test.ts b/test/unit/util.test.ts similarity index 96% rename from test/util.test.ts rename to test/unit/util.test.ts index 2681d877..31eace76 100644 --- a/test/util.test.ts +++ b/test/unit/util.test.ts @@ -10,11 +10,11 @@ import { split, trimSlashes, normalize, -} from "../src/common/util" -import { Cookie as CookieEnum } from "../src/node/routes/login" -import { hash } from "../src/node/util" -import { PASSWORD } from "./constants" -import { checkForCookie, createCookieIfDoesntExist, loggerModule, Cookie } from "./helpers" +} from "../../src/common/util" +import { Cookie as CookieEnum } from "../../src/node/routes/login" +import { hash } from "../../src/node/util" +import { PASSWORD } from "../utils/constants" +import { checkForCookie, createCookieIfDoesntExist, loggerModule, Cookie } from "../utils/helpers" const dom = new JSDOM() global.document = dom.window.document @@ -22,7 +22,7 @@ global.document = dom.window.document type LocationLike = Pick // jest.mock is hoisted above the imports so we must use `require` here. -jest.mock("@coder/logger", () => require("./helpers").loggerModule) +jest.mock("@coder/logger", () => require("../utils/helpers").loggerModule) describe("util", () => { describe("normalize", () => { diff --git a/test/wtfnode.ts b/test/wtfnode.ts deleted file mode 100644 index 2d31a4e6..00000000 --- a/test/wtfnode.ts +++ /dev/null @@ -1,35 +0,0 @@ -import * as util from "util" -import * as wtfnode from "wtfnode" - -// Jest seems to hijack console.log in a way that makes the output difficult to -// read. So we'll write directly to process.stderr instead. -const write = (...args: [any, ...any]) => { - if (args.length > 0) { - process.stderr.write(util.format(...args) + "\n") - } -} -wtfnode.setLogger("info", write) -wtfnode.setLogger("warn", write) -wtfnode.setLogger("error", write) - -let active = false - -/** - * Start logging open handles periodically. This can be used to see what is - * hanging open if anything. - */ -export function setup(): void { - if (active) { - return - } - active = true - - const interval = 5000 - const wtfnodeDump = () => { - wtfnode.dump() - const t = setTimeout(wtfnodeDump, interval) - t.unref() - } - const t = setTimeout(wtfnodeDump, interval) - t.unref() -}