1 |
|
2 |
|
3 | import 'babel-polyfill'
|
4 | import path from 'path'
|
5 | import readdir from 'readdir-enhanced'
|
6 |
|
7 | import { cloneFixtures } from './helpers'
|
8 | import File from '../src/File'
|
9 |
|
10 | describe('File', () => {
|
11 | let fixturesPath: string
|
12 |
|
13 | beforeEach(async (done) => {
|
14 | fixturesPath = await cloneFixtures()
|
15 | done()
|
16 | })
|
17 |
|
18 | function createFile (filePath: string): Promise<?File> {
|
19 | return File.create(path.join(fixturesPath, filePath), filePath)
|
20 | }
|
21 |
|
22 | it('verifies that virtual files can be created without a physical file existing and is the right type', async (done) => {
|
23 | const file = await createFile('foo.log-ParsedLaTeXLog')
|
24 | expect(file).toBeDefined()
|
25 | if (file) expect(file.type).toEqual('ParsedLaTeXLog')
|
26 | done()
|
27 | })
|
28 |
|
29 | it('verifies that physical files that do not exist will not be created', async (done) => {
|
30 | const file = await createFile('foo.tex')
|
31 | expect(file).toBeUndefined()
|
32 | done()
|
33 | })
|
34 |
|
35 | it('verifies that plain TeX files are not classified as LaTeX files', async (done) => {
|
36 | const file = await createFile('plain.tex')
|
37 | expect(file).toBeDefined()
|
38 | if (file) expect(file.type).toBeUndefined()
|
39 | done()
|
40 | })
|
41 |
|
42 | it('verifies that BibTeX control files are not classified as BibTeX files', async (done) => {
|
43 | const file = await createFile('wibble-blx.bib')
|
44 | expect(file).toBeDefined()
|
45 | if (file) expect(file.type).toEqual('BibTeXControlFile')
|
46 | done()
|
47 | })
|
48 |
|
49 | it('verifies that the detected file types are correct', async (done) => {
|
50 | const rootPath = path.join(fixturesPath, 'file-types')
|
51 | for (const fileName of await readdir.async(rootPath)) {
|
52 | const [, type, subType] = fileName.match(/^([^-._]+)(?:_([^-.]+))?/)
|
53 | const file = await createFile(path.join('file-types', fileName))
|
54 | expect(file).toBeDefined()
|
55 | if (file) {
|
56 | expect(file.type).toEqual(type)
|
57 | expect(file.subType).toEqual(subType)
|
58 | }
|
59 | }
|
60 | done()
|
61 | })
|
62 | })
|