Skip to content

Commit

Permalink
Switch to module 'NodeNext' compilation, fix tests, change in Profile…
Browse files Browse the repository at this point in the history
…Manager
  • Loading branch information
hrax committed Aug 20, 2024
1 parent 9441a93 commit 868fe8e
Show file tree
Hide file tree
Showing 19 changed files with 530 additions and 168 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
/**
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
Expand Down
125 changes: 125 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"docx": "^8.5.0",
"dotenv": "^16.4.5",
"https-proxy-agent": "^7.0.5",
"open": "^10.1.0",
"pdfmake": "^0.2.10",
"prompts": "^2.4.2",
"xpath": "^0.0.34"
Expand Down Expand Up @@ -84,7 +85,7 @@
"peerDependencies": {
"eslint": ">=9.3.0"
},
"type": "commonjs",
"type": "module",
"engines": {
"node": ">=22"
}
Expand Down
34 changes: 17 additions & 17 deletions spec/core/ProfileManager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs, { Stats } from "fs";
import path from "path";
import * as ProfileManager from "../../src/core/ProfileManager";
import profileManager from "../../src/core/ProfileManager";
import { InstanceConfig, Profile, ProfileInfo } from "../../src/core/ProfileManager";
import { RESTClient } from "../../src/core/RESTClient";
import { OAuthClient } from "../../src/core/OAuthClient";
Expand Down Expand Up @@ -55,8 +55,8 @@ describe("ProfileManagerSpec", () => {

const profilesHomePath = "#profilesHome";
jest.spyOn(path, "normalize").mockImplementation((path) => path);
jest.spyOn(ProfileManager, "homeDirPath").mockReturnValue(profilesHomePath);
jest.spyOn(ProfileManager, "profileFilePath").mockImplementation((name, file) => `${profilesHomePath}/${name}/${file}`);
jest.spyOn(profileManager, "getHomePath").mockReturnValue(profilesHomePath);
jest.spyOn(profileManager, "getProfileFilePath").mockImplementation((name, file) => `${profilesHomePath}/${name}/${file}`);

when(jest.spyOn(fs, "readdirSync"))
.defaultImplementation(jesthelpers.defaultWhenImplementationThrow)
Expand All @@ -73,17 +73,17 @@ describe("ProfileManagerSpec", () => {
.calledWith(`${profilesHomePath}/dev1/profile.json`, "utf8").mockReturnValue(JSON.stringify(expected[0]))
.calledWith(`${profilesHomePath}/dev2/profile.json`, "utf8").mockReturnValue(JSON.stringify(expected[1]));

const profiles: ProfileInfo[] = ProfileManager.listProfiles();
const profiles: ProfileInfo[] = profileManager.listProfiles();

expect(profiles).toStrictEqual(expected);
});

it("should purge all existing profiles", () => {
const profilesHomePath = "#profilesHome";
const profilesHomeDirPathSpy = jest.spyOn(ProfileManager, "homeDirPath").mockReturnValue(profilesHomePath);
const profilesHomeDirPathSpy = jest.spyOn(profileManager, "getHomePath").mockReturnValue(profilesHomePath);

const rmSpy = jest.spyOn(fs, "rmdirSync").mockReturnValue(undefined);
ProfileManager.purgeProfiles();
profileManager.purgeProfiles();

expect(profilesHomeDirPathSpy).toHaveBeenCalled();
expect(rmSpy).toHaveBeenCalledWith(profilesHomePath, {recursive: true});
Expand All @@ -94,8 +94,8 @@ describe("ProfileManagerSpec", () => {
const profileName = "dev1";

jest.spyOn(path, "normalize").mockImplementation((path) => path);
jest.spyOn(ProfileManager, "homeDirPath").mockReturnValue(profilesHomePath);
jest.spyOn(ProfileManager, "profileFilePath").mockImplementation((name, file) => `${profilesHomePath}/${name}/${file}`);
jest.spyOn(profileManager, "getHomePath").mockReturnValue(profilesHomePath);
jest.spyOn(profileManager, "getProfileFilePath").mockImplementation((name, file) => `${profilesHomePath}/${name}/${file}`);

jest.spyOn(fs, "existsSync").mockReturnValue(true);
when(jest.spyOn(fs, "readFileSync"))
Expand All @@ -110,7 +110,7 @@ describe("ProfileManagerSpec", () => {
tables: {}
});

await ProfileManager.loadProfile(profileName, restClient);
await profileManager.loadProfile(profileName, restClient);

expect(restClientSpy).toHaveBeenCalledTimes(1);
});
Expand All @@ -131,13 +131,13 @@ describe("ProfileManagerSpec", () => {
const profilesHomePath = "#profilesHome";

jest.spyOn(path, "normalize").mockImplementation((path) => path);
jest.spyOn(ProfileManager, "homeDirPath").mockReturnValue(profilesHomePath);
jest.spyOn(ProfileManager, "profileFilePath").mockImplementation((name, file) => `${profilesHomePath}/${name}/${file}`);
jest.spyOn(profileManager, "getHomePath").mockReturnValue(profilesHomePath);
jest.spyOn(profileManager, "getProfileFilePath").mockImplementation((name, file) => `${profilesHomePath}/${name}/${file}`);

jest.spyOn(fs, "existsSync").mockReturnValue(true);
const writeSpy = jest.spyOn(fs, "writeFileSync").mockReturnValue(undefined);

ProfileManager.saveProfile(profile);
profileManager.saveProfile(profile);

expect(writeSpy).toHaveBeenCalledWith(expect.anything(), JSON.stringify(profileData, null, 2), expect.anything());
});
Expand All @@ -158,13 +158,13 @@ describe("ProfileManagerSpec", () => {
const profilesHomePath = "#profilesHome";

jest.spyOn(path, "normalize").mockImplementation((path) => path);
jest.spyOn(ProfileManager, "homeDirPath").mockReturnValue(profilesHomePath);
jest.spyOn(ProfileManager, "profileFilePath").mockImplementation((name, file) => `${profilesHomePath}/${name}/${file}`);
jest.spyOn(profileManager, "getHomePath").mockReturnValue(profilesHomePath);
jest.spyOn(profileManager, "getProfileFilePath").mockImplementation((name, file) => `${profilesHomePath}/${name}/${file}`);

jest.spyOn(fs, "existsSync").mockReturnValue(true);
const writeSpy = jest.spyOn(fs, "writeFileSync").mockImplementation(undefined);

ProfileManager.updateProfileConfig(profile);
profileManager.updateProfileConfig(profile);

expect(writeSpy).toHaveBeenCalledWith(expect.anything(), JSON.stringify(profileData, null, 2), expect.anything());
});
Expand All @@ -185,11 +185,11 @@ describe("ProfileManagerSpec", () => {
const profilesHomePath = "#profilesHome";

jest.spyOn(path, "normalize").mockImplementation((path) => path);
jest.spyOn(ProfileManager, "homeDirPath").mockReturnValue(profilesHomePath);
jest.spyOn(profileManager, "getHomePath").mockReturnValue(profilesHomePath);

const rmSpy = jest.spyOn(fs, "rmdirSync").mockReturnValue(undefined);

ProfileManager.purgeProfile(profile);
profileManager.purgeProfile(profile);

expect(rmSpy).toHaveBeenCalledTimes(1);
});
Expand Down
29 changes: 0 additions & 29 deletions src/cli/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable no-console */
import { InvalidArgumentError, Option } from "commander";
import { red, green } from "colors/safe";
import * as ProfileManager from "../core/ProfileManager.js";

