From ed19a19fedc124d3f067aae986074a2ff54c8ba4 Mon Sep 17 00:00:00 2001 From: Artyom Stepanishchev Date: Sun, 9 Dec 2018 17:28:59 +0300 Subject: [PATCH] Fixed tests for node 6 --- test/apps/AppRunner.ts | 23 +++++++++-------------- test/apps/redirects/test.ts | 14 +++++++++++++- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/test/apps/AppRunner.ts b/test/apps/AppRunner.ts index 09653296c..84dd6b627 100644 --- a/test/apps/AppRunner.ts +++ b/test/apps/AppRunner.ts @@ -8,6 +8,10 @@ declare const prefetchRoutes: () => Promise; declare const prefetch: (href: string) => Promise; declare const goto: (href: string) => Promise; +type StartOpts = { + requestInterceptor?: (interceptedRequst: puppeteer.Request) => any +}; + export class AppRunner { cwd: string; entry: string; @@ -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, [], { @@ -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: `

external

` - }); - } else { - interceptedRequest.continue(); - } - }); + if (requestInterceptor) { + await this.page.setRequestInterception(true); + this.page.on('request', requestInterceptor); + } return { page: this.page, diff --git a/test/apps/redirects/test.ts b/test/apps/redirects/test.ts index 719a92c47..50d65074f 100644 --- a/test/apps/redirects/test.ts +++ b/test/apps/redirects/test.ts @@ -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: `

external

` + }); + } else { + interceptedRequest.continue(); + } + } + })); }); after(() => runner.end());