|
| 1 | +/* eslint-disable @typescript-eslint/no-unused-vars */ |
| 2 | +/* eslint-disable @typescript-eslint/no-var-requires */ |
| 3 | +/* eslint-disable import/order */ |
| 4 | +/* eslint-disable import/no-extraneous-dependencies */ |
| 5 | +/* eslint-disable react/jsx-filename-extension */ |
| 6 | +import React, { Component } from 'react'; |
| 7 | +import { render } from 'react-dom'; |
| 8 | +import linkFiberStart from '../linkFiber'; |
| 9 | +// import 'expect-puppeteer'; |
| 10 | +import puppeteer from 'puppeteer'; |
| 11 | + |
| 12 | +const SERVER = require('./puppeteerServer'); |
| 13 | + |
| 14 | +const APP = 'http://localhost:5000'; |
| 15 | + |
| 16 | +let linkFiber; |
| 17 | +let mode; |
| 18 | +let snapShot; |
| 19 | + |
| 20 | +let browser; |
| 21 | +let page; |
| 22 | + |
| 23 | +class App extends Component { |
| 24 | + constructor(props) { |
| 25 | + super(props); |
| 26 | + this.state = { foo: 'bar' }; |
| 27 | + } |
| 28 | + |
| 29 | + render() { |
| 30 | + const { foo } = this.state; |
| 31 | + return <div>{foo}</div>; |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +describe('unit test for linkFiber', () => { |
| 36 | + beforeAll(async () => { |
| 37 | + await SERVER; |
| 38 | + const args = puppeteer.defaultArgs().filter(arg => String(arg).toLowerCase() !== '--disable-extensions'); |
| 39 | + browser = await puppeteer.launch({ |
| 40 | + args: args.concat(['--no-sandbox', '--disable-setuid-sandbox', |
| 41 | + '---extensions-on-chrome-urls', |
| 42 | + '--whitelisted-extension-id=fmkadmapgofadopljbjfkapdkoienihi', |
| 43 | + '--whitelisted-extension-id=hilpbahfbckghckaiafiiinjkeagmfhn', |
| 44 | + '--load-extension=/mnt/d/Libraries/Documents/codeRepos/reactime/src/extension/build']), |
| 45 | + devtools: true, |
| 46 | + ignoreDefaultArgs: true, |
| 47 | + // '--load-extension', '../../src/extension/build'], |
| 48 | + |
| 49 | + // headless: false, |
| 50 | + }); |
| 51 | + |
| 52 | + const c = await puppeteer.connect({ |
| 53 | + browserWSEndpoint: browser.wsEndpoint(), // `ws://${host}:${port}/devtools/browser/<id>`, |
| 54 | + ignoreHTTPSErrors: false, |
| 55 | + }); |
| 56 | + |
| 57 | + page = await browser.newPage(); |
| 58 | + }); |
| 59 | + |
| 60 | + afterAll(async () => { |
| 61 | + await SERVER.close(); |
| 62 | + |
| 63 | + await browser.close(); |
| 64 | + }); |
| 65 | + |
| 66 | + beforeEach(() => { |
| 67 | + snapShot = { tree: null }; |
| 68 | + mode = { |
| 69 | + jumping: false, |
| 70 | + paused: false, |
| 71 | + locked: false, |
| 72 | + }; |
| 73 | + linkFiber = linkFiberStart(snapShot, mode); |
| 74 | + |
| 75 | + page.waitForFunction(async lf => { |
| 76 | + const container = document.createElement('div'); |
| 77 | + render(<App />, container); |
| 78 | + lf(container); |
| 79 | + }, {}, linkFiber); |
| 80 | + }); |
| 81 | + |
| 82 | + test('linkFiber should mutate the snapshot tree property', () => { |
| 83 | + // linkFiber mutates the snapshot |
| 84 | + |
| 85 | + expect(typeof snapShot.tree).toBe('object'); |
| 86 | + // expect(snapShot.tree.component.state).toBe('root'); |
| 87 | + expect(snapShot.tree.state).toBe('root'); |
| 88 | + expect(snapShot.tree.children).toHaveLength(1); |
| 89 | + expect(snapShot.tree.children[0].component.state.foo).toBe('bar'); |
| 90 | + }); |
| 91 | + |
| 92 | + test('linkFiber should modify the setState of the stateful component', () => { |
| 93 | + expect(snapShot.tree.children[0].component.setState.linkFiberChanged).toBe(true); |
| 94 | + }); |
| 95 | +}); |
0 commit comments