mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
test(service-worker): simplify how redirects are defined in MockServerState (#47260)
Previously, the `MockServerStateBuilder#withRedirect()` method did two things: (a) define a redirect from one path to another and (b) specify the contents of the redirect destination. This was confusing, because it deviated from the regular way of specifying file contents, which is via a `MockFileSystem` instance. This commit slightly simplifies the process of defining redirects by having the `withRedirect()` method only define the redirect and let the contents of the redirect destination be specified as usual via `MockFileSystem`. This makes `MockFileSystem` the single source of truth for file contents used with `MockServerState`. PR Close #47260
This commit is contained in:
parent
e842fd75ac
commit
d63fe2fa46
2 changed files with 13 additions and 14 deletions
|
|
@ -32,6 +32,7 @@ const dist =
|
|||
.addFile('/qux.txt', 'this is qux')
|
||||
.addFile('/quux.txt', 'this is quux')
|
||||
.addFile('/quuux.txt', 'this is quuux')
|
||||
.addFile('/redirect-target.txt', 'this was a redirect')
|
||||
.addFile('/lazy/unchanged1.txt', 'this is unchanged (1)')
|
||||
.addFile('/lazy/unchanged2.txt', 'this is unchanged (2)')
|
||||
.addUnhashedFile('/unhashed/a.txt', 'this is unhashed', {'Cache-Control': 'max-age=10'})
|
||||
|
|
@ -48,6 +49,7 @@ const distUpdate =
|
|||
.addFile('/qux.txt', 'this is qux v2')
|
||||
.addFile('/quux.txt', 'this is quux v2')
|
||||
.addFile('/quuux.txt', 'this is quuux v2')
|
||||
.addFile('/redirect-target.txt', 'this was a redirect')
|
||||
.addFile('/lazy/unchanged1.txt', 'this is unchanged (1)')
|
||||
.addFile('/lazy/unchanged2.txt', 'this is unchanged (2)')
|
||||
.addUnhashedFile('/unhashed/a.txt', 'this is unhashed v2', {'Cache-Control': 'max-age=10'})
|
||||
|
|
@ -265,23 +267,21 @@ const manifestUpdate: Manifest = {
|
|||
hashTable: tmpHashTableForFs(distUpdate),
|
||||
};
|
||||
|
||||
const serverBuilderBase =
|
||||
new MockServerStateBuilder()
|
||||
.withStaticFiles(dist)
|
||||
.withRedirect('/redirected.txt', '/redirect-target.txt', 'this was a redirect')
|
||||
.withError('/error.txt');
|
||||
const serverBuilderBase = new MockServerStateBuilder()
|
||||
.withStaticFiles(dist)
|
||||
.withRedirect('/redirected.txt', '/redirect-target.txt')
|
||||
.withError('/error.txt');
|
||||
|
||||
const server = serverBuilderBase.withManifest(manifest).build();
|
||||
|
||||
const serverRollback =
|
||||
serverBuilderBase.withManifest({...manifest, timestamp: manifest.timestamp + 1}).build();
|
||||
|
||||
const serverUpdate =
|
||||
new MockServerStateBuilder()
|
||||
.withStaticFiles(distUpdate)
|
||||
.withManifest(manifestUpdate)
|
||||
.withRedirect('/redirected.txt', '/redirect-target.txt', 'this was a redirect')
|
||||
.build();
|
||||
const serverUpdate = new MockServerStateBuilder()
|
||||
.withStaticFiles(distUpdate)
|
||||
.withManifest(manifestUpdate)
|
||||
.withRedirect('/redirected.txt', '/redirect-target.txt')
|
||||
.build();
|
||||
|
||||
const brokenServer =
|
||||
new MockServerStateBuilder().withStaticFiles(brokenFs).withManifest(brokenManifest).build();
|
||||
|
|
|
|||
|
|
@ -104,9 +104,8 @@ export class MockServerStateBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
withRedirect(from: string, to: string, toContents: string): MockServerStateBuilder {
|
||||
this.resources.set(from, new MockResponse(toContents, {redirected: true, url: to}));
|
||||
this.resources.set(to, new MockResponse(toContents));
|
||||
withRedirect(from: string, to: string): MockServerStateBuilder {
|
||||
this.resources.set(from, new MockResponse('', {redirected: true, url: to}));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue