pomanalyzer 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +21 -0
- package/DOCUMENTATION.md +0 -0
- package/LICENSE +21 -0
- package/PUBLISH.md +28 -0
- package/README.md +152 -0
- package/TEST.md +43 -0
- package/babel.config.js +3 -0
- package/cli.js +56 -0
- package/jest.config.js +17 -0
- package/output/Maven_Dependencies_report.html +84 -0
- package/output/Maven_Dependencies_report.md +24 -0
- package/package.json +47 -0
- package/screenshots/CodeCoverage.png +0 -0
- package/screenshots/ConsoleOutput.png +0 -0
- package/screenshots/HtmlOutput.png +0 -0
- package/screenshots/MarkdownOutput.png +0 -0
- package/src/index.js +50 -0
- package/src/services/dependencyService.js +61 -0
- package/src/services/duplicateChecker.js +17 -0
- package/src/utils/dependencyResolver.js +28 -0
- package/src/utils/fileUtils.js +19 -0
- package/src/utils/outputFormatter.js +14 -0
- package/src/utils/printHTMLTable.js +88 -0
- package/src/utils/printMarkdownTable.js +50 -0
- package/src/utils/xmlParser.js +21 -0
- package/test/Test1.xml +56 -0
- package/test/dependencyResolver.test.js +58 -0
- package/test/dependencyService.test.js +310 -0
- package/test/duplicateChecker.test.js +67 -0
- package/test/fileUtils.test.js +43 -0
- package/test/outputFormatter.test.js +57 -0
- package/test/xmlParser.test.js +71 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { readFile } from '../src/utils/fileUtils';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
|
|
4
|
+
jest.mock('fs');
|
|
5
|
+
|
|
6
|
+
describe('File Utils', () => {
|
|
7
|
+
const mockFilePath = 'mock/path/to/file.txt';
|
|
8
|
+
const mockFileContent = 'Hello, World!';
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
jest.clearAllMocks();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should read file content correctly', async () => {
|
|
15
|
+
fs.readFile.mockImplementation((path, encoding, callback) => {
|
|
16
|
+
callback(null, mockFileContent);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const content = await readFile(mockFilePath);
|
|
20
|
+
expect(content).toBe(mockFileContent);
|
|
21
|
+
expect(fs.readFile).toHaveBeenCalledWith(mockFilePath, 'utf-8', expect.any(Function));
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should reject promise when file read fails', async () => {
|
|
25
|
+
const mockError = new Error('File not found');
|
|
26
|
+
fs.readFile.mockImplementation((path, encoding, callback) => {
|
|
27
|
+
callback(mockError, null);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
await expect(readFile(mockFilePath)).rejects.toThrow('File not found');
|
|
31
|
+
expect(fs.readFile).toHaveBeenCalledWith(mockFilePath, 'utf-8', expect.any(Function));
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should handle non-UTF8 encodings if specified', async () => {
|
|
35
|
+
fs.readFile.mockImplementation((path, encoding, callback) => {
|
|
36
|
+
expect(encoding).toBe('utf-8'); // Default encoding
|
|
37
|
+
callback(null, mockFileContent);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
await readFile(mockFilePath);
|
|
41
|
+
expect(fs.readFile).toHaveBeenCalledWith(mockFilePath, 'utf-8', expect.any(Function));
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { printTable } from '../src/utils/outputFormatter';
|
|
2
|
+
|
|
3
|
+
describe('Output Formatter', () => {
|
|
4
|
+
let consoleLogSpy, consoleTableSpy;
|
|
5
|
+
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
8
|
+
consoleTableSpy = jest.spyOn(console, 'table').mockImplementation();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
consoleLogSpy.mockRestore();
|
|
13
|
+
consoleTableSpy.mockRestore();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should print a title and table for non-empty dependencies', () => {
|
|
17
|
+
const dependencies = [
|
|
18
|
+
{ groupId: 'com.example', artifactId: 'example-artifact', version: '1.0.0' }
|
|
19
|
+
];
|
|
20
|
+
const title = 'Test Dependencies';
|
|
21
|
+
|
|
22
|
+
printTable(dependencies, title);
|
|
23
|
+
|
|
24
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(title);
|
|
25
|
+
expect(consoleTableSpy).toHaveBeenCalledWith(dependencies);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should print a message for empty dependencies', () => {
|
|
29
|
+
const dependencies = [];
|
|
30
|
+
const title = 'Empty Dependencies';
|
|
31
|
+
|
|
32
|
+
printTable(dependencies, title);
|
|
33
|
+
|
|
34
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(`${title}: No data available.`);
|
|
35
|
+
expect(consoleTableSpy).not.toHaveBeenCalled();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should handle null dependencies', () => {
|
|
39
|
+
const dependencies = null;
|
|
40
|
+
const title = 'Null Dependencies';
|
|
41
|
+
|
|
42
|
+
printTable(dependencies, title);
|
|
43
|
+
|
|
44
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(`${title}: No data available.`);
|
|
45
|
+
expect(consoleTableSpy).not.toHaveBeenCalled();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should handle undefined dependencies', () => {
|
|
49
|
+
const dependencies = undefined;
|
|
50
|
+
const title = 'Undefined Dependencies';
|
|
51
|
+
|
|
52
|
+
printTable(dependencies, title);
|
|
53
|
+
|
|
54
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(`${title}: No data available.`);
|
|
55
|
+
expect(consoleTableSpy).not.toHaveBeenCalled();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { parseXml } from '../src/utils/xmlParser';
|
|
2
|
+
import xml2js from 'xml2js';
|
|
3
|
+
|
|
4
|
+
jest.mock('xml2js');
|
|
5
|
+
|
|
6
|
+
describe('XML Parser', () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
jest.clearAllMocks();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should parse valid XML content into a JavaScript object', async () => {
|
|
12
|
+
const xmlContent = '<project><properties><prop>value</prop></properties></project>';
|
|
13
|
+
const expectedResult = {
|
|
14
|
+
project: {
|
|
15
|
+
properties: [{ prop: ['value'] }]
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
xml2js.Parser.mockImplementation(() => ({
|
|
20
|
+
parseString: (content, callback) => {
|
|
21
|
+
expect(content).toBe(xmlContent);
|
|
22
|
+
callback(null, expectedResult);
|
|
23
|
+
}
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
const result = await parseXml(xmlContent);
|
|
27
|
+
expect(result).toEqual(expectedResult);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should reject the promise when XML parsing fails', async () => {
|
|
31
|
+
const xmlContent = '<invalid>xml';
|
|
32
|
+
const errorMsg = 'XML parsing error';
|
|
33
|
+
|
|
34
|
+
xml2js.Parser.mockImplementation(() => ({
|
|
35
|
+
parseString: (content, callback) => {
|
|
36
|
+
callback(new Error(errorMsg), null);
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
await expect(parseXml(xmlContent)).rejects.toThrow('Error parsing XML: ' + errorMsg);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should handle empty XML content', async () => {
|
|
44
|
+
const xmlContent = '';
|
|
45
|
+
const expectedResult = {};
|
|
46
|
+
|
|
47
|
+
xml2js.Parser.mockImplementation(() => ({
|
|
48
|
+
parseString: (content, callback) => {
|
|
49
|
+
callback(null, expectedResult);
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
const result = await parseXml(xmlContent);
|
|
54
|
+
expect(result).toEqual(expectedResult);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should use the xml2js Parser with default options', async () => {
|
|
58
|
+
const xmlContent = '<project></project>';
|
|
59
|
+
const mockParseString = jest.fn((content, callback) => {
|
|
60
|
+
callback(null, {});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
xml2js.Parser.mockImplementation(() => ({
|
|
64
|
+
parseString: mockParseString
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
await parseXml(xmlContent);
|
|
68
|
+
expect(mockParseString).toHaveBeenCalledWith(xmlContent, expect.any(Function));
|
|
69
|
+
expect(xml2js.Parser).toHaveBeenCalledWith();
|
|
70
|
+
});
|
|
71
|
+
});
|