Skip to content
This repository was archived by the owner on Apr 18, 2020. It is now read-only.

Commit 498610a

Browse files
author
Rohith
committed
fixed the jsdom usage in the test
1 parent 1be93f0 commit 498610a

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

dist/tableToExcel.517b1af9.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ var TTEParser = function () {
144144
methods.parseDomToTable = function (ws, table, opts) {
145145
var _r, _c, cs, rs, r, c;
146146

147-
var rows = _toConsumableArray(table.getElementsByTagName("tr"));
147+
var rows = _toConsumableArray(table.rows);
148148

149149
var widths = table.getAttribute("data-cols-width");
150150
if (widths) widths = widths.split(",").map(function (item) {
@@ -217,11 +217,7 @@ var TTEParser = function () {
217217
exCell.border = styles.border || null;
218218
exCell.fill = styles.fill || null;
219219
exCell.numFmt = styles.numFmt || null;
220-
} // // If first row, set width of the columns.
221-
// if (_r == 0) {
222-
// // ws.columns[_c].width = Math.round(tds[_c].offsetWidth / 7.2); // convert pixel to character width
223-
// }
224-
220+
}
225221
}
226222
} //Setting column width
227223

@@ -45157,7 +45153,7 @@ var parent = module.bundle.parent;
4515745153
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
4515845154
var hostname = "" || location.hostname;
4515945155
var protocol = location.protocol === 'https:' ? 'wss' : 'ws';
45160-
var ws = new WebSocket(protocol + '://' + hostname + ':' + "63620" + '/');
45156+
var ws = new WebSocket(protocol + '://' + hostname + ':' + "50766" + '/');
4516145157

4516245158
ws.onmessage = function (event) {
4516345159
checkedAssets = {};

dist/tableToExcel.517b1af9.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/parser.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const TTEParser = (function() {
88
*/
99
methods.parseDomToTable = function(ws, table, opts) {
1010
let _r, _c, cs, rs, r, c;
11-
let rows = [...table.getElementsByTagName("tr")];
11+
let rows = [...table.rows];
1212
let widths = table.getAttribute("data-cols-width");
1313
if (widths)
1414
widths = widths.split(",").map(function(item) {
@@ -64,10 +64,6 @@ const TTEParser = (function() {
6464
exCell.fill = styles.fill || null;
6565
exCell.numFmt = styles.numFmt || null;
6666
}
67-
// // If first row, set width of the columns.
68-
// if (_r == 0) {
69-
// // ws.columns[_c].width = Math.round(tds[_c].offsetWidth / 7.2); // convert pixel to character width
70-
// }
7167
}
7268
}
7369
//Setting column width

test/utils/utils.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
import TTE from "../../src/tableToExcel";
2+
import jsdom from "jsdom";
23
import fs from "fs";
4+
35
export const defaultOpts = {
46
name: "export.xlsx",
57
autoStyle: false,
68
sheet: {
79
name: "Sheet 1"
810
}
911
};
12+
13+
/**
14+
* Returns an empty worksheet for testing.
15+
* @param {object} opts
16+
*/
1017
export function getWorkSheet(opts = {}) {
1118
let _opts = defaultOpts;
1219
opts = { ..._opts, ...opts };
1320
let wb = TTE.initWorkBook();
1421
return TTE.initSheet(wb, opts.sheet.name);
1522
}
16-
23+
/**
24+
* Read the conents of the a given file and returns the parsed DOM element
25+
* corresponding to the first table in the document.
26+
* @param {string} filename name of the html file where the table to test is written
27+
* @returns {HTMLTableElement}
28+
*/
1729
export function getTable(filename) {
1830
if (filename) {
1931
let path = __dirname + "/../samples/" + filename + ".html";
2032
let htmlString = fs.readFileSync(path, "utf8");
21-
let document = new window.DOMParser().parseFromString(
22-
htmlString,
23-
"text/xml"
24-
);
25-
return document.firstChild;
33+
const { JSDOM } = jsdom;
34+
const dom = new JSDOM(htmlString);
35+
return dom.window.document.querySelector("table");
2636
}
2737
}

0 commit comments

Comments
 (0)