From 9522cb45396a8e4689c1435a053be8501f4b6c78 Mon Sep 17 00:00:00 2001 From: Thomas Ghysels Date: Sat, 2 Mar 2019 18:33:23 +0100 Subject: [PATCH] Add failing test for #589 --- .../with-basepath/src/routes/index.svelte | 3 +- .../src/routes/redirect-from.svelte | 7 +++ .../src/routes/redirect-to.svelte | 1 + test/apps/with-basepath/test.ts | 44 ++++++++++++++++++- 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 test/apps/with-basepath/src/routes/redirect-from.svelte create mode 100644 test/apps/with-basepath/src/routes/redirect-to.svelte diff --git a/test/apps/with-basepath/src/routes/index.svelte b/test/apps/with-basepath/src/routes/index.svelte index 0cc4b7267..45bc3a3fc 100644 --- a/test/apps/with-basepath/src/routes/index.svelte +++ b/test/apps/with-basepath/src/routes/index.svelte @@ -1 +1,2 @@ -

Great success!

\ No newline at end of file +

Great success!

+redirect from diff --git a/test/apps/with-basepath/src/routes/redirect-from.svelte b/test/apps/with-basepath/src/routes/redirect-from.svelte new file mode 100644 index 000000000..45805e117 --- /dev/null +++ b/test/apps/with-basepath/src/routes/redirect-from.svelte @@ -0,0 +1,7 @@ + + +

unredirected

\ No newline at end of file diff --git a/test/apps/with-basepath/src/routes/redirect-to.svelte b/test/apps/with-basepath/src/routes/redirect-to.svelte new file mode 100644 index 000000000..eeb0dfc2c --- /dev/null +++ b/test/apps/with-basepath/src/routes/redirect-to.svelte @@ -0,0 +1 @@ +

redirected

\ No newline at end of file diff --git a/test/apps/with-basepath/test.ts b/test/apps/with-basepath/test.ts index 5741d1bb8..bfb50d8a9 100644 --- a/test/apps/with-basepath/test.ts +++ b/test/apps/with-basepath/test.ts @@ -3,6 +3,8 @@ import * as puppeteer from 'puppeteer'; import * as api from '../../../api'; import { walk } from '../../utils'; import { AppRunner } from '../AppRunner'; +import { wait } from '../../utils'; + describe('with-basepath', function() { this.timeout(10000); @@ -11,6 +13,10 @@ describe('with-basepath', function() { let page: puppeteer.Page; let base: string; + let start: () => Promise; + let prefetchRoutes: () => Promise; + let title: () => Promise; + // hooks before(async () => { await api.build({ cwd: __dirname }); @@ -21,7 +27,7 @@ describe('with-basepath', function() { }); runner = new AppRunner(__dirname, '__sapper__/build/server/server.js'); - ({ base, page } = await runner.start()); + ({ base, start, page, prefetchRoutes, title } = await runner.start()); }); after(() => runner.end()); @@ -56,8 +62,44 @@ describe('with-basepath', function() { assert.deepEqual(non_client_assets, [ 'custom-basepath/global.css', 'custom-basepath/index.html', + 'custom-basepath/redirect-from/index.html', + 'custom-basepath/redirect-to', 'custom-basepath/service-worker-index.html', 'custom-basepath/service-worker.js' ]); }); + + it('redirects on server', async () => { + console.log('base', base) + await page.goto(`${base}/custom-basepath/redirect-from`); + + assert.equal( + page.url(), + `${base}/custom-basepath/redirect-to` + ); + + assert.equal( + await title(), + 'redirected' + ); + }); + + it('redirects in client', async () => { + await page.goto(`${base}/custom-basepath`); + await start(); + await prefetchRoutes(); + + await page.click('[href="redirect-from"]'); + await wait(50); + + assert.equal( + page.url(), + `${base}/custom-basepath/redirect-to` + ); + + assert.equal( + await title(), + 'redirected' + ); + }); }); \ No newline at end of file