Skip to content

Commit f99a8a5

Browse files
securedeveloperafzalah
authored andcommitted
JSE [feat] Update the coverage options.
1 parent 88c5560 commit f99a8a5

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

jest.config.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
module.exports = {
2-
"globals": {
3-
"ts-jest": {
4-
"skipBabel": true
5-
}
6-
},
72
"collectCoverage": true,
83
"coverageDirectory": "./coverage/",
94
"collectCoverageFrom": [
10-
"**/*.{ts,tsx}",
5+
"**/src/util/*.{ts,tsx}",
6+
"!**/src/api/*.{ts,tsx}",
7+
"!**/src/xlsx/*.{ts,tsx}",
118
"!**/.circleci/**",
129
"!**/.idea/**",
1310
"!**/lib/**",
@@ -25,7 +22,7 @@ module.exports = {
2522
"moduleDirectories": [
2623
"node_modules"
2724
],
28-
modulePathIgnorePatterns: [
25+
"modulePathIgnorePatterns": [
2926
"<rootDir>/.circleci",
3027
"<rootDir>/.idea",
3128
"<rootDir>/coverage",

src/api/Helper.ts renamed to src/util/Helper.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export function cleanAlphaNumericString(str: string): string {
2-
return str ? str.replace(/\W/g, '') : str;
2+
return (str && typeof str === "string") ? str.replace(/\W/g, '') : str;
33
}
44

55
export function getISOFormattedDate(date?: Date): string {
6-
if (!date) {
6+
if (!date || typeof date !== "object") {
77
date = new Date();
88
}
99

src/xlsx/FileContentTypes.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ import {
1111
PART_NAME_XL_THEME,
1212
PART_NAME_XL_WORKBOOK,
1313
XMLNS_CONTENT_TYPES,
14-
DEFAULT_XML_VERSION, ENCODING_UTF_8, DEFAULT_STAND_ALONE
14+
DEFAULT_XML_VERSION,
15+
ENCODING_UTF_8,
16+
DEFAULT_STAND_ALONE
1517
} from "../api/Internals";
1618
import {JSESheet, JSExcel} from "../Types";
1719
import {DEFAULT_FILE_EXTENSION} from "../api/constants";
20+
import {cleanAlphaNumericString} from "../util/Helper";
1821

1922
const fileProps: any = {
2023
name: "[Content_Types]",
@@ -99,7 +102,10 @@ function getWorkSheetsOverrides(excel: JSExcel): Array<___JSE_XLSX___Node> {
99102
return excel.sheets.map((sheet: JSESheet) => ({
100103
name: fileProps.nodes.Override,
101104
values: [
102-
{key: fileProps.keys.PartName, value: `${partNameOverride}${sheet.name}${fileProps.extension}`},
105+
{
106+
key: fileProps.keys.PartName,
107+
value: `${partNameOverride}${cleanAlphaNumericString(sheet.name)}${fileProps.extension}`
108+
},
103109
{key: fileProps.keys.ContentType, value: PART_NAME_XL_WORKSHEET}
104110
]
105111
}));

src/xlsx/docProps/FileDocPropsCore.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// TODO: Tier-02 Replace values when file properties module is implemented
22
import {JSExcel} from "../../Types";
33
import {___JSE_XLSX___File, ___JSE_XLSX___Node} from "../../api/xlsx";
4-
import {getISOFormattedDate} from "../../api/Helper";
4+
import {getISOFormattedDate} from "../../util/Helper";
55
import {
66
DEFAULT_PROPS_CREATOR,
77
DEFAULT_PROPS_DESCRIPTION,

test/unit/Helper.test.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {cleanAlphaNumericString, getISOFormattedDate} from "../../src/api/Helper";
1+
import {cleanAlphaNumericString, getISOFormattedDate} from "../../src/util/Helper";
22

33
describe("Helper --> ", () => {
4-
describe("String --> ", () => {
4+
describe("String -->", () => {
55
test("it return a clean expected string", () => {
66
const inputs: Array<string> = ["\\test\red\bob\fred\new", "±~NaNNumericApha$-and_returned0"];
77
const outputs: Array<string> = ["testedobredew", "NaNNumericAphaand_returned0"];
@@ -10,14 +10,29 @@ describe("Helper --> ", () => {
1010
expect(cleanAlphaNumericString(input)).toBe(outputs[index]);
1111
});
1212
});
13+
14+
test("it return exact input if wrong string value is supplied", () => {
15+
const inputs: Array<any> = [false, undefined, true, 121, new Date(), {}, null];
16+
17+
inputs.forEach((input: any) => {
18+
expect(cleanAlphaNumericString(input)).toBe(input);
19+
});
20+
});
1321
});
1422

15-
describe("Date --> ", () => {
16-
test("it should return required ISO formatted date stamp", () => {
23+
describe("Date -->", () => {
24+
test("it should return required ISO formatted date stamp w.r.t date provided", () => {
1725
const inputDate: Date = new Date('05 October 2011 14:48 UTC');
1826
const expectedOutput: string = "2011-10-05T14:48:00Z";
1927

2028
expect(getISOFormattedDate(inputDate)).toBe(expectedOutput);
2129
});
30+
31+
32+
test("it should return today as ISO formatted date stamp if no arg is provided", () => {
33+
const expectedOutput: string = new Date().toISOString().split(".")[0] + "Z";
34+
35+
expect(getISOFormattedDate()).toBe(expectedOutput);
36+
});
2237
});
2338
});

0 commit comments

Comments
 (0)