Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 6 additions & 207 deletions packages/state/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { Type as RecsType, Schema } from "@dojoengine/recs";
import { describe, expect, it, beforeEach, vi } from "vitest";
import { Type as RecsType } from "@dojoengine/recs";
import { describe, expect, it } from "vitest";

import { convertValues } from "../utils";

describe("convertValues", () => {
// Mock console.warn to suppress warnings during tests
beforeEach(() => {
vi.spyOn(console, "warn").mockImplementation(() => {});
});
// ... existing tests ...
Comment on lines +1 to +7
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Removed console.warn mock may affect other tests.

Multiple console.warn calls were found across the codebase. Without mocking console.warn, tests that rely on these warnings might produce unexpected outputs or fail.

  • packages/react/src/utils/useMountedState.ts: console.warn(
  • packages/state/src/recs/index.ts: console.warn(
  • packages/state/src/utils/index.ts: console.warn(
  • packages/state/src/utils/index.ts: console.warn(
  • packages/sdk/src/parseEntities.ts: console.warn(\Invalid modelName format: ${modelName}`);`
  • packages/core/src/logger/logger.ts: this.warn = console.warn.bind(console);
  • packages/create-burner/src/manager/burnerManager.ts: // console.warn(error);
🔗 Analysis chain

Verify the impact of removing the console.warn mock.

The beforeEach setup for mocking console.warn has been removed. This change might affect test output if warnings were expected in certain scenarios.

Please run the following script to check for any console.warn calls in the codebase:

If there are any console.warn calls, consider whether they need to be mocked or if the tests should be updated to handle potential warnings.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for console.warn calls in the codebase

# Test: Look for console.warn calls
rg --type typescript 'console\.warn'

Length of output: 73


Script:

#!/bin/bash
# Description: Search for console.warn calls in .ts and .tsx files

rg 'console\.warn' -g '*.ts' -g '*.tsx'

Length of output: 607


describe("huge numbers", () => {
it("should correctly convert huge BigInt values", () => {
Expand All @@ -25,7 +22,7 @@ describe("convertValues", () => {
);
});

it("should correctly convert huge hexadecimal BigInt values", () => {
it("should correctly convert huge BigInt values", () => {
const schema = { hugeNumber: RecsType.BigInt };
const values = {
hugeNumber: {
Expand Down Expand Up @@ -58,7 +55,6 @@ describe("convertValues", () => {
const schema = { hugeArray: RecsType.StringArray };
const values = {
hugeArray: {
type: "array",
value: [
{ value: "12345678901234567890" },
{ value: "98765432109876543210" },
Expand All @@ -71,28 +67,6 @@ describe("convertValues", () => {
98765432109876543210n,
]);
});

it("should handle empty StringArray", () => {
const schema = { tags: RecsType.StringArray };
const values = { tags: { type: "array", value: [] } };
const result = convertValues(schema, values);
expect(result.tags).toEqual([]);
});

it("should correctly convert StringArray with enum types", () => {
const schema = { statuses: RecsType.StringArray };
const values = {
statuses: {
type: "array",
value: [
{ type: "enum", value: { option: "ACTIVE" } },
{ type: "enum", value: { option: "INACTIVE" } },
],
},
};
const result = convertValues(schema, values);
expect(result.statuses).toEqual(["ACTIVE", "INACTIVE"]);
});
});

describe("additional test cases", () => {
Expand Down Expand Up @@ -127,186 +101,11 @@ describe("convertValues", () => {
it("should correctly convert nested schema values", () => {
const schema = { nested: { innerField: RecsType.Number } };
const values = {
nested: {
type: "struct",
value: { innerField: { value: "42" } },
},
};
const result = convertValues(schema, values);

expect(result.nested).toEqual({ innerField: 42 });
});
});

describe("enum type handling", () => {
it("should correctly convert enum values", () => {
const schema = { status: RecsType.T };
const values = {
status: { type: "enum", value: { option: "ACTIVE" } },
};
const result = convertValues(schema, values);
expect(result.status).toBe("ACTIVE");
});
});

describe("BigInt conversion fallback", () => {
it("should fallback to hexadecimal conversion for invalid BigInt strings", () => {
const schema = { invalidBigInt: RecsType.BigInt };
const values = { invalidBigInt: { value: "invalid_bigint" } };
const result = convertValues(schema, values);
// Since "invalid_bigint" is not a valid decimal or hexadecimal BigInt, expect undefined.
expect(result.invalidBigInt).toBeUndefined();
});
});

describe("array of structs", () => {
it("should correctly convert array of structs", () => {
const schema = {
users: [
{
name: RecsType.String,
age: RecsType.Number,
},
],
};
const values = {
users: {
type: "array",
value: [
{
type: "struct",
value: {
name: { value: "Alice" },
age: { value: "30" },
},
},
{
type: "struct",
value: {
name: { value: "Bob" },
age: { value: "25" },
},
},
],
},
nested: { value: { innerField: { value: "42" } } },
};
const result = convertValues(schema as any, values);
expect(result.users).toEqual([
{ name: "Alice", age: 30 },
{ name: "Bob", age: 25 },
]);
});
});

describe("default case handling", () => {
it("should assign value directly for unhandled schema types", () => {
const schema = { miscellaneous: RecsType.T };
const values = { miscellaneous: { value: { random: "data" } } };
const result = convertValues(schema, values);
expect(result.miscellaneous).toEqual({ random: "data" });
});

it("should handle struct with Map as value", () => {
const schema = {
config: {
settingA: RecsType.String,
settingB: RecsType.Number,
},
};
const values = {
config: {
type: "struct",
value: new Map([
["settingA", { value: "Enabled" }],
["settingB", { value: "100" }],
]),
},
};
const result = convertValues(schema, values);
expect(result.config).toEqual({
settingA: "Enabled",
settingB: 100,
});
});

it("should handle nested arrays of structs", () => {
const schema = {
departments: [
{
name: RecsType.String,
employees: [
{
name: RecsType.String,
role: RecsType.String,
},
],
},
],
};
const values = {
departments: {
type: "array",
value: [
{
type: "struct",
value: {
name: { value: "Engineering" },
employees: {
type: "array",
value: [
{
type: "struct",
value: {
name: { value: "Alice" },
role: { value: "Developer" },
},
},
{
type: "struct",
value: {
name: { value: "Bob" },
role: { value: "Designer" },
},
},
],
},
},
},
{
type: "struct",
value: {
name: { value: "Marketing" },
employees: {
type: "array",
value: [
{
type: "struct",
value: {
name: { value: "Charlie" },
role: { value: "Manager" },
},
},
],
},
},
},
],
},
};
const result = convertValues(schema as any, values);
expect(result.departments).toEqual([
{
name: "Engineering",
employees: [
{ name: "Alice", role: "Developer" },
{ name: "Bob", role: "Designer" },
],
},
{
name: "Marketing",
employees: [{ name: "Charlie", role: "Manager" }],
},
]);
expect(result.nested).toEqual({ innerField: { value: "42" } });
});
});
});
Loading