import * as readdir from 'recursive-readdir'
import { destPath } from './util/helpers'

const paths = {
  dest: '__tests__/integration/dest',
}

const expectedFiles: {
  [file: string]: string
} = {
  font: destPath('f', 'font.woff2'),
  html: destPath('h.html'),
  image: destPath('i', 'image.jpg'),
  javascript: destPath('j', 'app.js'),
  reactJsx: destPath('j', 'JsApp.js'),
  reactTsx: destPath('j', 'TsApp.js'),
  static: destPath('hello.txt'),
  stylesheet: destPath('s', 'app.css'),
  svg: destPath('sv', 'icons.svg'),
  timplaWebpackStats: destPath('j', 'timpla-webpack-stats.json'),
  typescript: destPath('j', 'ts-app.js'),
}

const builtFiles: string[] = []

describe('build', () => {
  beforeAll(async () => {
    const files = await readdir(paths.dest)
    builtFiles.push(...files)
  })

  it('should copy images', () => {
    expect(builtFiles.includes(expectedFiles.image))
  })
  it('should copy html files', () => {
    expect(builtFiles.includes(expectedFiles.html))
  })
  it('should copy static files', () => {
    expect(builtFiles.includes(expectedFiles.static))
  })
  it('should copy fonts', () => {
    expect(builtFiles.includes(expectedFiles.font))
  })
  it('should bundle svgs', () => {
    expect(builtFiles.includes(expectedFiles.svg))
  })
  it('should bundle stylesheets', () => {
    expect(builtFiles.includes(expectedFiles.stylesheet))
  })
  it('should bundle javascripts', () => {
    expect(builtFiles.includes(expectedFiles.javascript))
    expect(builtFiles.includes(expectedFiles.typescript))
    expect(builtFiles.includes(expectedFiles.reactJsx))
    expect(builtFiles.includes(expectedFiles.reactTsx))
    expect(builtFiles.includes(expectedFiles.timplaWebpackStats))
  })
})
