Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,7 @@ function _insertBefore(parent, node, child, _inDocumentAssertion) {
do {
newFirst.parentNode = parent;
} while (newFirst !== newLast && (newFirst = newFirst.nextSibling));
_onUpdateChild(parent.ownerDocument || parent, parent);
_onUpdateChild(parent.ownerDocument || parent, parent, node);
if (node.nodeType == DOCUMENT_FRAGMENT_NODE) {
node.firstChild = node.lastChild = null;
}
Expand Down
14 changes: 14 additions & 0 deletions test/dom/node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

const { describe, test, expect } = require('@jest/globals');
const { DOMImplementation, Node } = require('../../lib/dom');
const { DOMParser } = require('../../lib/dom-parser');
const { DOMExceptionName } = require('../../lib/errors');
const { expectDOMException } = require('../errors/expectDOMException');
const { MIME_TYPE } = require('../../lib/conventions');
const { performance } = require('perf_hooks');

describe('Node.prototype', () => {
describe('constructor', () => {
Expand All @@ -28,6 +31,17 @@ describe('Node.prototype', () => {
);
});
});
const MANY = 10 * 1000;
const huge = `<xml>${[...Array(MANY).keys()].map((i) => `<node index="${i}"/>`).join('\n\t')}</xml>`;
test(`should be able to parse and append ${MANY / 1000}k nodes with a good performance`, () => {
const start = performance.now();
new DOMParser().parseFromString(huge, MIME_TYPE.XML_TEXT);
const duration = performance.now() - start;
// with the issue the test was introduced for,
// it took minutes for such an amount of nodes to be appended
// it usually takes < 1sec on my machine, but let's make sure the test is not flaky anywhere
expect(duration).toBeLessThanOrEqual(1500);
});
});
describe('isConnected', () => {
const impl = new DOMImplementation();
Expand Down