<commit_before>import { getDebugFunction, setDebugFunction } from '@ember/debug';

// @ts-ignore
import EmberDevTestHelperAssert from './index';

export interface Assertion {
  reset(): void;
  inject(): void;
  assert(): void;
  restore(): void;
}

export default function setupQUnit({ runningProdBuild }: { runningProdBuild: boolean }) {
  let assertion = new EmberDevTestHelperAssert({
    runningProdBuild,
    getDebugFunction,
    setDebugFunction,
  });

  let originalModule = QUnit.module;

  QUnit.module = function(name: string, _options: any) {
    let options = _options || {};
    let originalSetup = options.setup || options.beforeEach || function() {};
    let originalTeardown = options.teardown || options.afterEach || function() {};

    delete options.setup;
    delete options.teardown;

    options.beforeEach = function() {
      assertion.reset();
      assertion.inject();

      return originalSetup.apply(this, arguments);
    };

    options.afterEach = function() {
      let result = originalTeardown.apply(this, arguments);

      assertion.assert();
      assertion.restore();

      return result;
    };

    return originalModule(name, options);
  };
}<commit_msg>internal-test-helpers: Add nested module API support to `setupQUnit()` function<commit_after>import { getDebugFunction, setDebugFunction } from '@ember/debug';

// @ts-ignore
import EmberDevTestHelperAssert from './index';

export interface Assertion {
  reset(): void;
  inject(): void;
  assert(): void;
  restore(): void;
}

export default function setupQUnit({ runningProdBuild }: { runningProdBuild: boolean }) {
  let assertion = new EmberDevTestHelperAssert({
    runningProdBuild,
    getDebugFunction,
    setDebugFunction,
  });

  let originalModule = QUnit.module;

  QUnit.module = function(name: string, _options: any) {
    if (typeof _options === 'function') {
      let callback = _options;

      return originalModule(name, function(hooks) {
        hooks.beforeEach(function() {
          assertion.reset();
          assertion.inject();
        });

        hooks.afterEach(function() {
          assertion.assert();
          assertion.restore();
        });

        callback(hooks);
      });
    }

    let options = _options || {};
    let originalSetup = options.setup || options.beforeEach || function() {};
    let originalTeardown = options.teardown || options.afterEach || function() {};

    delete options.setup;
    delete options.teardown;

    options.beforeEach = function() {
      assertion.reset();
      assertion.inject();

      return originalSetup.apply(this, arguments);
    };

    options.afterEach = function() {
      let result = originalTeardown.apply(this, arguments);

      assertion.assert();
      assertion.restore();

      return result;
    };

    return originalModule(name, options);
  };
}
{'fraction_non_alphanumeric': 0.1265334735366281, 'fraction_numerical': 0.0, 'mean_word_length': 3.2470238095238093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '12807', 'n_tokens_mistral': 806, 'n_tokens_neox': 784, 'n_words': 185}