Fix code-server module not being provided in Jest
This commit is contained in:
parent
b881117762
commit
e098df0766
@ -21,20 +21,22 @@ type Module = any
|
|||||||
*/
|
*/
|
||||||
const originalLoad = require("module")._load
|
const originalLoad = require("module")._load
|
||||||
require("module")._load = function (request: string, parent: object, isMain: boolean): Module {
|
require("module")._load = function (request: string, parent: object, isMain: boolean): Module {
|
||||||
if (request === "code-server") {
|
return request === "code-server" ? codeServer : originalLoad.apply(this, [request, parent, isMain])
|
||||||
return {
|
}
|
||||||
express,
|
|
||||||
field,
|
/**
|
||||||
HttpCode,
|
* The module you get when importing "code-server".
|
||||||
HttpError,
|
*/
|
||||||
Level,
|
export const codeServer = {
|
||||||
proxy,
|
express,
|
||||||
replaceTemplates,
|
field,
|
||||||
WsRouter,
|
HttpCode,
|
||||||
wss,
|
HttpError,
|
||||||
}
|
Level,
|
||||||
}
|
proxy,
|
||||||
return originalLoad.apply(this, [request, parent, isMain])
|
replaceTemplates,
|
||||||
|
WsRouter,
|
||||||
|
wss,
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Plugin extends pluginapi.Plugin {
|
interface Plugin extends pluginapi.Plugin {
|
||||||
|
@ -3,11 +3,14 @@ import * as express from "express"
|
|||||||
import * as fs from "fs"
|
import * as fs from "fs"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import { HttpCode } from "../src/common/http"
|
import { HttpCode } from "../src/common/http"
|
||||||
import { PluginAPI } from "../src/node/plugin"
|
import { codeServer, PluginAPI } from "../src/node/plugin"
|
||||||
import * as apps from "../src/node/routes/apps"
|
import * as apps from "../src/node/routes/apps"
|
||||||
import * as httpserver from "./httpserver"
|
import * as httpserver from "./httpserver"
|
||||||
const fsp = fs.promises
|
const fsp = fs.promises
|
||||||
|
|
||||||
|
// Jest overrides `require` so our usual override doesn't work.
|
||||||
|
jest.mock("code-server", () => codeServer)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use $LOG_LEVEL=debug to see debug logs.
|
* Use $LOG_LEVEL=debug to see debug logs.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user