<commit_before>/* eslint-env jest */

const { exec } = require('child_process')
const request = require('supertest')
let app

// start a mongo instance loaded with test data using docker
beforeAll(async () => {
  await exec('docker run --name scraper_test_db -d --rm -p 27017:27017 mongo')
  await exec('docker cp dump/ scraper_test_db:/dump')
  await exec('docker exec scraper_test_db mongorestore /dump')
  app = await require('../app')
  await twoSeconds()
})

afterAll(done => exec('docker kill scraper_test_db', done))

describe('courses endpoint', () => {
  test('/courses succeeds', async () => {
    const response = await request(app).get('/courses')
    expect(response.type).toBe('application/json')
    expect(response.statusCode).toBe(200)
  })

  test('/courses returns an Array', async () => {
    const response = await request(app).get('/courses')
    expect(Array.isArray(response.body)).toBeTruthy()
  })
})

function twoSeconds () {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve()
    }, 2000)
  })
}
<commit_msg>Test db should have data now<commit_after>/* eslint-env jest */

const util = require('util')
const exec = util.promisify(require('child_process').exec)
const request = require('supertest')
let app

// start a mongo instance loaded with test data using docker
beforeAll(async () => {
  await exec('docker run --name scraper_test_db -d --rm -p 27017:27017 mongo')
  await exec('docker cp __tests__/dump/ scraper_test_db:/dump')
  await exec('docker exec scraper_test_db mongorestore /dump')
  app = require('../app')
  await twoSeconds()
})

afterAll(done => exec('docker kill scraper_test_db', done))

describe('courses endpoint', () => {
  test('/courses succeeds', async () => {
    const response = await request(app).get('/courses')
    expect(response.type).toBe('application/json')
    expect(response.statusCode).toBe(200)
  })

  test('/courses returns an Array', async () => {
    const response = await request(app).get('/courses')
    expect(Array.isArray(response.body)).toBeTruthy()
  })
})

function twoSeconds () {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve()
    }, 2000)
  })
}

{'fraction_non_alphanumeric': 0.15955983493810177, 'fraction_numerical': 0.015589179275561669, 'mean_word_length': 4.074418604651163, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '6304382', 'n_tokens_mistral': 711, 'n_tokens_neox': 678, 'n_words': 171}