/
getOptions.test.js
80 lines (62 loc) · 2.24 KB
/
getOptions.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const fs = require('fs');
const path = require('path');
const getOptions = require('../utils/getOptions.js');
jest.mock('fs', () => {
return Object.assign(
{},
jest.requireActual('fs'),
{
existsSync: jest.fn().mockReturnValue(true)
}
)
});
// Mock return of require('/package.json')
// Virtual because it doesn't actually exist
jest.mock('/package.json', () => {
return {
name: 'foo',
version: '1.0.0',
'jest-junit': {
suiteName: 'test suite'
}
}
}, {virtual: true});
describe('getOptions', () => {
it ('should support package.json in /', () => {
});
});
describe('getUniqueOutputName', () =>{
const defaultPrefix = 'junit'
it(`should return default ${defaultPrefix} value if given no preferred prefix`, () => {
const uniqueOutput = getOptions.getUniqueOutputName()
expect(uniqueOutput).toContain(defaultPrefix)
})
it(`should return apply custom prefix value if given prefix`, () => {
const customPrefix = "foo"
const uniqueOutput = getOptions.getUniqueOutputName(customPrefix)
expect(uniqueOutput).not.toContain(defaultPrefix)
expect(uniqueOutput).toContain(customPrefix)
})
})
describe('replace <rootDir>', () => {
it('should replace <rootDir> in output path', () => {
const rootDir = 'testRootDir';
const outputPath = '<rootDir>/test/result/output.xml';
const newOutput = getOptions.replaceRootDirInOutput(rootDir, outputPath);
// Result of replaceRootDirInOutput will also contain the drive letter and path slashes (different format depending on OS).
// So instead assert that the rootDir is in the result and the placeholder (<rootDir>) is not.
expect(newOutput).toContain(rootDir);
expect(newOutput).not.toContain('<rootDir>');
});
it('should not replace when output has no <rootDir>', () => {
const rootDir = 'testRootDir';
const outputPath = 'testDir/test/result/output.xml';
const newOutput = getOptions.replaceRootDirInOutput(rootDir, outputPath);
expect(newOutput).toBe(outputPath);
});
it('should not replace when rootDir is null', () => {
const outputPath = 'testDir/test/result/output.xml';
const newOutput = getOptions.replaceRootDirInOutput(null, outputPath);
expect(newOutput).toBe(outputPath);
});
});