Skip to content

Commit

Permalink
run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
samouri committed Mar 29, 2021
1 parent 0441d61 commit a23317c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 35 deletions.
5 changes: 1 addition & 4 deletions src/main-thread/iframe-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ type MessageFromWorker = {
message: any;
};
type MessageFromIframe = { type: 'iframe-ready' } | MessageFromWorker;
type MessageToIframe =
| { type: 'terminate' }
| { type: 'init-worker'; code: string }
| { type: 'postMessage'; message: any };
type MessageToIframe = { type: 'terminate' } | { type: 'init-worker'; code: string } | { type: 'postMessage'; message: any };

/**
* An almost drop-in replacement for a standard Web Worker, although this one
Expand Down
2 changes: 1 addition & 1 deletion src/main-thread/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class WorkerContext {
if (!config.sandbox) {
this[TransferrableKeys.worker] = new Worker(URL.createObjectURL(new Blob([code])));
} else {
this[TransferrableKeys.worker] = (new IframeWorker(URL.createObjectURL(new Blob([code])), config.sandbox.iframeUrl)) as Worker;
this[TransferrableKeys.worker] = new IframeWorker(URL.createObjectURL(new Blob([code])), config.sandbox.iframeUrl) as Worker;
}
if (WORKER_DOM_DEBUG) {
console.info('debug', 'hydratedNode', readableHydrateableRootNode(baseElement, config, this));
Expand Down
15 changes: 4 additions & 11 deletions src/test/main-thread/iframe-worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,16 @@ test.beforeEach((t) => {
const sentToIframe: MessageEvent[] = [];

const messageListeners: any = [];
env.window.addEventListener = (type: string, listener: any) =>
messageListeners.push(listener);
env.window.addEventListener = (type: string, listener: any) => messageListeners.push(listener);

global.fetch = (blob: any) =>
Promise.resolve({
text: () => Promise.resolve(blob.toString().slice('BLOB:'.length)),
}) as any;
const worker = new IframeWorker(
URL.createObjectURL(new Blob(['worker code'])),
'https://example.com' as any
);
const worker = new IframeWorker(URL.createObjectURL(new Blob(['worker code'])), 'https://example.com' as any);
const iframe = (worker as any).iframe as HTMLIFrameElement;

const oldPostMessage = iframe.contentWindow!.postMessage.bind(
iframe.contentWindow
);
const oldPostMessage = iframe.contentWindow!.postMessage.bind(iframe.contentWindow);
iframe.contentWindow!.postMessage = (msg, targetOrigin, transferables) => {
sentToIframe.push(msg);
oldPostMessage(msg, targetOrigin, transferables);
Expand Down Expand Up @@ -104,8 +98,7 @@ test('Should proxy iframed worker messages.', async (t) => {
const onmessageerrorMessages: MessageEvent[] = [];

worker.onmessage = (msg: MessageEvent) => onmessageMessages.push(msg);
worker.onmessageerror = (msg: MessageEvent) =>
onmessageerrorMessages.push(msg);
worker.onmessageerror = (msg: MessageEvent) => onmessageerrorMessages.push(msg);
worker.onerror = (msg: ErrorEvent) => onerrorMessages.push(msg);

fakeReceiveMessage({ type: 'onmessage', message: { onmessage: 1 } });
Expand Down
30 changes: 15 additions & 15 deletions src/test/node/replaceWith.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

import anyTest, { TestInterface } from "ava";
import { Document } from "../../worker-thread/dom/Document";
import { Element } from "../../worker-thread/dom/Element";
import { createTestingDocument } from "../DocumentCreation";
import anyTest, { TestInterface } from 'ava';
import { Document } from '../../worker-thread/dom/Document';
import { Element } from '../../worker-thread/dom/Element';
import { createTestingDocument } from '../DocumentCreation';

const test = anyTest as TestInterface<{
document: Document;
Expand All @@ -32,42 +32,42 @@ test.beforeEach((t) => {

t.context = {
document,
parent: document.createElement("div"),
child: document.createElement("div"),
childTwo: document.createElement("div"),
childThree: document.createElement("div"),
parent: document.createElement('div'),
child: document.createElement('div'),
childTwo: document.createElement('div'),
childThree: document.createElement('div'),
};
});

test('replacing with no values provided removes child from parent', (t) => {
const { parent, child } = t.context;

parent.appendChild(child);
t.is(child.parentNode, parent, "before replacement parentNode exists");
t.is(child.parentNode, parent, 'before replacement parentNode exists');

child.replaceWith();
t.is(child.parentNode, null, "after replacement parentNode is unset");
t.is(child.parentNode, null, 'after replacement parentNode is unset');
t.deepEqual(parent.childNodes, []);
});

test('replacing unattached child results in no changes', (t) => {
const { child, childTwo } = t.context;

t.is(child.parentNode, null, "before replacement parentNode does not exist");
t.is(child.parentNode, null, 'before replacement parentNode does not exist');

child.replaceWith(childTwo);
t.is(child.parentNode, null, "after replacement original child parentNode remains unset");
t.is(childTwo.parentNode, null, "after replacement new child parentNode remains unset");
t.is(child.parentNode, null, 'after replacement original child parentNode remains unset');
t.is(childTwo.parentNode, null, 'after replacement new child parentNode remains unset');
});

test('replacing the same child results in no changes', (t) => {
const { parent, child } = t.context;

parent.appendChild(child);
t.is(child.parentNode, parent, "before replacement parentNode exists");
t.is(child.parentNode, parent, 'before replacement parentNode exists');

child.replaceWith(child);
t.is(child.parentNode, parent, "after replacement parentNode remains correct");
t.is(child.parentNode, parent, 'after replacement parentNode remains correct');
t.deepEqual(parent.childNodes, [child]);
});

Expand Down
8 changes: 4 additions & 4 deletions src/worker-thread/dom/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,10 @@ export abstract class Node {

/**
* Replaces the current node with the provided Array<node|string>.
* @param nodes
* @param nodes
* @see https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/replaceWith
*/
public replaceWith(...nodes: Array<Node|string>): void {
public replaceWith(...nodes: Array<Node | string>): void {
const parent: Node | null = this.parentNode;
let nodeIterator: number = nodes.length;
let currentNode: Node | string;
Expand All @@ -389,10 +389,10 @@ export abstract class Node {
}
while (nodeIterator--) {
currentNode = nodes[nodeIterator];

if (typeof currentNode !== 'object') {
currentNode = this.ownerDocument.createTextNode(currentNode);
}
}

// TODO: Investigate inserting all new nodes in a single operation.
if (!nodeIterator) {
Expand Down

0 comments on commit a23317c

Please sign in to comment.