@tryghost/express-test 0.5.0 → 0.6.0
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/README.md +10 -0
- package/index.js +8 -0
- package/lib/agent.js +22 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -40,6 +40,16 @@ return await agent
|
|
|
40
40
|
This is an initial version for review. More docs coming if it works :)
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
### Assertion execution order
|
|
44
|
+
The order of *chained* assertion execution is NOT the order they were declared in. The framework follows the priority order of the assertion types:
|
|
45
|
+
1. `expect`
|
|
46
|
+
2. `expectHeader`
|
|
47
|
+
3. `expectStatus`
|
|
48
|
+
|
|
49
|
+
Meaning, any `expect` declarations would be asserted first following by `expectHeader` and `expectStatus` declarations.
|
|
50
|
+
|
|
51
|
+
The custom order is here to prioritize assertions with the most context first. The feature was added based on frustrations with frameworks like [superagent](https://github.com/visionmedia/superagent), which didn't provide enough information when the status code assertions failed.
|
|
52
|
+
|
|
43
53
|
## Develop
|
|
44
54
|
|
|
45
55
|
This is a mono repository, managed with [lerna](https://lernajs.io/).
|
package/index.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
1
|
module.exports = require('./lib/agent');
|
|
2
|
+
|
|
3
|
+
// NOTE: exposing jest-snapshot as a part of express-test to avoid
|
|
4
|
+
// version missmatching on the client side
|
|
5
|
+
module.exports.snapshot = {
|
|
6
|
+
mochaHooks: require('@tryghost/jest-snapshot').mochaHooks,
|
|
7
|
+
any: require('@tryghost/jest-snapshot').any,
|
|
8
|
+
stringMatching: require('@tryghost/jest-snapshot').stringMatching
|
|
9
|
+
};
|
package/lib/agent.js
CHANGED
|
@@ -3,6 +3,14 @@ const ExpectRequest = require('./expect-request');
|
|
|
3
3
|
const {RequestOptions} = require('./request');
|
|
4
4
|
|
|
5
5
|
class Agent {
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} app instance of Express app
|
|
9
|
+
* @param {Object} [defaults]
|
|
10
|
+
* @param {string} [defaults.baseUrl]
|
|
11
|
+
* @param {Object} [defaults.headers]
|
|
12
|
+
* @param {Object} [defaults.queryParams] - custom query params to append to each request
|
|
13
|
+
*/
|
|
6
14
|
constructor(app, defaults = {}) {
|
|
7
15
|
this.app = app;
|
|
8
16
|
this.defaults = defaults;
|
|
@@ -15,6 +23,20 @@ class Agent {
|
|
|
15
23
|
url = `/${this.defaults.baseUrl}/${url}`.replace(/(^|[^:])\/\/+/g, '$1/');
|
|
16
24
|
}
|
|
17
25
|
|
|
26
|
+
if (this.defaults.queryParams) {
|
|
27
|
+
const searchParams = new URLSearchParams();
|
|
28
|
+
|
|
29
|
+
for (const key in this.defaults.queryParams) {
|
|
30
|
+
searchParams.append(key, this.defaults.queryParams[key]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (url.includes('?')) {
|
|
34
|
+
url = `${url}&${searchParams.toString()}`;
|
|
35
|
+
} else {
|
|
36
|
+
url = `${url}?${searchParams.toString()}`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
18
40
|
return url;
|
|
19
41
|
}
|
|
20
42
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/express-test",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"repository": "https://github.com/TryGhost/framework/tree/main/packages/express-test",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"dev": "echo \"Implement me!\"",
|
|
10
|
-
"test": "NODE_ENV=testing c8 mocha --require ./test/utils/overrides.js './test/**/*.test.js'",
|
|
10
|
+
"test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha --require ./test/utils/overrides.js './test/**/*.test.js'",
|
|
11
11
|
"lint": "eslint . --ext .js --cache",
|
|
12
12
|
"posttest": "yarn lint"
|
|
13
13
|
},
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"c8": "7.11.0",
|
|
23
|
-
"express": "4.17.
|
|
23
|
+
"express": "4.17.3",
|
|
24
24
|
"express-session": "1.17.2",
|
|
25
|
-
"mocha": "9.2.
|
|
25
|
+
"mocha": "9.2.1",
|
|
26
26
|
"sinon": "13.0.1"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@tryghost/jest-snapshot": "^0.3.
|
|
29
|
+
"@tryghost/jest-snapshot": "^0.3.3",
|
|
30
30
|
"cookiejar": "^2.1.3",
|
|
31
31
|
"reqresnext": "^1.7.0"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "64606b3f53d3ec8e6bf988f694d9dc4bbf5fac70"
|
|
34
34
|
}
|