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|Pnw)$/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 |
|
42 |
|
43 | const eventFilePath = dicy.resolvePath('$ROOTDIR/$NAME-events.yaml')
|
44 | if (await File.canRead(eventFilePath)) {
|
45 | expected = await File.safeLoad(eventFilePath)
|
46 | for (const type of expected.types) {
|
47 | dicy.on(type, event => { events.push(event) })
|
48 | }
|
49 | }
|
50 |
|
51 |
|
52 | expect(await dicy.run('load')).toBeTruthy()
|
53 |
|
54 | for (const command of dicy.options.check || []) {
|
55 | if (!await doCheck(command)) {
|
56 |
|
57 | spec.pend(`Skipped test since required program is not available (\`${command}\` was not successful).`)
|
58 | done()
|
59 | return
|
60 | }
|
61 | }
|
62 |
|
63 | expect(await dicy.run('build', 'log', 'save')).toBeTruthy()
|
64 |
|
65 |
|
66 | if (expected.types.length !== 0) expect(events).toReceiveEvents(expected.events)
|
67 |
|
68 | done()
|
69 |
|
70 | }, ASYNC_TIMEOUT)
|
71 | }
|
72 | })
|
73 | })
|