Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:sveltejs/sapper
Browse files Browse the repository at this point in the history
  • Loading branch information
artemjackson committed Dec 9, 2018
2 parents af2a792 + af0a7e0 commit e7cf9bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
23 changes: 9 additions & 14 deletions test/apps/AppRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ declare const prefetchRoutes: () => Promise<void>;
declare const prefetch: (href: string) => Promise<void>;
declare const goto: (href: string) => Promise<void>;

type StartOpts = {
requestInterceptor?: (interceptedRequst: puppeteer.Request) => any
};

export class AppRunner {
cwd: string;
entry: string;
Expand All @@ -24,7 +28,7 @@ export class AppRunner {
this.messages = [];
}

async start() {
async start({ requestInterceptor }: StartOpts = {}) {
this.port = await ports.find(3000);

this.proc = fork(this.entry, [], {
Expand All @@ -50,19 +54,10 @@ export class AppRunner {
}
});

await this.page.setRequestInterception(true);

this.page.on('request', interceptedRequest => {
if (/example\.com/.test(interceptedRequest.url())) {
interceptedRequest.respond({
status: 200,
contentType: 'text/html',
body: `<h1>external</h1>`
});
} else {
interceptedRequest.continue();
}
});
if (requestInterceptor) {
await this.page.setRequestInterception(true);
this.page.on('request', requestInterceptor);
}

return {
page: this.page,
Expand Down
14 changes: 13 additions & 1 deletion test/apps/redirects/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ describe('redirects', function() {
await build({ cwd: __dirname });

runner = new AppRunner(__dirname, '__sapper__/build/server/server.js');
({ base, page, start, prefetchRoutes, title } = await runner.start());
({ base, page, start, prefetchRoutes, title } = await runner.start({
requestInterceptor: (interceptedRequest) => {
if (/example\.com/.test(interceptedRequest.url())) {
interceptedRequest.respond({
status: 200,
contentType: 'text/html',
body: `<h1>external</h1>`
});
} else {
interceptedRequest.continue();
}
}
}));
});

after(() => runner.end());
Expand Down

0 comments on commit e7cf9bf

Please sign in to comment.