Skip to content

Commit

Permalink
Add failing test for sveltejs#589
Browse files Browse the repository at this point in the history
  • Loading branch information
thgh committed Mar 2, 2019
1 parent 411e259 commit 9522cb4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
3 changes: 2 additions & 1 deletion test/apps/with-basepath/src/routes/index.svelte
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<h1>Great success!</h1>
<h1>Great success!</h1>
<a href="redirect-from">redirect from</a>
7 changes: 7 additions & 0 deletions test/apps/with-basepath/src/routes/redirect-from.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script context="module">
export function preload() {
this.redirect(301, 'redirect-to');
}
</script>

<h1>unredirected</h1>
1 change: 1 addition & 0 deletions test/apps/with-basepath/src/routes/redirect-to.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>redirected</h1>
44 changes: 43 additions & 1 deletion test/apps/with-basepath/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -11,6 +13,10 @@ describe('with-basepath', function() {
let page: puppeteer.Page;
let base: string;

let start: () => Promise<void>;
let prefetchRoutes: () => Promise<void>;
let title: () => Promise<string>;

// hooks
before(async () => {
await api.build({ cwd: __dirname });
Expand All @@ -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());
Expand Down Expand Up @@ -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'
);
});
});

0 comments on commit 9522cb4

Please sign in to comment.