Warning: Docs are currently under development, join us at discord.
Logo

Testing: The Keystone of Digital Construction

In building, thorough testing and inspections are non-negotiable, ensuring every part of the structure meets exacting standards. Vixeny embeds this principle deeply within its framework, offering a comprehensive testing suite that simulates various scenarios, ensuring every component functions as intended.

Case Study: Simulating Conditions

Imagine a feature in our digital architecture that responds to environmental changes, much like a smart home system adjusting to weather variations. Vixeny enables us to test these dynamic responses, ensuring they act precisely under varied simulated conditions.

Scenario: Predicting Outcomes

Our focus falls on a /random feature, designed to yield different outcomes based on a random number generator. This setup mirrors real-life scenarios where outcomes pivot on user interactions or external data.

const routes = wrap(options)()
  .stdPetition({
    path: "/random",
    f: (c) =>
      c.randomNumber > .5
        ? c.randomNumber > .99 ? "winner" : "almost"
        : "try again",
  });

Crafting the Tests

To ensure our feature behaves predictably across a range of states, we manipulate the random number generator, crafting scenarios to test the anticipated outcomes.

test("/random", async () => {
  // Testing for the "try again" outcome.
  expect(
    await routes
      .handleRequest("/random")({
        options: {
          setRandomNumber: .25,
        },
      })(new Request("/random"))
      .then((res) => res.text()),
  ).toStrictEqual("try again");

  // Testing for the "almost" outcome.
  expect(
    await routes
      .handleRequest("/random")({
        options: {
          setRandomNumber: .51,
        },
      })(new Request("/random"))
      .then((res) => res.text()),
  ).toStrictEqual("almost");

  // Testing for the "winner" outcome.
  expect(
    await routes
      .handleRequest("/random")({
        options: {
          setRandomNumber: .999,
        },
      })(new Request("/random"))
      .then((res) => res.text()),
  ).toStrictEqual("winner");
});

Refining the Process with Mocked Resolves

For a feature reliant on external APIs, like fetching current weather data, we aim to test without real-time data fetches. Here, we introduce a mocked synchronous function to simulate the data fetching:

// Original asynchronous resolve function for fetching weather data
const routes = wrap(options)()
  .stdPetition({
    path: "/weather",
    resolve: {
      currentWeather: {
        async f: () => {
          return await fetch("https://api.weather.com/current").then(res => res.json());
        }
      }
    },
    f: (c) => {
      return c.resolve.currentWeather.temperature > 75 ? "It's warm outside" : "It's cool outside";
    },
  });

// Mocking the resolve function for controlled testing
const mockedWeatherResolve = () => ({ temperature: 80 });

// Injecting the mocked resolve using handleRequest
const mockRoutes = routes.handleRequest("/weather")({
  resolve: {
    currentWeather: mockedWeatherResolve
  }
});

// Verifying behavior with the mocked data
test("/weather", async () => {
  expect(
    await mockRoutes(new Request("/weather"))
      .then(res => res.text())
  ).toStrictEqual("It's warm outside");
});

The Virtues of Mocked Testing

This approach grants us unparalleled control over the testing environment, mirroring the precision and adaptability seen in the most advanced construction methodologies. It allows for:

  • Precision and Predictability: Creating a controlled environment that simulates specific conditions, ensuring components react as expected.
  • Efficiency: Streamlining the testing process by removing dependencies on external data sources.
  • Confidence: Providing assurance in the reliability and functionality of the digital structure, much like the final inspection before a home’s completion.

Conclusion: Building Digital Foundations with Assurance

Just as thorough inspections ensure a home is ready for habitation, Vixeny’s testing capabilities, particularly the use of mocked resolves, ensure that every digital component is built to perfection. This meticulous approach to testing empowers developers to construct with confidence, knowing every part of the application is crafted to meet and exceed expectations, ensuring a robust, functional, and adaptable digital experience. Through Resolve, Branch, and precise testing, Vixeny lays the groundwork for web applications that stand the test of time, embodying the principles of a well-constructed home.

Thank you for your time.