Skip to content

Commit 1a76449

Browse files
add test suite for "Test basic load function for empty element path pointing to an object where object is also the current working directory"
1 parent 1606654 commit 1a76449

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

test/load.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { DEFAULT_SPEC_CASE_FOLDER } from "./spec_constants";
55
import { expect } from "chai";
66
import fs from "node:fs";
77
import path from "path";
8+
import process from "process";
89

910
export function runBasicLoadTest(
1011
specCaseName: string,
@@ -23,6 +24,8 @@ export function runBasicLoadTest(
2324
expect(toJsonString(result.element)).to.equal(toJsonString(expectedModel));
2425
}
2526

27+
const projectRootDir = process.cwd();
28+
2629
describe("Test basic load function for empty working directory", () => {
2730
it("shall return a YdsResult object where success is false, element is null, and message is a correct error message string, given an empty working directory path", () => {
2831
const result = load("", "");
@@ -184,6 +187,43 @@ describe("Test basic load function for empty element path pointing to an object"
184187
});
185188
});
186189

190+
describe("Test basic load function for empty element path pointing to an object where object is also the current working directory", () => {
191+
afterEach(function () {
192+
process.chdir(projectRootDir);
193+
});
194+
it("shall load object for empty element path", () => {
195+
const specCasePath = toSpecCasePath(
196+
"1.1_object_with_simple_data_types/" + DEFAULT_SPEC_CASE_FOLDER
197+
);
198+
const elementPath = "";
199+
const workingDir = path.join(specCasePath, "model");
200+
process.chdir(workingDir);
201+
const expectedModel = JSON.parse(
202+
fs.readFileSync(path.resolve("../..", "model.json"), "utf8")
203+
);
204+
const result = load(".", elementPath);
205+
expect(result.success).to.equal(true);
206+
expect(result.message).to.equal(elementPath);
207+
expect(toJsonString(result.element)).to.equal(toJsonString(expectedModel));
208+
});
209+
it("shall load object with object of complex data types for empty element path", () => {
210+
const specCasePath = toSpecCasePath(
211+
"1.2.3_object_with_object_of_complex_data_types/" +
212+
DEFAULT_SPEC_CASE_FOLDER
213+
);
214+
const elementPath = "";
215+
const workingDir = path.join(specCasePath, "model");
216+
process.chdir(workingDir);
217+
const expectedModel = JSON.parse(
218+
fs.readFileSync(path.resolve("../..", "model.json"), "utf8")
219+
);
220+
const result = load(".", elementPath);
221+
expect(result.success).to.equal(true);
222+
expect(result.message).to.equal(elementPath);
223+
expect(toJsonString(result.element)).to.equal(toJsonString(expectedModel));
224+
});
225+
});
226+
187227
// see shortToObject in ElementPathType (enum)
188228
describe("Test basic load function for short element path pointing to object", () => {
189229
it("shall load object with simple data types", () => {

0 commit comments

Comments
 (0)