-
Notifications
You must be signed in to change notification settings - Fork 0
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
e5f8e48
commit 05b9c23
Showing
8 changed files
with
228 additions
and
100 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
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,103 @@ | ||
"use strict"; | ||
|
||
// deps | ||
|
||
// natives | ||
const { join } = require("path"); | ||
const { parse } = require("url"); | ||
const { strictEqual } = require("assert"); | ||
const { createServer } = require("http"); | ||
|
||
// locals | ||
|
||
const LocalOrchestrator = require(join(__dirname, "utils", "Orchestrator", "LocalOrchestrator.js")); | ||
const tests = require(join(__dirname, "utils", "Server", "tests.js")); | ||
|
||
// consts | ||
|
||
const GOOD_OPTIONS = { | ||
"packageFile": join(__dirname, "..", "package.json"), | ||
"descriptorFile": join(__dirname, "utils", "Descriptor.json"), | ||
"mediatorFile": join(__dirname, "utils", "Mediator", "LocalMediator.js"), | ||
"serverFile": join(__dirname, "..", "lib", "components", "Server.js") | ||
}; | ||
|
||
const HERITED_OPTIONS = { | ||
"packageFile": join(__dirname, "..", "package.json"), | ||
"descriptorFile": join(__dirname, "utils", "Descriptor.json"), | ||
"mediatorFile": join(__dirname, "utils", "Mediator", "HeritedMediator.js"), | ||
"serverFile": join(__dirname, "utils", "Server", "HeritedServer.js") | ||
}; | ||
|
||
// tests | ||
|
||
describe("Orchestrator / request / http", () => { | ||
|
||
let runningServer = null; | ||
const orchestrator = new LocalOrchestrator(HERITED_OPTIONS); | ||
|
||
before(() => { | ||
|
||
return orchestrator.load().then(() => { | ||
return orchestrator.init(); | ||
}).then(() => { | ||
|
||
const port = parseInt(parse(orchestrator._Descriptor.servers[0].url).port, 10); | ||
|
||
return new Promise((resolve) => { | ||
|
||
runningServer = createServer((req, res) => { | ||
|
||
orchestrator.appMiddleware(req, res, () => { | ||
|
||
res.writeHead(404, { | ||
"Content-Type": "application/json; charset=utf-8" | ||
}); | ||
|
||
res.end(JSON.stringify({ | ||
"code": "404", | ||
"message": "Unknown page" | ||
})); | ||
|
||
}); | ||
|
||
}).listen(port, resolve); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
after(() => { | ||
|
||
return orchestrator.release().then(() => { | ||
return orchestrator.destroy(); | ||
}).then(() => { | ||
|
||
return runningServer ? new Promise((resolve) => { | ||
|
||
runningServer.close(() => { | ||
runningServer = null; | ||
resolve(); | ||
}); | ||
|
||
}) : Promise.resolve(); | ||
|
||
}); | ||
|
||
}); | ||
|
||
it("should test app middleware without Server", () => { | ||
|
||
const res = new LocalOrchestrator(GOOD_OPTIONS).appMiddleware(null, null, () => { | ||
return false; | ||
}); | ||
|
||
strictEqual(typeof res, "undefined", "Generated result is not undefined"); | ||
|
||
}); | ||
|
||
tests(orchestrator); | ||
|
||
}); |
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
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
Oops, something went wrong.