Skip to content

Commit

Permalink
Patch up unit tests after change to casing rules
Browse files Browse the repository at this point in the history
  • Loading branch information
hatton committed Jul 18, 2024
1 parent bb18090 commit 92ed4ef
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 40 deletions.
54 changes: 34 additions & 20 deletions src/export/consentImdi-edolo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import temp from "temp";
import * as fs from "fs-extra";
import * as Path from "path";
import { IMDIMode } from "./ImdiGenerator";
import { c } from "vitest/dist/reporters-5f784f42.js";

temp.track(); // cleanup on exit: doesn't work

/* April 2021 this needs work. It relies on a file, ConsentDocuments.imdi being in the Edolo Sample, but that
wouldn't normally have that file since imdi's don't come with the sample, they need to be generated.*/

let rootDirectory: string;
let lock = false;
describe("Consent Form Inclusion", () => {
afterAll(() => {
try {
Expand All @@ -26,29 +28,41 @@ describe("Consent Form Inclusion", () => {
} catch (e) {
// was having trouble cleaning up when running all tests
console.warn(`consentImdi-edolo.spec.ts: afterAll: ${e}`);
} finally {
lock = false;
}
});
beforeAll(async () => {
const project = Project.fromDirectory("sample data/Edolo sample");
// including "fssync" in the path tells our file copy thing to just do the copy synchronously
rootDirectory = temp.mkdirSync("ImdiBundlerTest-fssync");
await ImdiBundler.addConsentBundle(
project,
rootDirectory,
"",
[],
IMDIMode.RAW_IMDI,
true, //<-- copy in files
// eslint-disable-next-line @typescript-eslint/no-unused-vars
(f) => true,
true
);
const xml = fs.readFileSync(
Path.join(rootDirectory, "ConsentDocuments.imdi"),
"utf8"
);
expect(xml).toBeTruthy();
setResultXml(xml);
// I was getting errors that appeared to be related to parallel tests
while (lock) {
await new Promise((resolve) => setTimeout(resolve, 100));
}

lock = true;
try {
const project = Project.fromDirectory("sample data/Edolo sample");
// including "fssync" in the path tells our file copy thing to just do the copy synchronously
rootDirectory = temp.mkdirSync("ImdiBundlerTest-fssync");
await ImdiBundler.addConsentBundle(
project,
rootDirectory,
"",
[],
IMDIMode.RAW_IMDI,
true, //<-- copy in files
// eslint-disable-next-line @typescript-eslint/no-unused-vars
(f) => true,
true
);
const xml = fs.readFileSync(
Path.join(rootDirectory, "ConsentDocuments.imdi"),
"utf8"
);
expect(xml).toBeTruthy();
setResultXml(xml);
} finally {
lock = false;
}
});
it("The consent form dummy session to look reasonable", () => {
expect(count("METATRANSCRIPT")).toBe(1);
Expand Down
4 changes: 2 additions & 2 deletions src/export/sessionImdi-custom.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ describe("session imdi export", () => {
true /*omit namespace*/
)
);
expect(`//Keys/Key[@Name="Keyword"]`).toHaveSomeMatch("One two UN");
expect(`//Keys/Key[@Name="Keyword"]`).toHaveSomeMatch("one two UN");
expect(`//Keys/Key[@Name="Keyword"]`).toHaveSomeMatch("FLEx");
expect(`//Keys/Key[@Name="Keyword"]`).toHaveSomeMatch("Foo");
expect(`//Keys/Key[@Name="Keyword"]`).toHaveSomeMatch("foo");
expect(`//Keys/Key[@Name="Keyword"]`).toHaveSomeMatch("XYZ");
});

Expand Down
4 changes: 2 additions & 2 deletions src/export/sessionImdi-edolo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ it("should make separate keys for each topic separated by a comma", () => {
"Incoming"
);
expect("METATRANSCRIPT/Session/MDGroup/Content/Keys/Key[2]").toMatch(
"Fishing"
"fishing"
);
expect("METATRANSCRIPT/Session/MDGroup/Content/Keys/Key[3]").toMatch(
"Poison"
"poison"
);
});

Expand Down
38 changes: 23 additions & 15 deletions src/other/UserSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,38 @@ export class UserSettings {
if (E2E_USER_SETTINGS_STORE_NAME?.length > 0) {
name = E2E_USER_SETTINGS_STORE_NAME;
} else {
// at some point during 2.3 beta, we broke the file name here,
// leaving it named ".json"
// So here we fix it up if we find that.
const brokenPath = Path.join(app.getPath("userData"), ".json");
if (fs.existsSync(brokenPath)) {
const correctPath = Path.join(app.getPath("userData"), name + ".json");
try {
if (!fs.existsSync(correctPath)) {
fs.renameSync(brokenPath, correctPath);
} else {
fs.rmSync(brokenPath); // we have two files, bad and good names. Remove incorrectly named one (note, it could be the more recent, ah well)
if (app.getPath) {
// false in unit tests
// at some point during 2.3 beta, we broke the file name here,
// leaving it named ".json"
// So here we fix it up if we find that.
const brokenPath = Path.join(app.getPath("userData"), ".json");
if (fs.existsSync(brokenPath)) {
const correctPath = Path.join(
app.getPath("userData"),
name + ".json"
);
try {
if (!fs.existsSync(correctPath)) {
fs.renameSync(brokenPath, correctPath);
} else {
fs.rmSync(brokenPath); // we have two files, bad and good names. Remove incorrectly named one (note, it could be the more recent, ah well)
}
} catch (e) {
// ah well
}
} catch (e) {
// ah well
}
}
}
this.store =
process.env.NODE_ENV === "test" || E2E_USER_SETTINGS_STORE_NAME === "none" // like we're running for the first time
process.env == undefined || // unit tests
process.env.NODE_ENV === "test" ||
E2E_USER_SETTINGS_STORE_NAME === "none" // like we're running for the first time
? new FakeStore()
: new Store({
name: name
});
this.sendErrors = process.env.NODE_ENV === "production"; // developer has a menu that can toggle this
this.sendErrors = process.env?.NODE_ENV === "production"; // developer has a menu that can toggle this

this.imdiMode = this.store.get("imdiMode") || false;
this.paradisecMode = this.store.get("paradisecMode") || false;
Expand Down
7 changes: 6 additions & 1 deletion src/vitest.mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { app } from "electron";
import { beforeAll, vi } from "vitest";

vi.mock("@electron/remote", () => ({ exec: vi.fn(), process: vi.fn() })); //See commit msg for info
vi.mock("@electron/remote", () => ({
exec: vi.fn(),
process: vi.fn(),
app: vi.fn()
})); //See commit msg for info
//
// getTestEnvironment: () => ({
// E2E: false,
Expand Down

0 comments on commit 92ed4ef

Please sign in to comment.