Skip to content

Commit 350be44

Browse files
testing progress
1 parent 969ff3f commit 350be44

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/backend/__tests__/linkFiber.test.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ describe('linkFiber', () => {
2828

2929
// Set up mock React DevTools global hook
3030
(window as any).__REACT_DEVTOOLS_GLOBAL_HOOK__ = {
31-
renderers: new Map<1, { version: string }>(),
31+
renderers: new Map<1, { version: string }>([[1, { version: '16' }]]),
3232
inject: jest.fn(),
3333
supportsFiber: true,
3434
onCommitFiberRoot: jest.fn(),
3535
onCommitFiberUnmount: jest.fn(),
3636
rendererInterfaces: {},
37+
getFiberRoots: jest.fn(() => [{ current: { tag: 0 } }]),
3738
};
3839
});
3940

@@ -42,15 +43,15 @@ describe('linkFiber', () => {
4243
delete window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
4344
});
4445

45-
it('link fiber should return a function', () => {
46+
xit('link fiber should return a function', () => {
4647
expect(typeof linkFiber).toBe('function');
4748
});
4849

49-
it('returned function should not throw an error', () => {
50+
xit('returned function should not throw an error', () => {
5051
expect(() => linkFiber()).not.toThrowError();
5152
});
5253

53-
it('should send message to front end that React DevTools is installed', () => {
54+
xit('should send message to front end that React DevTools is installed', () => {
5455
linkFiber();
5556
expect(mockPostMessage).toHaveBeenCalled();
5657
expect(mockPostMessage).toHaveBeenCalledWith(
@@ -62,15 +63,33 @@ describe('linkFiber', () => {
6263
);
6364
});
6465

65-
it('should not do anything if React Devtools is not installed', () => {
66+
xit('should not do anything if React Devtools is not installed', () => {
6667
delete window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
6768
expect(() => linkFiber()).not.toThrowError();
6869
expect(mockPostMessage).not.toHaveBeenCalled();
6970
});
7071

71-
xit('should not do anything if the target application is not a React App', () => {});
72+
it('should send a message to the front end if the target application is a React App', () => {
73+
linkFiber();
74+
// the third call is from the onCommitFiberRoot() function
75+
expect(mockPostMessage).toHaveBeenCalledTimes(3);
76+
expect(mockPostMessage).toHaveBeenCalledWith(
77+
{
78+
action: 'devToolsInstalled',
79+
payload: 'devToolsInstalled',
80+
},
81+
'*',
82+
);
83+
expect(mockPostMessage).toHaveBeenCalledWith(
84+
{
85+
action: 'aReactApp',
86+
payload: 'aReactApp',
87+
},
88+
'*',
89+
);
90+
});
7291

73-
xit('should send a message to the front end if the target application is a React App', () => {});
92+
xit('should not do anything if the target application is not a React App', () => {});
7493

7594
xit('should initiate an event listener for visibility change', () => {});
7695
});

src/backend/routers/linkFiber.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export default function linkFiber(snapShot: Snapshot, mode: Status): () => void
7777
// TODO: Convert this into async/await & add try/catch
7878

7979
return () => {
80-
console.log('testing called');
8180
// -------------------CHECK REACT DEVTOOL INSTALLATION----------------------
8281
// react devtools global hook is a global object that was injected by the React Devtools content script, allows access to fiber nodes and react version
8382
// Obtain React Devtools Object:
@@ -101,6 +100,7 @@ export default function linkFiber(snapShot: Snapshot, mode: Status): () => void
101100
const reactInstance = devTools.renderers.get(1);
102101
// If target application is not a React App, this will return undefined.
103102
if (!reactInstance) {
103+
console.log('not a react instance', reactInstance);
104104
return;
105105
}
106106
// If target application is a React App, send a message to front end.
@@ -124,7 +124,7 @@ export default function linkFiber(snapShot: Snapshot, mode: Status): () => void
124124
// ---------OBTAIN THE INITIAL FIBEROOTNODE FROM REACT DEV TOOL-------------
125125
// Obtain the FiberRootNode, which is the first value in the FiberRoot Set:
126126
fiberRoot = devTools.getFiberRoots(1).values().next().value;
127-
console.log('linkFiber', { fiberRoot });
127+
console.log('fiberRoot', fiberRoot);
128128

129129
// ----------INITIALIZE THE TREE SNAP SHOT ON CHROME EXTENSION--------------
130130
throttledUpdateSnapshot(fiberRoot); // only runs on start up

0 commit comments

Comments
 (0)