1 |
|
2 |
|
3 | import 'babel-polyfill'
|
4 | import path from 'path'
|
5 | import readdir from 'readdir-enhanced'
|
6 | import childProcess from 'child_process'
|
7 |
|
8 | import { DiCy, File } from '../src/main'
|
9 | import { cloneFixtures, customMatchers } from './helpers'
|
10 |
|
11 | const ASYNC_TIMEOUT = 50000
|
12 |
|
13 | function doCheck (command: string): Promise<boolean> {
|
14 | return new Promise(resolve => {
|
15 | childProcess.exec(command, error => resolve(!error))
|
16 | })
|
17 | }
|
18 |
|
19 | describe('DiCy', () => {
|
20 | let dicy: DiCy
|
21 | let fixturesPath: string
|
22 | const testPath: string = path.join(__dirname, 'fixtures', 'builder-tests')
|
23 | let tests: Array<string> = readdir.sync(testPath, { filter: /\.(lhs|tex|Rnw|lagda)$/i })
|
24 |
|
25 | beforeEach(async (done) => {
|
26 | fixturesPath = await cloneFixtures()
|
27 |
|
28 | jasmine.addMatchers(customMatchers)
|
29 | done()
|
30 | })
|
31 |
|
32 | describe('can successfully build', () => {
|
33 | for (const name of tests) {
|
34 | const spec = it(name, async (done) => {
|
35 | let expected = { types: [], events: [] }
|
36 | let events = []
|
37 | const filePath = path.resolve(fixturesPath, 'builder-tests', name)
|
38 |
|
39 |
|
40 | dicy = await DiCy.create(filePath)
|
41 | dicy.state.env.HOME = fixturesPath
|
42 |
|
43 |
|
44 | const eventFilePath = dicy.resolvePath('$DIR/$NAME-events.yaml')
|
45 | if (await File.canRead(eventFilePath)) {
|
46 | expected = await File.safeLoad(eventFilePath)
|
47 | for (const type of expected.types) {
|
48 | dicy.on(type, event => { events.push(event) })
|
49 | }
|
50 | }
|
51 |
|
52 |
|
53 | expect(await dicy.run('load')).toBeTruthy()
|
54 |
|
55 | for (const command of dicy.options.check || []) {
|
56 | if (!await doCheck(command)) {
|
57 |
|
58 | spec.pend(`Skipped test since required program is not available (\`${command}\` was not successful).`)
|
59 | done()
|
60 | return
|
61 | }
|
62 | }
|
63 |
|
64 | expect(await dicy.run('build', 'log', 'save')).toBeTruthy()
|
65 |
|
66 |
|
67 | if (expected.types.length !== 0) expect(events).toReceiveEvents(expected.events)
|
68 |
|
69 | done()
|
70 |
|
71 | }, ASYNC_TIMEOUT)
|
72 | }
|
73 | })
|
74 | })
|