export const DOMAIN_REGEXP = /^https?:\/\/.*?\/?$/;
Expand Down Expand Up @@ -28,21 +27,6 @@ export function validateFileName(value: string) {
throw new InvalidArgumentError("'file-name' can only contain lowecase/uppercase letters, numbers, underscore and dash.");
}

export function debugOption(): Option {
return new Option("--debug")
.default(false);
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isDebug(options: any): boolean {
return options.debug === true;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function debug(options: any): void {
if (isDebug(options)) {
outputKeyValue("Working profiles home directory", `${ProfileManager.homeDirPath()}`, true);
}
};

export function forceOption(): Option {
return new Option("--force");
}
Expand All @@ -51,19 +35,6 @@ export function isForce(options: any): boolean {
return options.force === true;
}

export function outputError(str: string, write = console.error) {
write(`${red(str)}`);
}
export function outputInfo(str: string, write = console.info) {
write(`${str}`);
}
export function outputDebug(str: string, write = console.debug) {
write(`${str}`);
}
export function outputKeyValue(key: string, value: string, newLine = false, write = console.debug) {
write(`${key}: ${green(value)}${newLine ? "\n" : ""}`);
}

export function boolYesNo(bool: boolean) {
return bool === true ? "Yes" : "No";
}
Loading

0 comments on commit 868fe8e

Please sign in to comment.