1 | import fs from 'fs'
|
2 |
|
3 | import DockerCompiler from '../src/DockerCompiler'
|
4 | import { fixture } from './test-functions'
|
5 | import { SoftwareEnvironment, Person } from '@stencila/schema'
|
6 | import MockUrlFetcher from './MockUrlFetcher'
|
7 |
|
8 | const urlFetcher = new MockUrlFetcher()
|
9 |
|
10 | jest.setTimeout(30 * 60 * 1000)
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | test('compile:empty', async () => {
|
20 | const compiler = new DockerCompiler(urlFetcher)
|
21 | let environ = await compiler.compile('file://' + fixture('empty'), false)
|
22 |
|
23 | let expected = new SoftwareEnvironment()
|
24 | expected.name = 'empty'
|
25 | expect(environ).toEqual(expected)
|
26 | })
|
27 |
|
28 | test('compile:dockerfile-date', async () => {
|
29 | const compiler = new DockerCompiler(urlFetcher)
|
30 | let environ = await compiler.compile('file://' + fixture('dockerfile-date'), false)
|
31 |
|
32 | expect(environ && environ.description && environ.description.substring(0, 23)).toEqual('Prints the current date')
|
33 | expect(environ && environ.authors && (environ.authors[0] as Person).name).toEqual('Nokome Bentley')
|
34 | })
|
35 |
|
36 | test('compile:multi-lang', async () => {
|
37 | const compiler = new DockerCompiler(urlFetcher)
|
38 | let environ = await compiler.compile('file://' + fixture('multi-lang'), false, false)
|
39 |
|
40 |
|
41 | const aptAddMRAN = /(apt-add-repository "deb https:\/\/mran.microsoft.com\/snapshot)\/([\d-]+)\/(bin\/linux\/ubuntu bionic-cran35\/)"/
|
42 | const actual = fs.readFileSync(fixture('multi-lang/.Dockerfile'), 'utf8').replace(aptAddMRAN, '$1/YYYY-MM-DD/$3')
|
43 | const expected = fs.readFileSync(fixture('multi-lang/Dockerfile.expected'), 'utf8').replace(aptAddMRAN, '$1/YYYY-MM-DD/$3')
|
44 | expect(actual).toEqual(expected)
|
45 | })
|
46 |
|
47 | test('who:r-gsl', async () => {
|
48 | const compiler = new DockerCompiler(urlFetcher)
|
49 | let people = await compiler.who('file://' + fixture('r-gsl'))
|
50 |
|
51 | expect(people).toEqual({"Robin K.": ["gsl"]})
|
52 | })
|