-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Abort and passthrough from an intercept (#57)
- Loading branch information
1 parent
0a3d591
commit 4ebacb8
Showing
7 changed files
with
366 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const ABORT = Symbol(); | ||
const PASSTHROUGH = Symbol(); | ||
|
||
function setDefaults(interceptor) { | ||
interceptor[ABORT] = false; | ||
interceptor[PASSTHROUGH] = false; | ||
} | ||
|
||
export default class Interceptor { | ||
constructor() { | ||
setDefaults(this); | ||
} | ||
|
||
abort() { | ||
setDefaults(this); | ||
this[ABORT] = true; | ||
} | ||
|
||
passthrough() { | ||
setDefaults(this); | ||
this[PASSTHROUGH] = true; | ||
} | ||
|
||
get shouldAbort() { | ||
return this[ABORT]; | ||
} | ||
|
||
get shouldPassthrough() { | ||
return this[PASSTHROUGH]; | ||
} | ||
|
||
get shouldIntercept() { | ||
return !this.shouldAbort && !this.shouldPassthrough; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/@pollyjs/adapter/tests/unit/-private/interceptor-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import Interceptor from '../../../src/-private/interceptor'; | ||
|
||
describe('Unit | Private | Interceptor', function() { | ||
it('should exist', function() { | ||
expect(Interceptor).to.be.a('function'); | ||
}); | ||
|
||
it('should have the correct defaults', function() { | ||
const interceptor = new Interceptor(); | ||
|
||
expect(interceptor.shouldAbort).to.be.false; | ||
expect(interceptor.shouldPassthrough).to.be.false; | ||
expect(interceptor.shouldIntercept).to.be.true; | ||
}); | ||
|
||
it('should disable passthrough when calling abort and vise versa', function() { | ||
const interceptor = new Interceptor(); | ||
|
||
expect(interceptor.shouldAbort).to.be.false; | ||
expect(interceptor.shouldPassthrough).to.be.false; | ||
|
||
interceptor.abort(); | ||
expect(interceptor.shouldAbort).to.be.true; | ||
expect(interceptor.shouldPassthrough).to.be.false; | ||
|
||
interceptor.passthrough(); | ||
expect(interceptor.shouldAbort).to.be.false; | ||
expect(interceptor.shouldPassthrough).to.be.true; | ||
}); | ||
|
||
it('.abort()', function() { | ||
const interceptor = new Interceptor(); | ||
|
||
expect(interceptor.shouldAbort).to.be.false; | ||
expect(interceptor.shouldIntercept).to.be.true; | ||
|
||
interceptor.abort(); | ||
|
||
expect(interceptor.shouldAbort).to.be.true; | ||
expect(interceptor.shouldIntercept).to.be.false; | ||
}); | ||
|
||
it('.passthrough()', function() { | ||
const interceptor = new Interceptor(); | ||
|
||
expect(interceptor.shouldPassthrough).to.be.false; | ||
expect(interceptor.shouldIntercept).to.be.true; | ||
|
||
interceptor.passthrough(); | ||
|
||
expect(interceptor.shouldPassthrough).to.be.true; | ||
expect(interceptor.shouldIntercept).to.be.false; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...Rest-Persister_112800326/should-be-able-to-abort-from-an-intercept_68559697/recording.har
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{ | ||
"log": { | ||
"_recordingName": "@pollyjs/core/Integration | Adapters/Fetch Adapter + Rest Persister/should be able to abort from an intercept", | ||
"browser": { | ||
"name": "Chrome", | ||
"version": "67.0" | ||
}, | ||
"creator": { | ||
"name": "Polly.JS", | ||
"version": "0.5.0" | ||
}, | ||
"entries": [ | ||
{ | ||
"_id": "1bcdb30445bfd8996055be3579e6c9f2", | ||
"_order": 0, | ||
"cache": {}, | ||
"request": { | ||
"bodySize": 0, | ||
"cookies": [], | ||
"headers": [], | ||
"headersSize": 212, | ||
"httpVersion": "HTTP/1.1", | ||
"method": "GET", | ||
"queryString": [], | ||
"url": "http://localhost:7357/api/db/-pollyjs_2160168770%2Fcore_3713949822%2FIntegration-Adapters_529408267%2FFetch-Adapter-Rest-Persister_112800326%2Fshould-be-able-to-abort-from-an-intercept_68559697" | ||
}, | ||
"response": { | ||
"bodySize": 0, | ||
"content": { | ||
"mimeType": "text/plain", | ||
"size": 0 | ||
}, | ||
"cookies": [], | ||
"headers": [ | ||
{ | ||
"name": "access-control-allow-origin", | ||
"value": "*" | ||
}, | ||
{ | ||
"name": "connection", | ||
"value": "close" | ||
}, | ||
{ | ||
"name": "content-length", | ||
"value": "0" | ||
}, | ||
{ | ||
"name": "date", | ||
"value": "Tue, 03 Jul 2018 21:10:04 GMT" | ||
}, | ||
{ | ||
"name": "x-powered-by", | ||
"value": "Express" | ||
} | ||
], | ||
"headersSize": 132, | ||
"httpVersion": "HTTP/1.1", | ||
"redirectURL": "", | ||
"status": 404, | ||
"statusText": "Not Found" | ||
}, | ||
"startedDateTime": "2018-07-03T21:10:04.607Z", | ||
"time": 13, | ||
"timings": { | ||
"blocked": -1, | ||
"connect": -1, | ||
"dns": -1, | ||
"receive": 0, | ||
"send": 0, | ||
"ssl": -1, | ||
"wait": 13 | ||
} | ||
} | ||
], | ||
"pages": [], | ||
"version": "1.2" | ||
} | ||
} |
Oops, something went wrong.