UNPKG

1.99 kBPlain TextView Raw
1import fs from 'fs'
2
3import DockerCompiler from '../src/DockerCompiler'
4import { fixture } from './test-functions'
5import { SoftwareEnvironment, Person } from '@stencila/schema'
6import MockUrlFetcher from './MockUrlFetcher'
7
8const urlFetcher = new MockUrlFetcher()
9
10jest.setTimeout(30 * 60 * 1000)
11
12/**
13 * Tests of compiling Dockerfile
14 *
15 * To avoid actual building of the Docker image these tests
16 * set the build flag to false
17 */
18
19test('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
28test('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
36test('compile:multi-lang', async () => {
37 const compiler = new DockerCompiler(urlFetcher)
38 let environ = await compiler.compile('file://' + fixture('multi-lang'), false, false)
39
40 // Remove the date from the MRAN line to allow for changing date of test v expected
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
47test('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})