-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a5f3ac
commit 121addb
Showing
12 changed files
with
88 additions
and
7 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
4 changes: 4 additions & 0 deletions
4
jest/edgeworkers/examples/respond-from-edgeworkers/respondwith/was-terminated/bundle.json
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,4 @@ | ||
{ | ||
"edgeworker-version": "0.1", | ||
"description" : "Returns true if respondWith() has been called in the current handler and false otherwise." | ||
} |
5 changes: 5 additions & 0 deletions
5
jest/edgeworkers/examples/respond-from-edgeworkers/respondwith/was-terminated/main.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,5 @@ | ||
export function onClientResponse(request, response) { | ||
request.respondWith(333, {}, ""); | ||
request.wasTerminated(); | ||
request.respondWith(222, {}, "GOOD: wasTerminated worked!"); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,28 @@ | ||
import { onClientResponse } from "../../../edgeworkers/examples/respond-from-edgeworkers/respondwith/was-terminated/main"; | ||
import Request from "request"; | ||
|
||
describe("demonstrates how an EdgeWorker can be used to see if respondWith() has been called.", () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test("Simple onClientResponse call to check that wasTerminated was called", () => { | ||
let requestMock = new Request(); | ||
requestMock.mockWasTerminated = true; | ||
|
||
onClientResponse(requestMock); | ||
expect(requestMock.respondWith).toHaveBeenCalledTimes(2); | ||
expect(requestMock.wasTerminated).toHaveBeenCalledTimes(1); | ||
expect(requestMock.mockWasTerminated).toBeTruthy(); | ||
}); | ||
|
||
test("Simple onClientResponse call to check that wasTerminated was not called", () => { | ||
let requestMock = new Request(); | ||
requestMock.mockWasTerminated = false; | ||
|
||
onClientResponse(requestMock); | ||
expect(requestMock.respondWith).toHaveBeenCalledTimes(2); | ||
expect(requestMock.wasTerminated).toHaveBeenCalledTimes(1); | ||
expect(requestMock.mockWasTerminated).not.toBeTruthy(); | ||
}); | ||
}); |
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
4 changes: 4 additions & 0 deletions
4
mocha/edgeworkers/examples/respond-from-edgeworkers/respondwith/was-terminated/bundle.json
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,4 @@ | ||
{ | ||
"edgeworker-version": "0.1", | ||
"description" : "Returns true if respondWith() has been called in the current handler and false otherwise." | ||
} |
5 changes: 5 additions & 0 deletions
5
mocha/edgeworkers/examples/respond-from-edgeworkers/respondwith/was-terminated/main.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,5 @@ | ||
export function onClientResponse(request, response) { | ||
request.respondWith(333, {}, ""); | ||
request.wasTerminated(); | ||
request.respondWith(222, {}, "GOOD: wasTerminated worked!"); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,31 @@ | ||
import { onClientResponse } from "../../../edgeworkers/examples/respond-from-edgeworkers/respondwith/was-terminated/main"; | ||
import Request from "request"; | ||
|
||
const sinon = require("sinon"); | ||
const expect = require('expect.js'); | ||
|
||
describe("demonstrates how an EdgeWorker can be used to see if respondWith() has been called.", () => { | ||
afterEach(function () { | ||
sinon.reset(); | ||
}); | ||
|
||
it("Simple onClientResponse call to check that wasTerminated was called", () => { | ||
let requestMock = new Request(); | ||
requestMock.mockWasTerminated = true; | ||
|
||
onClientResponse(requestMock); | ||
expect(requestMock.respondWith.callCount).to.be(2); | ||
expect(requestMock.wasTerminated.callCount).to.be(1); | ||
expect(requestMock.mockWasTerminated).to.be.true; | ||
}); | ||
|
||
it("Simple onClientResponse call to check that wasTerminated was not called", () => { | ||
let requestMock = new Request(); | ||
requestMock.mockWasTerminated = false; | ||
|
||
onClientResponse(requestMock); | ||
expect(requestMock.respondWith.callCount).to.be(2); | ||
expect(requestMock.wasTerminated.callCount).to.be(1); | ||
expect(requestMock.mockWasTerminated).to.be.false; | ||
}); | ||
}); |