From d6d9dd1e424bd3301e94124fb72f8c850b63017c Mon Sep 17 00:00:00 2001 From: Anderson Leite Date: Sat, 24 Nov 2018 16:11:25 -0800 Subject: [PATCH] Tests for "ssr: true" on dynamic pages (#5728) **What's this PR?** Based on the feedback on [this PR](https://github.com/zeit/next.js/pull/5722) @timneutkens asked me to create a test for `ssr: true` **What's it do?** - adds a test for setting `ssr: true` - /basic - adds a test for setting `ssr: true` - /production --- .../basic/pages/dynamic/ssr-true.js | 5 +++++ test/integration/basic/test/dynamic.js | 22 ++++++++++++++++++- .../production/pages/dynamic/ssr-true.js | 5 +++++ test/integration/production/test/dynamic.js | 21 +++++++++++++++++- 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 test/integration/basic/pages/dynamic/ssr-true.js create mode 100644 test/integration/production/pages/dynamic/ssr-true.js diff --git a/test/integration/basic/pages/dynamic/ssr-true.js b/test/integration/basic/pages/dynamic/ssr-true.js new file mode 100644 index 00000000..8488001b --- /dev/null +++ b/test/integration/basic/pages/dynamic/ssr-true.js @@ -0,0 +1,5 @@ +import dynamic from 'next/dynamic' + +const Hello = dynamic(import('../../components/hello1'), { ssr: true }) + +export default Hello diff --git a/test/integration/basic/test/dynamic.js b/test/integration/basic/test/dynamic.js index c88984ab..0331616d 100644 --- a/test/integration/basic/test/dynamic.js +++ b/test/integration/basic/test/dynamic.js @@ -54,7 +54,7 @@ export default (context, render) => { }) }) describe('ssr:false option', () => { - it('Should render loading on the server side', async () => { + it('should render loading on the server side', async () => { const $ = await get$('/dynamic/no-ssr') expect($('body').html()).not.toContain('"dynamicIds"') expect($('p').text()).toBe('loading...') @@ -73,6 +73,26 @@ export default (context, render) => { }) }) + describe('ssr:true option', () => { + it('Should render the component on the server side', async () => { + const $ = await get$('/dynamic/ssr-true') + expect($('body').html()).toContain('"dynamicIds"') + expect($('p').text()).toBe('Hello World 1') + }) + + it('should render the component on client side', async () => { + let browser + try { + browser = await webdriver(context.appPort, '/dynamic/ssr-true') + await check(() => browser.elementByCss('body').text(), /Hello World 1/) + } finally { + if (browser) { + browser.close() + } + } + }) + }) + describe('custom chunkfilename', () => { it('should render the correct filename', async () => { const $ = await get$('/dynamic/chunkfilename') diff --git a/test/integration/production/pages/dynamic/ssr-true.js b/test/integration/production/pages/dynamic/ssr-true.js new file mode 100644 index 00000000..8488001b --- /dev/null +++ b/test/integration/production/pages/dynamic/ssr-true.js @@ -0,0 +1,5 @@ +import dynamic from 'next/dynamic' + +const Hello = dynamic(import('../../components/hello1'), { ssr: true }) + +export default Hello diff --git a/test/integration/production/test/dynamic.js b/test/integration/production/test/dynamic.js index d74b1391..719061c1 100644 --- a/test/integration/production/test/dynamic.js +++ b/test/integration/production/test/dynamic.js @@ -30,7 +30,7 @@ export default (context, render) => { }) }) describe('ssr:false option', () => { - it('Should render loading on the server side', async () => { + it('should render loading on the server side', async () => { const $ = await get$('/dynamic/no-ssr') expect($('p').text()).toBe('loading...') }) @@ -48,6 +48,25 @@ export default (context, render) => { }) }) + describe('ssr:true option', () => { + it('should render the component on the server side', async () => { + const $ = await get$('/dynamic/ssr-true') + expect($('p').text()).toBe('Hello World 1') + }) + + it('should render the component on client side', async () => { + let browser + try { + browser = await webdriver(context.appPort, '/dynamic/ssr-true') + await check(() => browser.elementByCss('body').text(), /Hello World 1/) + } finally { + if (browser) { + browser.close() + } + } + }) + }) + describe('custom loading', () => { it('should render custom loading on the server side when `ssr:false` and `loading` is provided', async () => { const $ = await get$('/dynamic/no-ssr-custom-loading')