|
| 1 | +/* eslint-disable no-undef */ |
| 2 | +import 'babel-polyfill'; |
| 3 | + |
| 4 | +const puppeteer = require('puppeteer'); |
| 5 | + |
| 6 | +const SERVER = require('../Backend/server'); |
| 7 | + |
| 8 | +const APP = 'http://localhost:3000'; |
| 9 | +const TYPESCRIPT = 'http://localhost:3000/typescript.html'; |
| 10 | + |
| 11 | +let browser; |
| 12 | +let page; |
| 13 | + |
| 14 | +describe('Sandbox Tests', () => { |
| 15 | + beforeAll(async () => { |
| 16 | + await SERVER; |
| 17 | + |
| 18 | + browser = await puppeteer.launch({ |
| 19 | + args: ['--no-sandbox', '--disable-setuid-sandbox'] |
| 20 | + // headless: false |
| 21 | + }); |
| 22 | + page = await browser.newPage(); |
| 23 | + }); |
| 24 | + |
| 25 | + afterAll(async () => { |
| 26 | + await SERVER.close(); |
| 27 | + |
| 28 | + await browser.close(); |
| 29 | + }); |
| 30 | + |
| 31 | + describe('Non-Typescript Tests', () => { |
| 32 | + describe('Sandbox Launch', () => { |
| 33 | + it('Sandboxes Load Successfully', async () => { |
| 34 | + await page.goto(APP); |
| 35 | + const title = await page.$eval('title', el => el.innerHTML); |
| 36 | + expect(title).toBe('Reactime Sandboxes'); |
| 37 | + |
| 38 | + // await page.screenshot({ path: 'example.png' }); // Add a screenshot |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + describe('Hook Tests', () => { |
| 43 | + it('The parent count should be 1 after the button is clicked 2 times', async () => { |
| 44 | + await page.$eval('#increaseButton', el => el.click()); |
| 45 | + await page.$eval('#increaseButton', el => el.click()); |
| 46 | + |
| 47 | + const lastSnapshotJSON = await page.$eval( |
| 48 | + '#lastSnapshot', |
| 49 | + el => el.innerHTML |
| 50 | + ); |
| 51 | + |
| 52 | + const lastSnapshot = await JSON.parse(lastSnapshotJSON); |
| 53 | + |
| 54 | + // The snapshot is 1 event behind currently; if this is changed then the expected value would be 2 |
| 55 | + // console.log(JSON.parse(document.querySelector('#lastSnapshot').innerHTML).children[0].children[1].state.count) |
| 56 | + expect(lastSnapshot.children[0].children[1].state.count).toBe(1); |
| 57 | + }); |
| 58 | + |
| 59 | + it('After the both button is clicked 2 times, the first child count should be 1 and the second child count should be 999', async () => { |
| 60 | + await page.$eval('#childBothButton', el => el.click()); |
| 61 | + await page.$eval('#childBothButton', el => el.click()); |
| 62 | + |
| 63 | + const lastSnapshotJSON = await page.$eval( |
| 64 | + '#lastSnapshot', |
| 65 | + el => el.innerHTML |
| 66 | + ); |
| 67 | + |
| 68 | + const lastSnapshot = await JSON.parse(lastSnapshotJSON); |
| 69 | + |
| 70 | + // console.log(JSON.parse(document.querySelector('#lastSnapshot').innerHTML).children[0].children[1].children[0].state.count2) |
| 71 | + expect( |
| 72 | + lastSnapshot.children[0].children[1].children[0].state.count2 |
| 73 | + ).toBe(1); |
| 74 | + |
| 75 | + expect( |
| 76 | + lastSnapshot.children[0].children[1].children[0].state.count3 |
| 77 | + ).toBe(999); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + describe('UseEffect Tests', () => { |
| 82 | + it('Should navigate to the useEffect Tests', async () => { |
| 83 | + await page.$eval('#UseEffect', el => el.click()); |
| 84 | + }); |
| 85 | + }); |
| 86 | + |
| 87 | + describe('UseContext Tests', () => { |
| 88 | + it('Should navigate to the UseContext Tests', async () => { |
| 89 | + await page.$eval('#UseContext', el => el.click()); |
| 90 | + }); |
| 91 | + }); |
| 92 | + |
| 93 | + describe('UseMemo Tests', () => { |
| 94 | + it('Should navigate to the UseMemo Tests', async () => { |
| 95 | + await page.$eval('#UseMemo', el => el.click()); |
| 96 | + }); |
| 97 | + }); |
| 98 | + |
| 99 | + describe('Redux Tests', () => { |
| 100 | + it('Should navigate to the Redux Tests', async () => { |
| 101 | + await page.$eval('#Redux', el => el.click()); |
| 102 | + }); |
| 103 | + }); |
| 104 | + |
| 105 | + describe('Router Tests', () => { |
| 106 | + it('Should navigate to the Router Tests', async () => { |
| 107 | + await page.$eval('#Router', el => el.click()); |
| 108 | + }); |
| 109 | + }); |
| 110 | + |
| 111 | + describe('SetState Tests', () => { |
| 112 | + it('Should navigate to the SetState Tests', async () => { |
| 113 | + await page.$eval('#SetState', el => el.click()); |
| 114 | + }); |
| 115 | + }); |
| 116 | + |
| 117 | + describe('SetStateConditional Tests', () => { |
| 118 | + it('Should navigate to the SetStateConditional Tests', async () => { |
| 119 | + await page.$eval('#SetStateConditional', el => el.click()); |
| 120 | + }); |
| 121 | + }); |
| 122 | + |
| 123 | + describe('ComponentDidMount Tests', () => { |
| 124 | + it('Should navigate to the ComponentDidMount Tests', async () => { |
| 125 | + await page.$eval('#ComponentDidMount', el => el.click()); |
| 126 | + }); |
| 127 | + }); |
| 128 | + }); |
| 129 | + |
| 130 | + describe('Typescript Tests', () => { |
| 131 | + describe('Typescript Sandbox Launch', () => { |
| 132 | + it('Typescript Sandboxes Load Successfully', async () => { |
| 133 | + await page.goto(TYPESCRIPT); |
| 134 | + const title = await page.$eval('title', el => el.innerHTML); |
| 135 | + expect(title).toBe('Typescript Reactime Sandboxes'); |
| 136 | + |
| 137 | + // await page.screenshot({ path: 'example.png' }); // Add a screenshot |
| 138 | + }); |
| 139 | + }); |
| 140 | + |
| 141 | + describe('Typescript Hook Tests', () => { |
| 142 | + describe('UseEffect Tests', () => { |
| 143 | + it('Should navigate to the useEffect Tests', async () => { |
| 144 | + await page.$eval('#UseEffect', el => el.click()); |
| 145 | + }); |
| 146 | + }); |
| 147 | + |
| 148 | + describe('UseContext Tests', () => { |
| 149 | + it('Should navigate to the UseContext Tests', async () => { |
| 150 | + await page.$eval('#UseContext', el => el.click()); |
| 151 | + }); |
| 152 | + }); |
| 153 | + |
| 154 | + describe('UseMemo Tests', () => { |
| 155 | + it('Should navigate to the UseMemo Tests', async () => { |
| 156 | + await page.$eval('#UseMemo', el => el.click()); |
| 157 | + }); |
| 158 | + }); |
| 159 | + |
| 160 | + describe('Redux Tests', () => { |
| 161 | + it('Should navigate to the Redux Tests', async () => { |
| 162 | + await page.$eval('#Redux', el => el.click()); |
| 163 | + }); |
| 164 | + }); |
| 165 | + |
| 166 | + describe('Router Tests', () => { |
| 167 | + it('Should navigate to the Router Tests', async () => { |
| 168 | + await page.$eval('#Router', el => el.click()); |
| 169 | + }); |
| 170 | + }); |
| 171 | + |
| 172 | + describe('SetState Tests', () => { |
| 173 | + it('Should navigate to the SetState Tests', async () => { |
| 174 | + await page.$eval('#SetState', el => el.click()); |
| 175 | + }); |
| 176 | + }); |
| 177 | + |
| 178 | + describe('ComponentDidMount Tests', () => { |
| 179 | + it('Should navigate to the ComponentDidMount Tests', async () => { |
| 180 | + await page.$eval('#ComponentDidMount', el => el.click()); |
| 181 | + }); |
| 182 | + }); |
| 183 | + }); |
| 184 | + }); |
| 185 | +}); |
0 commit comments