spyOnCompiler = (implementation) => {
  const actualFn = implementation.initAsyncCompiler.bind(implementation);

  const initSpy = jest
    .spyOn(implementation, "initAsyncCompiler")
    .mockImplementation(async () => {
      const compiler = await actualFn();
      // eslint-disable-next-line no-use-before-define
      spies.compileStringSpy = jest.spyOn(compiler, "compileStringAsync");
      return compiler;
    });

  const spies = {
    initSpy,
    mockClear() {
      if (this.compileStringSpy) {
        this.compileStringSpy.mockClear();
      }
    },
    mockRestore() {
      initSpy.mockRestore();
      delete this.compileStringSpy;
    },
  };

  return spies;
}
Helper to create spy functions for the modern Compiler API