import { render as render$1, settled } from '@ember/test-helpers';
import * as QUnit from 'qunit';
import { isPrivateStore } from '@warp-drive/core/store/-private';
import { macroCondition, getGlobalConfig } from '@embroider/macros';

async function render(template) {
  await render$1(template);
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
  const owner = QUnit.config.current.testEnvironment.owner;
  const store = isPrivateStore(owner.lookup('service:store'));
  const pending = store._getAllPending();

  // this should only be necessary in production tests
  // where @ember/test-waiters is deactivated :()
  if (macroCondition(getGlobalConfig().WarpDrive.env.PRODUCTION)) {
    macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
      if (!test) {
        throw new Error(`No pending requests exist in this test, use \`import { render } from '@ember/test-helpers';\``);
      }
    })(pending?.length) : {};
    await pending;
    await settled();
  }
}

export { render };
