velocious 1.0.27 → 1.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/spec/dummy/src/config/routes.js +2 -0
- package/spec/dummy/src/routes/_root/controller.js +11 -0
- package/spec/dummy/src/routes/projects/controller.js +0 -1
- package/spec/http-server/root-get-spec.js +26 -0
- package/src/database/query/index.js +1 -1
- package/src/routes/get-route.js +6 -2
- package/src/routes/resolver.js +3 -1
- package/src/testing/test.js +4 -2
package/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fetch from "node-fetch"
|
|
2
|
+
import Dummy from "../dummy/index.js"
|
|
3
|
+
|
|
4
|
+
describe("HttpServer", () => {
|
|
5
|
+
it("handles root get requests", async () => {
|
|
6
|
+
await Dummy.run(async () => {
|
|
7
|
+
const response = await fetch("http://localhost:3006/ping")
|
|
8
|
+
const text = await response.text()
|
|
9
|
+
|
|
10
|
+
expect(response.status).toEqual(200)
|
|
11
|
+
expect(response.statusText).toEqual("OK")
|
|
12
|
+
expect(text).toEqual("{\"message\":\"Pong\"}")
|
|
13
|
+
})
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it("returns a 404 error when a root get isn't found", async () => {
|
|
17
|
+
await Dummy.run(async () => {
|
|
18
|
+
const response = await fetch("http://localhost:3006/doesnt-exist")
|
|
19
|
+
const text = await response.text()
|
|
20
|
+
|
|
21
|
+
expect(response.status).toEqual(404)
|
|
22
|
+
expect(response.statusText).toEqual("Not Found")
|
|
23
|
+
expect(text).toEqual("Not found!\n")
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
})
|
package/src/routes/get-route.js
CHANGED
|
@@ -10,10 +10,14 @@ export default class VelociousRouteGetRoute extends BaseRoute {
|
|
|
10
10
|
this.regExp = new RegExp(`^(${escapeStringRegexp(name)})(.*)$`)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
matchWithPath({path}) {
|
|
14
|
-
|
|
13
|
+
matchWithPath({params, path}) {
|
|
14
|
+
const match = path.match(this.regExp)
|
|
15
|
+
|
|
16
|
+
if (match) {
|
|
15
17
|
const [_beginnigSlash, _matchedName, restPath] = match
|
|
16
18
|
|
|
19
|
+
params.action = this.name
|
|
20
|
+
|
|
17
21
|
return {restPath}
|
|
18
22
|
}
|
|
19
23
|
}
|
package/src/routes/resolver.js
CHANGED
|
@@ -33,7 +33,9 @@ export default class VelociousRoutesResolver {
|
|
|
33
33
|
controllerPath = "./built-in/errors/controller.js"
|
|
34
34
|
action = "notFound"
|
|
35
35
|
viewPath = await fs.realpath(`${__dirname}/built-in/errors`) // eslint-disable-line no-undef
|
|
36
|
-
} else if (action
|
|
36
|
+
} else if (action) {
|
|
37
|
+
if (!controller) controller = "_root"
|
|
38
|
+
|
|
37
39
|
controllerPath = `${this.configuration.getDirectory()}/src/routes/${controller}/controller.js`
|
|
38
40
|
viewPath = `${this.configuration.getDirectory()}/src/routes/${controller}`
|
|
39
41
|
} else {
|
package/src/testing/test.js
CHANGED
|
@@ -34,7 +34,7 @@ class ExpectToChange {
|
|
|
34
34
|
const difference = this.newCount - this.oldCount
|
|
35
35
|
|
|
36
36
|
if (difference != this.count) {
|
|
37
|
-
throw new Error(`Expected to change by ${count} but changed by ${difference}`)
|
|
37
|
+
throw new Error(`Expected to change by ${this.count} but changed by ${difference}`)
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -68,7 +68,7 @@ class Expect {
|
|
|
68
68
|
await expectation.runBefore()
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
await this._object()
|
|
71
|
+
const result = await this._object()
|
|
72
72
|
|
|
73
73
|
for (const expectation of this.expectations) {
|
|
74
74
|
await expectation.runAfter()
|
|
@@ -77,6 +77,8 @@ class Expect {
|
|
|
77
77
|
for (const expectation of this.expectations) {
|
|
78
78
|
await expectation.execute()
|
|
79
79
|
}
|
|
80
|
+
|
|
81
|
+
return result
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
toHaveAttributes(result) {
|