forked from gridsome/gridsome
-
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.
fix(api): use express app in configureServer (gridsome#668)
- Loading branch information
Showing
6 changed files
with
69 additions
and
12 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,30 @@ | ||
const Server = require('../Server') | ||
const App = require('../../app/App') | ||
const request = require('supertest') | ||
const { prepareUrls } = require('../utils') | ||
const { BOOTSTRAP_CONFIG } = require('../../utils/constants') | ||
|
||
test('api.configureServer()', async () => { | ||
const urls = prepareUrls('localhost', 8080) | ||
const callback = jest.fn((req, res) => res.send('Hello, world!')) | ||
const gridsome = await createApp(function (api) { | ||
api.configureServer(app => { | ||
app.get('/my-endpoint', callback) | ||
}) | ||
}) | ||
|
||
const server = new Server(gridsome, urls) | ||
const app = await server.createExpressApp() | ||
const res = await request(app).get('/my-endpoint') | ||
|
||
expect(res.text).toEqual('Hello, world!') | ||
expect(callback.mock.calls).toHaveLength(1) | ||
}) | ||
|
||
async function createApp(plugin) { | ||
const app = await new App(__dirname, { | ||
localConfig: { plugins: plugin ? [plugin] : [] } | ||
}) | ||
|
||
return app.bootstrap(BOOTSTRAP_CONFIG) | ||
} |
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 |
---|---|---|
|
@@ -4166,7 +4166,7 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.0.tgz#beb437e7022b3b6d49019d088665303ebe9c14ba" | ||
integrity sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg== | ||
|
||
cookiejar@^2.1.2: | ||
cookiejar@^2.1.0, cookiejar@^2.1.2: | ||
version "2.1.2" | ||
resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.1.2.tgz#dd8a235530752f988f9a0844f3fc589e3111125c" | ||
integrity sha512-Mw+adcfzPxcPeI+0WlvRrr/3lGVO0bD75SxX6811cxSh1Wbxx7xZBGK1eVtDf6si8rg2lhnUjsVLMFMfbRIuwA== | ||
|
@@ -6121,7 +6121,7 @@ forever-agent@~0.6.1: | |
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" | ||
integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE= | ||
|
||
form-data@^2.3.3: | ||
form-data@^2.3.1, form-data@^2.3.3: | ||
version "2.5.1" | ||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.5.1.tgz#f2cbec57b5e59e23716e128fe44d4e5dd23895f4" | ||
integrity sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA== | ||
|
@@ -9203,7 +9203,7 @@ merge2@^1.2.3: | |
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.2.4.tgz#c9269589e6885a60cf80605d9522d4b67ca646e3" | ||
integrity sha512-FYE8xI+6pjFOhokZu0We3S5NKCirLbCzSh2Usf3qEyr4X8U+0jNg9P8RZ4qz+V2UoECLVwSyzU3LxXBaLGtD3A== | ||
|
||
methods@^1.1.1, methods@~1.1.2: | ||
methods@^1.1.1, methods@^1.1.2, methods@~1.1.2: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" | ||
integrity sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4= | ||
|
@@ -9252,7 +9252,7 @@ mime-types@^2.1.12, mime-types@^2.1.21, mime-types@^2.1.24, mime-types@~2.1.19, | |
dependencies: | ||
mime-db "1.40.0" | ||
|
||
[email protected]: | ||
[email protected], mime@^1.4.1: | ||
version "1.6.0" | ||
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" | ||
integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== | ||
|
@@ -11307,7 +11307,7 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc" | ||
integrity sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ== | ||
|
||
qs@^6.5.2, qs@^6.6.0: | ||
qs@^6.5.1, qs@^6.5.2, qs@^6.6.0: | ||
version "6.8.0" | ||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.8.0.tgz#87b763f0d37ca54200334cd57bb2ef8f68a1d081" | ||
integrity sha512-tPSkj8y92PfZVbinY1n84i1Qdx75lZjMQYx9WZhnkofyxzw2r7Ho39G3/aEvSUdebxpnnM4LZJCtvE/Aq3+s9w== | ||
|
@@ -12813,6 +12813,22 @@ stylehacks@^4.0.0: | |
postcss "^7.0.0" | ||
postcss-selector-parser "^3.0.0" | ||
|
||
superagent@^3.8.3: | ||
version "3.8.3" | ||
resolved "https://registry.yarnpkg.com/superagent/-/superagent-3.8.3.tgz#460ea0dbdb7d5b11bc4f78deba565f86a178e128" | ||
integrity sha512-GLQtLMCoEIK4eDv6OGtkOoSMt3D+oq0y3dsxMuYuDvaNUvuT8eFBuLmfR0iYYzHC1e8hpzC6ZsxbuP6DIalMFA== | ||
dependencies: | ||
component-emitter "^1.2.0" | ||
cookiejar "^2.1.0" | ||
debug "^3.1.0" | ||
extend "^3.0.0" | ||
form-data "^2.3.1" | ||
formidable "^1.2.0" | ||
methods "^1.1.1" | ||
mime "^1.4.1" | ||
qs "^6.5.1" | ||
readable-stream "^2.3.5" | ||
|
||
superagent@^4.0.0: | ||
version "4.1.0" | ||
resolved "https://registry.yarnpkg.com/superagent/-/superagent-4.1.0.tgz#c465c2de41df2b8d05c165cbe403e280790cdfd5" | ||
|
@@ -12828,6 +12844,14 @@ superagent@^4.0.0: | |
qs "^6.6.0" | ||
readable-stream "^3.0.6" | ||
|
||
supertest@^4.0.2: | ||
version "4.0.2" | ||
resolved "https://registry.yarnpkg.com/supertest/-/supertest-4.0.2.tgz#c2234dbdd6dc79b6f15b99c8d6577b90e4ce3f36" | ||
integrity sha512-1BAbvrOZsGA3YTCWqbmh14L0YEq0EGICX/nBnfkfVJn7SrxQV1I3pMYjSzG9y/7ZU2V9dWqyqk2POwxlb09duQ== | ||
dependencies: | ||
methods "^1.1.2" | ||
superagent "^3.8.3" | ||
|
||
supports-color@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" | ||
|