Skip to content

Commit

Permalink
server-lib bugfix: need scopingRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
samouri committed Sep 28, 2021
1 parent 95ba4b8 commit ef101d8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/test/htmlelement/querySelectorAll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ test('test Element.querySelectorAll on id selectors', (t) => {
t.deepEqual(document.querySelectorAll(`#${DIV_ID}`), [div]);
});

// TODO: create better solution for parameterizing server tests.
test.serial('server=true: test Element.querySelectorAll on id selectors', (t) => {
process.env.SERVER = 'true';
try {
const document = createTestingDocument();
const testEl = document.createElement('test-el');
const id = 'TEST_EL_ID';
testEl.setAttribute('id', id);
document.appendChild(testEl);

const result = document.querySelectorAll(`#${id}`);
t.deepEqual(result, [testEl]);
} finally {
delete process.env.SERVER;
}
});

test('test Element.querySelectorAll on class selectors', (t) => {
const { document, div } = t.context;

Expand Down
2 changes: 1 addition & 1 deletion src/worker-thread/dom/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ export abstract class Node {
this.nodeType = nodeType;
this.nodeName = nodeName;
this.ownerDocument = ownerDocument || this;
this[TransferrableKeys.scopingRoot] = this;
if (process.env.SERVER) {
return;
}

this[TransferrableKeys.scopingRoot] = this;
this[TransferrableKeys.index] = overrideIndex ? storeOverrideNodeMapping(this, overrideIndex) : storeNodeMapping(this);
this[TransferrableKeys.transferredFormat] = [this[TransferrableKeys.index]];
}
Expand Down

0 comments on commit ef101d8

Please sign in to comment.