Class: MockIniFile<T>
Mock of the X-Ray engine ini_file for jest/node.
The mock stores sections in plain objects. Tests can pass data directly, pre-register data for a path, or configure a base config directory for loading real .ltx or .ini files. Unknown paths resolve to an empty store when no base directory is configured.
Remarks
This is a focused test helper, not a full engine parser. It does not implement section inheritance or #include expansion beyond what the ini package parses from a single file.
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends TMockIniData | TMockIniData |
Implements
ini_file
Constructors
Constructor
new MockIniFile<T>(
iniPath: string,
data?: T,
content?: string): MockIniFile<T>;Create an INI mock from direct data, registered data, or a configured config directory.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
iniPath | string | undefined | Config path returned by fname. |
data? | T | undefined | Optional pre-parsed section data. |
content? | string | "" | Optional original source content. |
Returns
MockIniFile<T>
Methods
asMock()
asMock(): ini_file;Cast this mock to the engine ini_file type.
Returns
ini_file
create()
static create<T>(
iniPath: string,
data?: T,
content?: string): MockIniFile<T>;Create a strongly typed mock instance.
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends TMockIniData | TMockIniData |
Parameters
| Parameter | Type | Description |
|---|---|---|
iniPath | string | Config path returned by fname. |
data? | T | Optional pre-parsed section data. |
content? | string | Optional original source content. |
Returns
MockIniFile<T>
Mock instance with access to jest spies and stored data.
mock()
static mock(
iniPath: string,
data?: TMockIniData,
content?: string): ini_file;Create an engine-typed ini_file mock.
Parameters
| Parameter | Type | Description |
|---|---|---|
iniPath | string | Config path returned by fname. |
data? | TMockIniData | Optional pre-parsed section data. |
content? | string | Optional original source content. |
Returns
ini_file
Mock typed as the engine ini_file.
register()
static register(iniPath: string, data: TMockIniData): void;Register pre-parsed section data for later construction by path.
Parameters
| Parameter | Type | Description |
|---|---|---|
iniPath | string | Config path to match in the constructor. |
data | TMockIniData | Parsed section data to reuse. |
Returns
void
registerIni()
static registerIni(ini: ini_file): void;Register an existing mock instance by its fname value.
Parameters
| Parameter | Type | Description |
|---|---|---|
ini | ini_file | Engine-typed mock returned by MockIniFile.mock. |
Returns
void
reset()
static reset(): void;Reset injected configuration and registered data.
Call this between suites when tests mutate the shared registry.
Returns
void
setup()
static setup(options: {
configsDir?: string | null;
files?: Record<string, TMockIniData>;
}): void;Configure the base directory used to read real .ltx or .ini files for unregistered paths, and optionally inject the registry object holding pre-registered data.
The consumer (engine) passes its FILES_MOCKS object here by reference, so paths registered via MockIniFile.register — or mutated directly on that object by tests — are seen by the mock.
Parameters
| Parameter | Type |
|---|---|
options | { configsDir?: string | null; files?: Record<string, TMockIniData>; } |
options.configsDir? | string | null |
options.files? | Record<string, TMockIniData> |
Returns
void
Properties
content
content: string;data
data: T;fname
fname: Mock<() => string>;Get file name and path of ini file.
Example
`f:\applications\steam\steamapps\common\stalker call of pripyat\gamedata\configs\misc\task_manager.ltx`Returns
Full path to ini file.
Implementation of
ini_file.fnameline_count
line_count: Mock<(section: string) => number>;Remarks
Missing sections are an engine assertion path. The recoverable branch returns 0.
Param
section
Target section to check lines count.
Returns
Count of lines for provided section.
Implementation of
ini_file.line_countline_exist
line_exist: Mock<(section: string, param: string) => boolean>;Check if line exists in the file by section and field.
Param
section
Target section to check.
Param
field
Section field to check.
Returns
Whether line exists.
Implementation of
ini_file.line_existpath
path: string;r_bool
r_bool: Mock<(section: string, field: string) => boolean>;Read a boolean value.
Param
section
Section name.
Param
field
Field name.
Returns
Parsed boolean value.
Implementation of
ini_file.r_boolr_clsid
r_clsid: Mock<(section: string, field: string) => any>;Read a class identifier value.
Param
section
Section name.
Param
field
Field name.
Returns
Parsed class identifier.
Implementation of
ini_file.r_clsidr_float
r_float: Mock<(section: string, field: string) => number>;Read a floating-point value.
Throws
If the section or field does not exist.
Param
section
Section name.
Param
field
Field name.
Returns
Parsed number.
Implementation of
ini_file.r_floatr_line
r_line: MockedFunction<<T, P>(section: string, line_number: number, key: string, value: string) => LuaMultiReturn<[boolean, T, P]>>;Read text line from ini config file.
Remarks
Returns false for an out-of-range line index. A missing section is a hard engine error.
Throws
If the section does not exist.
Param
section
Section name.
Param
line_number
Zero-based line index inside the section.
Param
key
Placeholder for Lua out parameter.
Param
value
Placeholder for Lua out parameter.
Returns
Success flag, key, and value.
Implementation of
ini_file.r_liner_s32
r_s32: Mock<(section: string, field: string) => any>;Read a signed 32-bit integer.
Throws
If the section or field does not exist.
Param
section
Section name.
Param
field
Field name.
Returns
Parsed integer.
Implementation of
ini_file.r_s32r_string
r_string: Mock<(section: string, field: string) => any>;Throws
If the section or field does not exist.
Param
section
Ini file section.
Param
field
Ini section field.
Returns
Raw string from ltx file without spaces in it.
Implementation of
ini_file.r_stringr_string_wb
r_string_wb: Mock<(section: string, field: string) => string>;Remarks
Reads a string with blanks preserved by the engine parser.
Param
section
Ini file section.
Param
field
Ini section field.
Returns
If quoted, parsed string data inside quotes including spaces, else is same data as with r_string.
Implementation of
ini_file.r_string_wbr_string_wq
r_string_wq: Mock<(section: string, field: string) => string>;Read a quoted string value.
Remarks
Uses the same engine reader as r_string_wb; quoted values may keep spaces.
Param
section
Section name.
Param
field
Field name.
Returns
Parsed string.
Implementation of
ini_file.r_string_wqr_token
r_token: Mock<(section: string, field: string) => any>;Read a token value using a token list.
Param
section
Section name.
Param
field
Field name.
Param
list
Token list used for lookup.
Returns
Token id.
Implementation of
ini_file.r_tokenr_u32
r_u32: Mock<(section: string, field: string) => any>;Read an unsigned 32-bit integer.
Throws
If the section or field does not exist.
Param
section
Section name.
Param
field
Field name.
Returns
Parsed integer.
Implementation of
ini_file.r_u32r_vector
r_vector: Mock<(section: string, field: string) => vector>;Read a 3D vector.
Throws
If the section or field does not exist.
Param
section
Section name.
Param
field
Field name.
Returns
Parsed vector.
Implementation of
ini_file.r_vectorremove_line
remove_line: Mock<(section: string, field: string) => void>;Remove ini file section field.
Param
section
Target section to modify.
Param
field
Target section field to remove.
Implementation of
ini_file.remove_linesave_as
save_as: Mock<() => boolean>;Save this ini file to a path.
Throws
If path is missing.
Param
path
Destination path.
Returns
Whether saving succeeded.
Implementation of
ini_file.save_assave_at_end
save_at_end: Mock<UnknownFunction>;Adjust saving on file closing/destructor calls.
Remarks
Intended for script-created or script-owned ini files. Be careful using it on engine-owned singletons returned by game_ini or system_ini.
Param
should_save
Whether ini file should be saved when destructor is called.
Implementation of
ini_file.save_at_endsection_count
section_count: Mock<() => number>;Returns
Number of sections in this file.
Implementation of
ini_file.section_countsection_exist
section_exist: Mock<(section: string) => boolean>;Check whether a section exists.
Param
section
Section name.
Returns
Whether the section exists.
Implementation of
ini_file.section_existsection_for_each
section_for_each: Mock<(cb: (section: string) => void) => void>;Iterate over ini file sections. Calls provided callback for each ini section in file.
Param
cb
Callback to call on each ini file section, where name is section name.
Implementation of
ini_file.section_for_eachset_override_names
set_override_names: Mock<UnknownFunction>;Enable or disable section override name handling.
Since
OpenXRay 2017-08-15, 565b39e5
Param
override
Whether override names should be used.
Implementation of
ini_file.set_override_namesset_readonly
set_readonly: Mock<UnknownFunction>;Switch the file into readonly or writable mode.
Param
is_readonly
Whether writes should be disabled.
Implementation of
ini_file.set_readonlyw_bool
w_bool: Mock<(section: string, field: string, value: boolean) => void>;Write a boolean value.
Param
section
Section name.
Param
field
Field name.
Param
value
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_boolw_color
w_color: Mock<(section: string, field: string, value: number) => void>;Write a packed color value.
Param
section
Section name.
Param
field
Field name.
Param
color
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_colorw_fcolor
w_fcolor: Mock<(section: string, field: string, value: unknown) => void>;Write a floating-point color value.
Param
section
Section name.
Param
field
Field name.
Param
color
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_fcolorw_float
w_float: Mock<(section: string, field: string, value: number) => void>;Write a floating-point number.
Param
section
Section name.
Param
field
Field name.
Param
value
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_floatw_fvector2
w_fvector2: Mock<(section: string, field: string, value: vector2) => void>;Write a 2D vector value.
Since
OpenXRay 2017-08-15, 565b39e5
Param
section
Section name.
Param
field
Field name.
Param
vector
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_fvector2w_fvector3
w_fvector3: Mock<(section: string, field: string, value: vector) => void>;Write a 3D vector value.
Since
OpenXRay 2017-08-15, 565b39e5
Param
section
Section name.
Param
field
Field name.
Param
vector
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_fvector3w_fvector4
w_fvector4: Mock<(section: string, field: string, value: never) => void>;Write a 4D vector value.
Since
OpenXRay 2017-08-15, 565b39e5
Param
section
Section name.
Param
field
Field name.
Param
vector
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_fvector4w_s16
w_s16: Mock<(section: string, field: string, value: number) => void>;Write a signed 16-bit integer.
Param
section
Section name.
Param
field
Field name.
Param
value
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_s16w_s32
w_s32: Mock<(section: string, field: string, value: number) => void>;Write a signed 32-bit integer.
Param
section
Section name.
Param
field
Field name.
Param
value
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_s32w_s64
w_s64: Mock<(section: string, field: string, value: number) => void>;Write a signed 64-bit integer.
Param
section
Section name.
Param
field
Field name.
Param
value
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_s64w_s8
w_s8: Mock<(section: string, field: string, value: number) => void>;Write a signed 8-bit integer.
Param
section
Section name.
Param
field
Field name.
Param
value
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_s8w_string
w_string: Mock<(section: string, field: string, value: string) => void>;Write a string value.
Param
section
Section name.
Param
field
Field name.
Param
value
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_stringw_u16
w_u16: Mock<(section: string, field: string, value: number) => void>;Write an unsigned 16-bit integer.
Param
section
Section name.
Param
field
Field name.
Param
value
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_u16w_u32
w_u32: Mock<(section: string, field: string, value: number) => void>;Write an unsigned 32-bit integer.
Param
section
Section name.
Param
field
Field name.
Param
value
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_u32w_u64
w_u64: Mock<(section: string, field: string, value: number) => void>;Write an unsigned 64-bit integer.
Param
section
Section name.
Param
field
Field name.
Param
value
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_u64w_u8
w_u8: Mock<(section: string, field: string, value: number) => void>;Write an unsigned 8-bit integer.
Param
section
Section name.
Param
field
Field name.
Param
value
Value to write.
Param
comment
Optional line comment.
Implementation of
ini_file.w_u8