<commit_before>import { HubServerConfig } from '../../interfaces';
import Mocha from 'mocha';
import { HubServer } from '../../main';
import CardCache from '../../services/card-cache';
import { Registry } from '@cardstack/di';
import { TestCardCacheConfig, ProjectTestRealm, resolveCard } from './cards';
import supertest from 'supertest';
import { INSECURE_CONTEXT } from '../../services/card-service';

export function setupServer(
  mochaContext: Mocha.Suite,
  config: {
    registryCallback?: HubServerConfig['registryCallback'];
    testRealm?: string;
  } = {}
) {
  let server: HubServer, cardCache: CardCache, cardCacheConfig: TestCardCacheConfig;

  mochaContext.beforeEach(async function () {
    let registryCallback = function (registry: Registry) {
      if (process.env.COMPILER) {
        registry.register('card-cache-config', TestCardCacheConfig);
      }

      config.registryCallback && config.registryCallback(registry);
    };

    server = await HubServer.create({ registryCallback });

    if (process.env.COMPILER) {
      cardCache = await server.container.lookup('card-cache');
      cardCacheConfig = (await server.container.lookup('card-cache-config')) as TestCardCacheConfig;
    }

    if (config.testRealm) {
      return (await server.container.lookup('realm-manager')).createRealm({ url: config.testRealm }, ProjectTestRealm);
    }
  });

  mochaContext.afterEach(async function () {
    await server.teardown();
  });

  return {
    getContainer() {
      return server.container;<commit_msg>Route tests use real FSRealm instead of test realm<commit_after>import { HubServerConfig } from '../../interfaces';
import Mocha from 'mocha';
import { HubServer } from '../../main';
import CardCache from '../../services/card-cache';
import { Registry } from '@cardstack/di';
import { TestCardCacheConfig, resolveCard } from './cards';
import supertest from 'supertest';
import { INSECURE_CONTEXT } from '../../services/card-service';

import tmp from 'tmp';
tmp.setGracefulCleanup();

export function setupServer(
  mochaContext: Mocha.Suite,
  config: {
    registryCallback?: HubServerConfig['registryCallback'];
    testRealm?: string;
  } = {}
) {
  let server: HubServer, cardCache: CardCache, cardCacheConfig: TestCardCacheConfig;

  mochaContext.beforeEach(async function () {
    let registryCallback = function (registry: Registry) {
      if (process.env.COMPILER) {
        registry.register('card-cache-config', TestCardCacheConfig);
      }

      config.registryCallback && config.registryCallback(registry);
    };

    server = await HubServer.create({ registryCallback });

    if (process.env.COMPILER) {
      cardCache = await server.container.lookup('card-cache');
      cardCacheConfig = (await server.container.lookup('card-cache-config')) as TestCardCacheConfig;
    }

    if (config.testRealm) {
      return (await server.container.lookup('realm-manager')).createRealm({
        url: config.testRealm,
        directory: tmp.dirSync().name,
      });
    }
  });

  mochaContext.afterEach(async function () {
    await server.teardown();
  });

  return {
    getContainer() {
      return server.container;
{'fraction_non_alphanumeric': 0.13712480252764614, 'fraction_numerical': 0.0, 'mean_word_length': 3.782477341389728, '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': '120104', 'n_tokens_mistral': 902, 'n_tokens_neox': 893, 'n_words': 200}