|
1 | 1 | const puppeteer = require('puppeteer'); |
2 | 2 |
|
3 | 3 | let browser; |
4 | | -let page; |
5 | 4 |
|
6 | 5 | beforeAll(async () => { |
7 | 6 | browser = await puppeteer.launch(); |
8 | | - page = await browser.newPage(); |
9 | | - await page.goto('http://localhost:6969/full-stack-lifecycle'); |
10 | 7 | }); |
11 | 8 |
|
12 | | -describe('FullStackLifecycle', () => { |
| 9 | +describe('FullStackLifecycle ssr', () => { |
| 10 | + |
| 11 | + let page; |
| 12 | + |
| 13 | + beforeAll(async () => { |
| 14 | + page = await browser.newPage(); |
| 15 | + await page.goto('http://localhost:6969/full-stack-lifecycle'); |
| 16 | + }); |
13 | 17 |
|
14 | 18 | test('prepare should run', async () => { |
15 | 19 | await page.waitForSelector('[data-prepared]'); |
16 | 20 | const element = await page.$('[data-prepared]'); |
17 | 21 | expect(element).toBeTruthy(); |
18 | 22 | }); |
19 | 23 |
|
| 24 | + test('prepare should run in the server for ssr', async () => { |
| 25 | + await page.waitForSelector('[data-prepare-env="server"]'); |
| 26 | + const element = await page.$('[data-prepare-env="server"]'); |
| 27 | + expect(element).toBeTruthy(); |
| 28 | + }); |
| 29 | + |
20 | 30 | test('initiate should run', async () => { |
21 | 31 | await page.waitForSelector('[data-initiated]'); |
22 | 32 | const element = await page.$('[data-initiated]'); |
23 | 33 | expect(element).toBeTruthy(); |
24 | 34 | }); |
25 | 35 |
|
| 36 | + test('initiate should run in the server for ssr', async () => { |
| 37 | + await page.waitForSelector('[data-initiate-env="server"]'); |
| 38 | + const element = await page.$('[data-initiate-env="server"]'); |
| 39 | + expect(element).toBeTruthy(); |
| 40 | + }); |
| 41 | + |
| 42 | + test('launch should run', async () => { |
| 43 | + await page.waitForSelector('[data-launched]'); |
| 44 | + const element = await page.$('[data-launched]'); |
| 45 | + expect(element).toBeTruthy(); |
| 46 | + }); |
| 47 | + |
| 48 | + test('launch should run in the server for ssr', async () => { |
| 49 | + await page.waitForSelector('[data-launch-env="server"]'); |
| 50 | + const element = await page.$('[data-launch-env="server"]'); |
| 51 | + expect(element).toBeTruthy(); |
| 52 | + }); |
| 53 | + |
26 | 54 | test('hydrate should run', async () => { |
27 | 55 | await page.waitForSelector('[data-hydrated]'); |
28 | 56 | const element = await page.$('[data-hydrated]'); |
29 | 57 | expect(element).toBeTruthy(); |
30 | 58 | }); |
31 | 59 |
|
| 60 | + test('update should run', async () => { |
| 61 | + await page.waitForSelector('[data-updated]'); |
| 62 | + const element = await page.$('[data-updated]'); |
| 63 | + expect(element).toBeTruthy(); |
| 64 | + }); |
| 65 | + |
| 66 | + test('terminate should run', async () => { |
| 67 | + await page.click('a[href="/"]'); |
| 68 | + await page.waitForFunction(() => location.search == '?terminated=true'); |
| 69 | + const element = await page.$('.FullStackLifecycle'); |
| 70 | + expect(element).toBeFalsy(); |
| 71 | + }); |
| 72 | + |
| 73 | +}); |
| 74 | + |
| 75 | +describe('FullStackLifecycle spa', () => { |
| 76 | + |
| 77 | + let page; |
| 78 | + |
| 79 | + beforeAll(async () => { |
| 80 | + page = await browser.newPage(); |
| 81 | + await page.goto('http://localhost:6969/'); |
| 82 | + await page.click('a[href="/full-stack-lifecycle"]') |
| 83 | + }); |
| 84 | + |
| 85 | + test('prepare should run', async () => { |
| 86 | + await page.waitForSelector('[data-prepared]'); |
| 87 | + const element = await page.$('[data-prepared]'); |
| 88 | + expect(element).toBeTruthy(); |
| 89 | + }); |
| 90 | + |
| 91 | + test('prepare should run in the client for spa', async () => { |
| 92 | + await page.waitForSelector('[data-prepare-env="client"]'); |
| 93 | + const element = await page.$('[data-prepare-env="client"]'); |
| 94 | + expect(element).toBeTruthy(); |
| 95 | + }); |
| 96 | + |
| 97 | + test('initiate should run', async () => { |
| 98 | + await page.waitForSelector('[data-initiated]'); |
| 99 | + const element = await page.$('[data-initiated]'); |
| 100 | + expect(element).toBeTruthy(); |
| 101 | + }); |
| 102 | + |
| 103 | + test('initiate should run in the client for spa', async () => { |
| 104 | + await page.waitForSelector('[data-initiate-env="client"]'); |
| 105 | + const element = await page.$('[data-initiate-env="client"]'); |
| 106 | + expect(element).toBeTruthy(); |
| 107 | + }); |
| 108 | + |
32 | 109 | test('launch should run', async () => { |
33 | 110 | await page.waitForSelector('[data-launched]'); |
34 | 111 | const element = await page.$('[data-launched]'); |
35 | 112 | expect(element).toBeTruthy(); |
36 | 113 | }); |
37 | 114 |
|
| 115 | + test('launch should run in the client for spa', async () => { |
| 116 | + await page.waitForSelector('[data-launch-env="client"]'); |
| 117 | + const element = await page.$('[data-launch-env="client"]'); |
| 118 | + expect(element).toBeTruthy(); |
| 119 | + }); |
| 120 | + |
| 121 | + test('hydrate should run', async () => { |
| 122 | + await page.waitForSelector('[data-hydrated]'); |
| 123 | + const element = await page.$('[data-hydrated]'); |
| 124 | + expect(element).toBeTruthy(); |
| 125 | + }); |
| 126 | + |
38 | 127 | test('update should run', async () => { |
39 | 128 | await page.waitForSelector('[data-updated]'); |
40 | 129 | const element = await page.$('[data-updated]'); |
|