forked from jest-community/jest-junit
/
getOptions.test.js
63 lines (49 loc) · 1.69 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
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('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);
});
});