mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
feat: refactor tests to use environment variables for credentials and update jest command
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { Command } from "commander";
|
||||
import { ResourceInfo } from "../Types/CLITypes";
|
||||
import * as ConfigManager from "../Core/ConfigManager";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import * as os from "os";
|
||||
@@ -177,11 +176,12 @@ describe("ResourceCommands", () => {
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
ConfigManager.addContext({
|
||||
name: "test",
|
||||
apiUrl: "https://test.oneuptime.com",
|
||||
apiKey: "test-key-12345",
|
||||
});
|
||||
/*
|
||||
* Use env vars for credentials instead of config file to avoid
|
||||
* race conditions with other test files that share ~/.oneuptime/config.json
|
||||
*/
|
||||
process.env["ONEUPTIME_API_KEY"] = "test-key-12345";
|
||||
process.env["ONEUPTIME_URL"] = "https://test.oneuptime.com";
|
||||
mockExecuteApiRequest.mockResolvedValue({ data: [] });
|
||||
});
|
||||
|
||||
@@ -540,7 +540,8 @@ describe("ResourceCommands", () => {
|
||||
|
||||
describe("credential resolution in commands", () => {
|
||||
it("should use global --api-key and --url flags", async () => {
|
||||
ConfigManager.removeContext("test");
|
||||
delete process.env["ONEUPTIME_API_KEY"];
|
||||
delete process.env["ONEUPTIME_URL"];
|
||||
mockExecuteApiRequest.mockResolvedValue({ data: [] });
|
||||
|
||||
const program: Command = createProgramWithResources();
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
"dev": "npx nodemon",
|
||||
"audit": "npm audit --audit-level=low",
|
||||
"dep-check": "npm install -g depcheck && depcheck ./ --skip-missing=true",
|
||||
"test": "jest --passWithNoTests",
|
||||
"test": "jest --passWithNoTests --runInBand",
|
||||
"link": "npm link"
|
||||
},
|
||||
"author": "OneUptime <hello@oneuptime.com> (https://oneuptime.com/)",
|
||||
|
||||
@@ -23,10 +23,7 @@ export class Reference {
|
||||
public derefInto(): unknown {
|
||||
return {};
|
||||
}
|
||||
public applySync(
|
||||
_receiver: unknown,
|
||||
_args: unknown[],
|
||||
): unknown {
|
||||
public applySync(_receiver: unknown, _args: unknown[]): unknown {
|
||||
return undefined;
|
||||
}
|
||||
public applySyncPromise(
|
||||
@@ -38,11 +35,11 @@ export class Reference {
|
||||
}
|
||||
|
||||
export class Callback {
|
||||
constructor(_fn: (...args: unknown[]) => void) {}
|
||||
public constructor(_fn: (...args: unknown[]) => void) {}
|
||||
}
|
||||
|
||||
export class ExternalCopy {
|
||||
constructor(_value: unknown) {}
|
||||
public constructor(_value: unknown) {}
|
||||
public copyInto(): unknown {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// Mock for whois-json ESM module (not parseable by Jest)
|
||||
const whoisJson = async (_domain: string): Promise<Record<string, unknown>> => {
|
||||
const whoisJson: (_domain: string) => Promise<Record<string, unknown>> = async (
|
||||
_domain: string,
|
||||
): Promise<Record<string, unknown>> => {
|
||||
return {};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user