Skip to content

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 ParameterDefault type
T extends TMockIniDataTMockIniData

Implements

  • ini_file

Constructors

Constructor

ts
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

ParameterTypeDefault valueDescription
iniPathstringundefinedConfig path returned by fname.
data?TundefinedOptional pre-parsed section data.
content?string""Optional original source content.

Returns

MockIniFile<T>

Methods

asMock()

ts
asMock(): ini_file;

Cast this mock to the engine ini_file type.

Returns

ini_file


create()

ts
static create<T>(
   iniPath: string, 
   data?: T, 
content?: string): MockIniFile<T>;

Create a strongly typed mock instance.

Type Parameters

Type ParameterDefault type
T extends TMockIniDataTMockIniData

Parameters

ParameterTypeDescription
iniPathstringConfig path returned by fname.
data?TOptional pre-parsed section data.
content?stringOptional original source content.

Returns

MockIniFile<T>

Mock instance with access to jest spies and stored data.


mock()

ts
static mock(
   iniPath: string, 
   data?: TMockIniData, 
   content?: string): ini_file;

Create an engine-typed ini_file mock.

Parameters

ParameterTypeDescription
iniPathstringConfig path returned by fname.
data?TMockIniDataOptional pre-parsed section data.
content?stringOptional original source content.

Returns

ini_file

Mock typed as the engine ini_file.


register()

ts
static register(iniPath: string, data: TMockIniData): void;

Register pre-parsed section data for later construction by path.

Parameters

ParameterTypeDescription
iniPathstringConfig path to match in the constructor.
dataTMockIniDataParsed section data to reuse.

Returns

void


registerIni()

ts
static registerIni(ini: ini_file): void;

Register an existing mock instance by its fname value.

Parameters

ParameterTypeDescription
iniini_fileEngine-typed mock returned by MockIniFile.mock.

Returns

void


reset()

ts
static reset(): void;

Reset injected configuration and registered data.

Call this between suites when tests mutate the shared registry.

Returns

void


setup()

ts
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

ParameterType
options{ configsDir?: string | null; files?: Record<string, TMockIniData>; }
options.configsDir?string | null
options.files?Record<string, TMockIniData>

Returns

void

Properties

content

ts
content: string;

data

ts
data: T;

fname

ts
fname: Mock<() => string>;

Get file name and path of ini file.

Example

ts
`f:\applications\steam\steamapps\common\stalker call of pripyat\gamedata\configs\misc\task_manager.ltx`

Returns

Full path to ini file.

Implementation of

ts
ini_file.fname

line_count

ts
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

ts
ini_file.line_count

line_exist

ts
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

ts
ini_file.line_exist

path

ts
path: string;

r_bool

ts
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

ts
ini_file.r_bool

r_clsid

ts
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

ts
ini_file.r_clsid

r_float

ts
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

ts
ini_file.r_float

r_line

ts
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

ts
ini_file.r_line

r_s32

ts
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

ts
ini_file.r_s32

r_string

ts
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

ts
ini_file.r_string

r_string_wb

ts
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

ts
ini_file.r_string_wb

r_string_wq

ts
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

ts
ini_file.r_string_wq

r_token

ts
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

ts
ini_file.r_token

r_u32

ts
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

ts
ini_file.r_u32

r_vector

ts
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

ts
ini_file.r_vector

remove_line

ts
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

ts
ini_file.remove_line

save_as

ts
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

ts
ini_file.save_as

save_at_end

ts
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

ts
ini_file.save_at_end

section_count

ts
section_count: Mock<() => number>;

Returns

Number of sections in this file.

Implementation of

ts
ini_file.section_count

section_exist

ts
section_exist: Mock<(section: string) => boolean>;

Check whether a section exists.

Param

section

Section name.

Returns

Whether the section exists.

Implementation of

ts
ini_file.section_exist

section_for_each

ts
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

ts
ini_file.section_for_each

set_override_names

ts
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

ts
ini_file.set_override_names

set_readonly

ts
set_readonly: Mock<UnknownFunction>;

Switch the file into readonly or writable mode.

Param

is_readonly

Whether writes should be disabled.

Implementation of

ts
ini_file.set_readonly

w_bool

ts
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

ts
ini_file.w_bool

w_color

ts
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

ts
ini_file.w_color

w_fcolor

ts
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

ts
ini_file.w_fcolor

w_float

ts
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

ts
ini_file.w_float

w_fvector2

ts
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

ts
ini_file.w_fvector2

w_fvector3

ts
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

ts
ini_file.w_fvector3

w_fvector4

ts
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

ts
ini_file.w_fvector4

w_s16

ts
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

ts
ini_file.w_s16

w_s32

ts
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

ts
ini_file.w_s32

w_s64

ts
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

ts
ini_file.w_s64

w_s8

ts
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

ts
ini_file.w_s8

w_string

ts
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

ts
ini_file.w_string

w_u16

ts
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

ts
ini_file.w_u16

w_u32

ts
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

ts
ini_file.w_u32

w_u64

ts
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

ts
ini_file.w_u64

w_u8

ts
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

ts
ini_file.w_u8