<commit_before>// AVANT
jest.mock("fs-jetpack");

import { RevealServer } from '../../RevealServer'
import Logger , {LogLevel} from '../../Logger';
import {defaultConfiguration} from "../../Configuration"
import request from "supertest"


//jest.mock('./Logger');

let inExport = false
const getRootDir = () => "getRoot"
const getSlides = () => []
const getConfiguration= () => defaultConfiguration
const extensionPath = "";
const isInExport= () => inExport
const getExportPath=jest.fn();

const logger =  new Logger(s => s,LogLevel.Error )


const createServer = () =>new RevealServer(logger,getRootDir, getSlides,getConfiguration, extensionPath, isInExport,getExportPath  )

test('Default state', () => {

  const server = createServer()
  expect(server.isListening).toBeFalsy()
  expect(server.uri).toBe("")
})

test('Start should return uri and trigger onDidStart', () => {

  const server = createServer()
  let receivedUri = ""
  server.onDidStart(uri => receivedUri = uri)
  const uri = server.start()
  expect(receivedUri).toEqual(uri)
})

test('Stop should trigger onDidStop only when server is listening', () => {

  const onDidStopLock = jest.fn()
  const server = createServer()
  server.onDidStop( onDidStopLock )
  server.stop()

  expect(onDidStopLock).toHaveBeenCalledTimes(0)
})

test('Stop should trigger onDidStop', () => {

  const onDidStopLock = jest.fn()
  const server = createServer()
  server.onDidStop( onDidStopLock )
  server.start()
  server.stop()

  expect(onDidStopLock).toHaveBeenCalledTimes(1)
})


test('Dispose should trigger onDidDispose and Stop', () => {

  const onDidStopMock = jest.fn()
  const onDidDisposeMock = jest.fn()
  const server = createServer()
  server.onDidStop( onDidStopMock )
  server.onDidDispose( onDidDisposeMock)
  server.start()
  server.dispose()

  expect(onDidStopMock).toHaveBeenCalledTimes(1)
  expect(onDidDisposeMock).toHaveBeenCalledTimes(1)
})

test('Request root', async () => {

  const server = createServer()
  //server.start()

  const response = await request(server.app.callback()).get('/')
  expect(response.status).toEqual(200);
  expect(response.type).toEqual('text/html');
  expect(response.text).toMatchSnapshot()
})


test('Request with export', async () => {
 
  const server = createServer()
  //server.start()<commit_msg>Diepose server in unit test<commit_after>// AVANT
jest.mock("fs-jetpack");


import { RevealServer } from '../../RevealServer'
import Logger , {LogLevel} from '../../Logger';
import {defaultConfiguration} from "../../Configuration"
import request from "supertest"


//jest.mock('./Logger');

let inExport = false
const getRootDir = () => "getRoot"
const getSlides = () => []
const getConfiguration= () => defaultConfiguration
const extensionPath = "";
const isInExport= () => inExport
const getExportPath=jest.fn();

const logger =  new Logger(s => s,LogLevel.Error )



const server = new RevealServer(logger,getRootDir, getSlides,getConfiguration, extensionPath, isInExport,getExportPath  )


afterEach(() => {
  server.dispose()
});

test('Default state', () => {
  expect(server.isListening).toBeFalsy()
  expect(server.uri).toBe("")
})

test('Start should return uri and trigger onDidStart', () => {

  let receivedUri = ""
  server.onDidStart(uri => receivedUri = uri)
  const uri = server.start()
  expect(receivedUri).toEqual(uri)
})

test('Stop should trigger onDidStop only when server is listening', () => {

  const onDidStopLock = jest.fn()
  server.onDidStop( onDidStopLock )
  server.stop()

  expect(onDidStopLock).toHaveBeenCalledTimes(0)
})

test('Stop should trigger onDidStop', () => {

  const onDidStopLock = jest.fn()
  server.onDidStop( onDidStopLock )
  server.start()
  server.stop()

  expect(onDidStopLock).toHaveBeenCalledTimes(1)
})


test('Dispose should trigger onDidDispose and Stop', () => {

  const onDidStopMock = jest.fn()
  const onDidDisposeMock = jest.fn()
  server.onDidStop( onDidStopMock )
  server.onDidDispose( onDidDisposeMock)
  server.start()
  server.dispose()

  expect(onDidStopMock).toHaveBeenCalledTimes(1)
  expect(onDidDisposeMock).toHaveBeenCalledTimes(1)
})

test('Request root', async () => {


  const response = await request(server.app.callback()).get('/')
  expect(response.status).toEqual(200);
  expect(response.type).toEqual('text/html');
  expect(response.text).toMatchSnapshot()
})


test('Request with export', async () => {
 
{'fraction_non_alphanumeric': 0.15232690124858117, 'fraction_numerical': 0.003178206583427923, 'mean_word_length': 4.835761589403973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '3939905', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1375, 'n_words': 294}