UNPKG

2.95 kBPlain TextView Raw
1import { fixture } from './test-functions'
2import RParser from '../src/RParser'
3import { SoftwarePackage } from '@stencila/schema'
4import MockUrlFetcher from './MockUrlFetcher'
5
6// Increase timeout (in milliseconds) to allow for HTTP requests
7// to get package meta data
8jest.setTimeout(30 * 60 * 1000)
9
10const urlFetcher = new MockUrlFetcher()
11
12/**
13 * When applied to an empty folder, parse should return null.
14 */
15test('parse:empty', async () => {
16 const parser = new RParser(urlFetcher, fixture('empty'))
17 expect(await parser.parse()).toBeNull()
18})
19
20/**
21 * When applied to a folder with no R code, parse should return null.
22 */
23test('parse:non-r', async () => {
24 const parser = new RParser(urlFetcher, fixture('py-source'))
25 expect(await parser.parse()).toBeNull()
26})
27
28/**
29 * When applied to a folder with only R source files, parse should return a `SoftwareEnvironment`
30 * with `name`, `softwareRequirements` etc populated correctly.
31 */
32test('parse:r-source', async () => {
33 const parser = new RParser(urlFetcher, fixture('r-source'))
34 const environ = await parser.parse() as SoftwarePackage
35 expect(environ.name).toEqual('rsource')
36
37 const reqs = environ.softwareRequirements
38 expect(reqs).not.toBeNull()
39 expect(reqs.map(req => req.name)).toEqual(['MASS', 'digest', 'dplyr', 'ggplot2', 'lubridate'])
40})
41
42/**
43 * When applied to a folder with a DESCRIPTION file,
44 * parse should return a `SoftwareEnvironment` with the packages listed.
45 */
46test('parse:r-requirements', async () => {
47 const parser = new RParser(urlFetcher, fixture('r-requirements'))
48 const environ = await parser.parse() as SoftwarePackage
49
50 expect(environ.name).toEqual('rrequirements')
51
52 const reqs = environ.softwareRequirements
53 expect(reqs).not.toBeNull()
54 expect(reqs.map(req => req.name)).toEqual(['packageone', 'packagetwo'])
55})
56
57/**
58 * When applied to a folder with a `DESCRIPTION` file, and R sources, only the `DESCRIPTION` file should be used to
59 * generate the requirements (i.e. R sources aren't parsed for requirements).
60 */
61test('parse:r-mixed', async () => {
62 const parser = new RParser(urlFetcher, fixture('r-mixed'))
63 const environ = await parser.parse() as SoftwarePackage
64
65 const reqs = environ.softwareRequirements
66 expect(reqs).not.toBeNull()
67 expect(reqs.map(req => req.name)).toEqual(['car', 'coin', 'ggplot2', 'httr', 'lsmeans'])
68})
69
70/**
71 * When applied to the `r-gsl` fixture, handles the sysreqs (which has an
72 * array of Debian packages) correctly.
73 */
74test('parse:r-gsl', async () => {
75 const parser = new RParser(urlFetcher, fixture('r-gsl'))
76 const environ = await parser.parse() as SoftwarePackage
77
78 const reqs = environ.softwareRequirements
79 expect(reqs).not.toBeNull()
80 expect(reqs.map(req => req.name)).toEqual(['gsl'])
81
82 const gsl = reqs.filter(req => req.name === 'gsl')[0]
83 const gslReqs = gsl.softwareRequirements
84 expect(gslReqs[0].name).toEqual('libgsl-dev')
85 expect(gslReqs[1].name).toEqual('libgsl2')
86})