@opra/testing 0.14.0 → 0.16.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/cjs/api-expect/api-expect-collection.js +1 -0
- package/cjs/api-expect/api-expect-error.js +1 -0
- package/cjs/api-expect/api-expect-object.js +1 -0
- package/cjs/api-expect/api-expect-operation-result.js +1 -0
- package/cjs/api-expect/api-expect.js +4 -1
- package/cjs/index.js +1 -1
- package/cjs/jest-extend/common.extend.js +1 -1
- package/cjs/jest-extend/index.js +4 -0
- package/cjs/test-client.js +7 -1
- package/esm/api-expect/api-expect-collection.js +28 -21
- package/esm/api-expect/api-expect-error.js +12 -6
- package/esm/api-expect/api-expect-object.js +10 -4
- package/esm/api-expect/api-expect-operation-result.js +6 -1
- package/esm/api-expect/api-expect.js +17 -10
- package/esm/index.js +5 -2
- package/esm/jest-extend/common.extend.js +12 -9
- package/esm/jest-extend/index.js +4 -0
- package/esm/test-client.js +21 -13
- package/esm/utils/is-absolute-url.util.js +7 -3
- package/esm/utils/object-matches.util.js +5 -1
- package/package.json +7 -6
- package/{esm → types}/api-expect/api-expect-collection.d.ts +3 -1
- package/{esm → types}/api-expect/api-expect-error.d.ts +2 -1
- package/{esm → types}/api-expect/api-expect-object.d.ts +2 -1
- package/{esm → types}/api-expect/api-expect-operation-result.d.ts +2 -1
- package/{esm → types}/api-expect/api-expect.d.ts +2 -1
- package/types/index.d.ts +2 -0
- package/types/jest-extend/index.d.ts +1 -0
- package/types/test-client.d.ts +18 -0
- package/esm/index.d.ts +0 -2
- package/esm/test-client.d.ts +0 -16
- /package/{esm → types}/jest-extend/common.extend.d.ts +0 -0
- /package/{esm → types}/utils/is-absolute-url.util.d.ts +0 -0
- /package/{esm → types}/utils/object-matches.util.d.ts +0 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertFilter = exports.ApiExpectCollection = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
require("../jest-extend/index.js");
|
|
5
6
|
const lodash_isnil_1 = tslib_1.__importDefault(require("lodash.isnil"));
|
|
6
7
|
const lodash_omitby_1 = tslib_1.__importDefault(require("lodash.omitby"));
|
|
7
8
|
const rule_judgment_1 = tslib_1.__importDefault(require("rule-judgment"));
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ApiExpectError = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
require("../jest-extend/index.js");
|
|
5
6
|
const jest_matcher_utils_1 = tslib_1.__importDefault(require("jest-matcher-utils"));
|
|
6
7
|
const object_matches_util_js_1 = require("../utils/object-matches.util.js");
|
|
7
8
|
const api_expect_object_js_1 = require("./api-expect-object.js");
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ApiExpectObject = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
require("../jest-extend/index.js");
|
|
5
6
|
const lodash_isnil_1 = tslib_1.__importDefault(require("lodash.isnil"));
|
|
6
7
|
const lodash_omitby_1 = tslib_1.__importDefault(require("lodash.omitby"));
|
|
7
8
|
class ApiExpectObject {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ApiExpect = void 0;
|
|
4
|
+
require("../jest-extend/index.js");
|
|
4
5
|
const api_expect_collection_js_1 = require("./api-expect-collection.js");
|
|
5
6
|
const api_expect_error_js_1 = require("./api-expect-error.js");
|
|
6
7
|
const api_expect_object_js_1 = require("./api-expect-object.js");
|
|
@@ -20,8 +21,10 @@ class ApiExpect {
|
|
|
20
21
|
this._expect(this.response.status).toStrictEqual(status);
|
|
21
22
|
}
|
|
22
23
|
catch (e) {
|
|
24
|
+
const issues = this.response.body?.errors;
|
|
25
|
+
const issue = issues?.[0]?.message;
|
|
23
26
|
if (msg)
|
|
24
|
-
e.message = msg + '\n\n' + e.message;
|
|
27
|
+
e.message = msg + '\n\n' + (issue || e.message);
|
|
25
28
|
Error.captureStackTrace(e, this.toSuccess);
|
|
26
29
|
throw e;
|
|
27
30
|
}
|
package/cjs/index.js
CHANGED
|
@@ -10,7 +10,7 @@ expect.extend({
|
|
|
10
10
|
const filteredKeys = expectedKeys.filter(x => !objectKeys.includes(x));
|
|
11
11
|
const pass = !filteredKeys.length === !this.isNot;
|
|
12
12
|
if (!pass) {
|
|
13
|
-
const message = () => `Expects keys
|
|
13
|
+
const message = () => `Expects keys ${this.isNot ? 'not ' : ''}to contain: ${ansi_colors_1.default.yellow('' + expectedKeys)}\n` +
|
|
14
14
|
`${this.isNot ? 'Unsolicited' : 'Missing'} fields: ${ansi_colors_1.default.yellow('' + filteredKeys)}\n`;
|
|
15
15
|
return { message, pass: !!this.isNot };
|
|
16
16
|
}
|
package/cjs/test-client.js
CHANGED
|
@@ -7,11 +7,17 @@ const common_1 = require("@opra/common");
|
|
|
7
7
|
const node_client_1 = require("@opra/node-client");
|
|
8
8
|
const api_expect_js_1 = require("./api-expect/api-expect.js");
|
|
9
9
|
const is_absolute_url_util_js_1 = require("./utils/is-absolute-url.util.js");
|
|
10
|
-
class OpraTestClient extends node_client_1.
|
|
10
|
+
class OpraTestClient extends node_client_1.OpraHttpClient {
|
|
11
11
|
constructor(app, options) {
|
|
12
12
|
super('/', options);
|
|
13
13
|
this._server = app instanceof http_1.Server ? app : (0, http_1.createServer)(app);
|
|
14
14
|
}
|
|
15
|
+
collection(resourceName) {
|
|
16
|
+
return super.collection(resourceName);
|
|
17
|
+
}
|
|
18
|
+
singleton(resourceName) {
|
|
19
|
+
return super.singleton(resourceName);
|
|
20
|
+
}
|
|
15
21
|
async _fetch(urlString, req = {}) {
|
|
16
22
|
return new Promise((resolve, reject) => {
|
|
17
23
|
urlString = (0, is_absolute_url_util_js_1.isAbsoluteUrl)(urlString) ? urlString : (0, common_1.joinPath)('http://opra.test', urlString);
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertFilter = exports.ApiExpectCollection = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
require("../jest-extend/index.js");
|
|
6
|
+
const lodash_isnil_1 = tslib_1.__importDefault(require("lodash.isnil"));
|
|
7
|
+
const lodash_omitby_1 = tslib_1.__importDefault(require("lodash.omitby"));
|
|
8
|
+
const rule_judgment_1 = tslib_1.__importDefault(require("rule-judgment"));
|
|
9
|
+
const common_1 = require("@opra/common");
|
|
5
10
|
// @ts-ignore
|
|
6
|
-
const ruleJudgment = typeof
|
|
7
|
-
|
|
11
|
+
const ruleJudgment = typeof rule_judgment_1.default === 'object' ? rule_judgment_1.default.default : rule_judgment_1.default;
|
|
12
|
+
class ApiExpectCollection {
|
|
8
13
|
constructor(response, _isNot = false) {
|
|
9
14
|
this.response = response;
|
|
10
15
|
this._isNot = _isNot;
|
|
@@ -18,7 +23,7 @@ export class ApiExpectCollection {
|
|
|
18
23
|
}
|
|
19
24
|
toMatch(expected) {
|
|
20
25
|
try {
|
|
21
|
-
const v =
|
|
26
|
+
const v = (0, lodash_omitby_1.default)(expected, lodash_isnil_1.default);
|
|
22
27
|
for (const item of this.response.body) {
|
|
23
28
|
this._expect(item).toMatchObject(v);
|
|
24
29
|
}
|
|
@@ -128,11 +133,12 @@ export class ApiExpectCollection {
|
|
|
128
133
|
return out;
|
|
129
134
|
}
|
|
130
135
|
}
|
|
131
|
-
|
|
132
|
-
|
|
136
|
+
exports.ApiExpectCollection = ApiExpectCollection;
|
|
137
|
+
function convertFilter(str) {
|
|
138
|
+
const ast = typeof str === 'string' ? (0, common_1.parseFilter)(str) : str;
|
|
133
139
|
if (!ast)
|
|
134
140
|
return;
|
|
135
|
-
if (ast instanceof ComparisonExpression) {
|
|
141
|
+
if (ast instanceof common_1.ComparisonExpression) {
|
|
136
142
|
const left = convertFilter(ast.left);
|
|
137
143
|
const right = convertFilter(ast.right);
|
|
138
144
|
switch (ast.op) {
|
|
@@ -156,30 +162,31 @@ export function convertFilter(str) {
|
|
|
156
162
|
throw new Error(`ComparisonExpression operator (${ast.op}) not implemented yet`);
|
|
157
163
|
}
|
|
158
164
|
}
|
|
159
|
-
if (ast instanceof QualifiedIdentifier) {
|
|
165
|
+
if (ast instanceof common_1.QualifiedIdentifier) {
|
|
160
166
|
return ast.value;
|
|
161
167
|
}
|
|
162
|
-
if (ast instanceof NumberLiteral ||
|
|
163
|
-
ast instanceof StringLiteral ||
|
|
164
|
-
ast instanceof BooleanLiteral ||
|
|
165
|
-
ast instanceof NullLiteral ||
|
|
166
|
-
ast instanceof DateLiteral ||
|
|
167
|
-
ast instanceof TimeLiteral) {
|
|
168
|
+
if (ast instanceof common_1.NumberLiteral ||
|
|
169
|
+
ast instanceof common_1.StringLiteral ||
|
|
170
|
+
ast instanceof common_1.BooleanLiteral ||
|
|
171
|
+
ast instanceof common_1.NullLiteral ||
|
|
172
|
+
ast instanceof common_1.DateLiteral ||
|
|
173
|
+
ast instanceof common_1.TimeLiteral) {
|
|
168
174
|
return ast.value;
|
|
169
175
|
}
|
|
170
|
-
if (ast instanceof ArrayExpression) {
|
|
176
|
+
if (ast instanceof common_1.ArrayExpression) {
|
|
171
177
|
return ast.items.map(convertFilter);
|
|
172
178
|
}
|
|
173
|
-
if (ast instanceof LogicalExpression) {
|
|
179
|
+
if (ast instanceof common_1.LogicalExpression) {
|
|
174
180
|
if (ast.op === 'or')
|
|
175
181
|
return { $or: ast.items.map(convertFilter) };
|
|
176
182
|
return { $and: ast.items.map(convertFilter) };
|
|
177
183
|
}
|
|
178
|
-
if (ast instanceof ArrayExpression) {
|
|
184
|
+
if (ast instanceof common_1.ArrayExpression) {
|
|
179
185
|
return ast.items.map(convertFilter);
|
|
180
186
|
}
|
|
181
|
-
if (ast instanceof ParenthesesExpression) {
|
|
187
|
+
if (ast instanceof common_1.ParenthesesExpression) {
|
|
182
188
|
return convertFilter(ast.expression);
|
|
183
189
|
}
|
|
184
190
|
throw new Error(`${ast.kind} is not implemented yet`);
|
|
185
191
|
}
|
|
192
|
+
exports.convertFilter = convertFilter;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiExpectError = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
require("../jest-extend/index.js");
|
|
6
|
+
const jest_matcher_utils_1 = tslib_1.__importDefault(require("jest-matcher-utils"));
|
|
7
|
+
const object_matches_util_js_1 = require("../utils/object-matches.util.js");
|
|
8
|
+
const api_expect_object_js_1 = require("./api-expect-object.js");
|
|
9
|
+
class ApiExpectError extends api_expect_object_js_1.ApiExpectObject {
|
|
5
10
|
constructor(response) {
|
|
6
11
|
super(response);
|
|
7
12
|
this.response = response;
|
|
@@ -18,6 +23,7 @@ export class ApiExpectError extends ApiExpectObject {
|
|
|
18
23
|
}
|
|
19
24
|
}
|
|
20
25
|
}
|
|
26
|
+
exports.ApiExpectError = ApiExpectError;
|
|
21
27
|
expect.extend({
|
|
22
28
|
apiErrorDetailToContain(received, issues) {
|
|
23
29
|
try {
|
|
@@ -35,7 +41,7 @@ expect.extend({
|
|
|
35
41
|
for (const detail of received) {
|
|
36
42
|
if (typeof m === 'object') {
|
|
37
43
|
try {
|
|
38
|
-
objectMatches(detail, m);
|
|
44
|
+
(0, object_matches_util_js_1.objectMatches)(detail, m);
|
|
39
45
|
matched = true;
|
|
40
46
|
break;
|
|
41
47
|
}
|
|
@@ -47,7 +53,7 @@ expect.extend({
|
|
|
47
53
|
if (!matched) {
|
|
48
54
|
return {
|
|
49
55
|
pass: false,
|
|
50
|
-
message: () => `Object does not match: \n` +
|
|
56
|
+
message: () => `Object does not match: \n` + jest_matcher_utils_1.default.stringify(m)
|
|
51
57
|
};
|
|
52
58
|
}
|
|
53
59
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiExpectObject = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
require("../jest-extend/index.js");
|
|
6
|
+
const lodash_isnil_1 = tslib_1.__importDefault(require("lodash.isnil"));
|
|
7
|
+
const lodash_omitby_1 = tslib_1.__importDefault(require("lodash.omitby"));
|
|
8
|
+
class ApiExpectObject {
|
|
4
9
|
constructor(response, _isNot = false) {
|
|
5
10
|
this.response = response;
|
|
6
11
|
this._isNot = _isNot;
|
|
@@ -10,7 +15,7 @@ export class ApiExpectObject {
|
|
|
10
15
|
}
|
|
11
16
|
toMatch(expected) {
|
|
12
17
|
try {
|
|
13
|
-
const v =
|
|
18
|
+
const v = (0, lodash_omitby_1.default)(expected, lodash_isnil_1.default);
|
|
14
19
|
this._expect(this.response.body).toMatchObject(v);
|
|
15
20
|
}
|
|
16
21
|
catch (e) {
|
|
@@ -46,3 +51,4 @@ export class ApiExpectObject {
|
|
|
46
51
|
return out;
|
|
47
52
|
}
|
|
48
53
|
}
|
|
54
|
+
exports.ApiExpectObject = ApiExpectObject;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiExpectOperationResult = void 0;
|
|
4
|
+
require("../jest-extend/index.js");
|
|
5
|
+
class ApiExpectOperationResult {
|
|
2
6
|
constructor(response, _isNot = false) {
|
|
3
7
|
this.response = response;
|
|
4
8
|
this._isNot = _isNot;
|
|
@@ -43,3 +47,4 @@ export class ApiExpectOperationResult {
|
|
|
43
47
|
return out;
|
|
44
48
|
}
|
|
45
49
|
}
|
|
50
|
+
exports.ApiExpectOperationResult = ApiExpectOperationResult;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiExpect = void 0;
|
|
4
|
+
require("../jest-extend/index.js");
|
|
5
|
+
const api_expect_collection_js_1 = require("./api-expect-collection.js");
|
|
6
|
+
const api_expect_error_js_1 = require("./api-expect-error.js");
|
|
7
|
+
const api_expect_object_js_1 = require("./api-expect-object.js");
|
|
8
|
+
const api_expect_operation_result_js_1 = require("./api-expect-operation-result.js");
|
|
9
|
+
class ApiExpect {
|
|
6
10
|
constructor(response, _isNot = false) {
|
|
7
11
|
this.response = response;
|
|
8
12
|
this._isNot = _isNot;
|
|
@@ -17,8 +21,10 @@ export class ApiExpect {
|
|
|
17
21
|
this._expect(this.response.status).toStrictEqual(status);
|
|
18
22
|
}
|
|
19
23
|
catch (e) {
|
|
24
|
+
const issues = this.response.body?.errors;
|
|
25
|
+
const issue = issues?.[0]?.message;
|
|
20
26
|
if (msg)
|
|
21
|
-
e.message = msg + '\n\n' + e.message;
|
|
27
|
+
e.message = msg + '\n\n' + (issue || e.message);
|
|
22
28
|
Error.captureStackTrace(e, this.toSuccess);
|
|
23
29
|
throw e;
|
|
24
30
|
}
|
|
@@ -45,7 +51,7 @@ export class ApiExpect {
|
|
|
45
51
|
Error.captureStackTrace(e, this.toFail);
|
|
46
52
|
throw e;
|
|
47
53
|
}
|
|
48
|
-
return new ApiExpectError(this.response);
|
|
54
|
+
return new api_expect_error_js_1.ApiExpectError(this.response);
|
|
49
55
|
}
|
|
50
56
|
toReturnOperationResult() {
|
|
51
57
|
let msg = '';
|
|
@@ -61,7 +67,7 @@ export class ApiExpect {
|
|
|
61
67
|
Error.captureStackTrace(e, this.toReturnOperationResult);
|
|
62
68
|
throw e;
|
|
63
69
|
}
|
|
64
|
-
return new ApiExpectOperationResult(this.response);
|
|
70
|
+
return new api_expect_operation_result_js_1.ApiExpectOperationResult(this.response);
|
|
65
71
|
}
|
|
66
72
|
toReturnObject() {
|
|
67
73
|
let msg = '';
|
|
@@ -76,7 +82,7 @@ export class ApiExpect {
|
|
|
76
82
|
Error.captureStackTrace(e, this.toReturnObject);
|
|
77
83
|
throw e;
|
|
78
84
|
}
|
|
79
|
-
return new ApiExpectObject(this.response);
|
|
85
|
+
return new api_expect_object_js_1.ApiExpectObject(this.response);
|
|
80
86
|
}
|
|
81
87
|
toReturnCollection() {
|
|
82
88
|
let msg = '';
|
|
@@ -92,7 +98,7 @@ export class ApiExpect {
|
|
|
92
98
|
Error.captureStackTrace(e, this.toReturnCollection);
|
|
93
99
|
throw e;
|
|
94
100
|
}
|
|
95
|
-
return new ApiExpectCollection(this.response);
|
|
101
|
+
return new api_expect_collection_js_1.ApiExpectCollection(this.response);
|
|
96
102
|
}
|
|
97
103
|
_expect(expected) {
|
|
98
104
|
const out = expect(expected);
|
|
@@ -101,3 +107,4 @@ export class ApiExpect {
|
|
|
101
107
|
return out;
|
|
102
108
|
}
|
|
103
109
|
}
|
|
110
|
+
exports.ApiExpect = ApiExpect;
|
package/esm/index.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
require("./jest-extend/index.js");
|
|
5
|
+
tslib_1.__exportStar(require("./test-client.js"), exports);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors"));
|
|
5
|
+
const jest_matcher_utils_1 = require("jest-matcher-utils");
|
|
3
6
|
expect.extend({
|
|
4
7
|
toHaveFields(received, expected) {
|
|
5
8
|
const expectedKeys = (Array.isArray(expected) ? expected : Object.keys(expected)).map(x => x.toLowerCase());
|
|
@@ -7,8 +10,8 @@ expect.extend({
|
|
|
7
10
|
const filteredKeys = expectedKeys.filter(x => !objectKeys.includes(x));
|
|
8
11
|
const pass = !filteredKeys.length === !this.isNot;
|
|
9
12
|
if (!pass) {
|
|
10
|
-
const message = () => `Expects keys
|
|
11
|
-
`${this.isNot ? 'Unsolicited' : 'Missing'} fields: ${
|
|
13
|
+
const message = () => `Expects keys ${this.isNot ? 'not ' : ''}to contain: ${ansi_colors_1.default.yellow('' + expectedKeys)}\n` +
|
|
14
|
+
`${this.isNot ? 'Unsolicited' : 'Missing'} fields: ${ansi_colors_1.default.yellow('' + filteredKeys)}\n`;
|
|
12
15
|
return { message, pass: !!this.isNot };
|
|
13
16
|
}
|
|
14
17
|
return { actual: received, pass: !this.isNot, message: () => '' };
|
|
@@ -19,8 +22,8 @@ expect.extend({
|
|
|
19
22
|
const filteredKeys = objectKeys.filter(x => !expectedKeys.includes(x));
|
|
20
23
|
const pass = !filteredKeys.length === !this.isNot;
|
|
21
24
|
if (!pass) {
|
|
22
|
-
const message = () => `${!this.isNot ? 'Do not expects' : 'Expects'} additional keys other than: ${
|
|
23
|
-
(filteredKeys ? `Additional keys received: ${
|
|
25
|
+
const message = () => `${!this.isNot ? 'Do not expects' : 'Expects'} additional keys other than: ${ansi_colors_1.default.yellow('' + expectedKeys)}\n` +
|
|
26
|
+
(filteredKeys ? `Additional keys received: ${ansi_colors_1.default.yellow('' + filteredKeys)}\n` :
|
|
24
27
|
'No additional keys received\n');
|
|
25
28
|
return { message, pass };
|
|
26
29
|
}
|
|
@@ -121,9 +124,9 @@ expect.extend({
|
|
|
121
124
|
});
|
|
122
125
|
function compare(matcherName, options, received, expected, operator, fn) {
|
|
123
126
|
const pass = fn(received, expected);
|
|
124
|
-
const message = () => matcherHint(matcherName, undefined, undefined, options) +
|
|
127
|
+
const message = () => (0, jest_matcher_utils_1.matcherHint)(matcherName, undefined, undefined, options) +
|
|
125
128
|
'\n\n' +
|
|
126
|
-
`Expected:${options.isNot ? ' not' : ''} ${operator} ${printExpected(expected)}\n` +
|
|
127
|
-
`Received:${options.isNot ? ' ' : ''} ${printReceived(received)}`;
|
|
129
|
+
`Expected:${options.isNot ? ' not' : ''} ${operator} ${(0, jest_matcher_utils_1.printExpected)(expected)}\n` +
|
|
130
|
+
`Received:${options.isNot ? ' ' : ''} ${(0, jest_matcher_utils_1.printReceived)(received)}`;
|
|
128
131
|
return { message, pass };
|
|
129
132
|
}
|
package/esm/test-client.js
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpraTestClient = void 0;
|
|
4
|
+
const http_1 = require("http");
|
|
5
|
+
const url_1 = require("url");
|
|
6
|
+
const common_1 = require("@opra/common");
|
|
7
|
+
const node_client_1 = require("@opra/node-client");
|
|
8
|
+
const api_expect_js_1 = require("./api-expect/api-expect.js");
|
|
9
|
+
const is_absolute_url_util_js_1 = require("./utils/is-absolute-url.util.js");
|
|
10
|
+
class OpraTestClient extends node_client_1.OpraHttpClient {
|
|
10
11
|
constructor(app, options) {
|
|
11
12
|
super('/', options);
|
|
12
|
-
this._server = app instanceof Server ? app : createServer(app);
|
|
13
|
+
this._server = app instanceof http_1.Server ? app : (0, http_1.createServer)(app);
|
|
14
|
+
}
|
|
15
|
+
collection(resourceName) {
|
|
16
|
+
return super.collection(resourceName);
|
|
17
|
+
}
|
|
18
|
+
singleton(resourceName) {
|
|
19
|
+
return super.singleton(resourceName);
|
|
13
20
|
}
|
|
14
21
|
async _fetch(urlString, req = {}) {
|
|
15
22
|
return new Promise((resolve, reject) => {
|
|
16
|
-
urlString = isAbsoluteUrl(urlString) ? urlString : joinPath('http://opra.test', urlString);
|
|
17
|
-
const url = new URL(urlString);
|
|
23
|
+
urlString = (0, is_absolute_url_util_js_1.isAbsoluteUrl)(urlString) ? urlString : (0, common_1.joinPath)('http://opra.test', urlString);
|
|
24
|
+
const url = new url_1.URL(urlString);
|
|
18
25
|
// Set protocol to HTTP
|
|
19
26
|
url.protocol = 'http';
|
|
20
27
|
// Apply original host to request header
|
|
@@ -49,7 +56,8 @@ export class OpraTestClient extends OpraHttpClientBase {
|
|
|
49
56
|
}
|
|
50
57
|
_createResponse(init) {
|
|
51
58
|
const resp = super._createResponse(init);
|
|
52
|
-
resp.expect = new ApiExpect(resp);
|
|
59
|
+
resp.expect = new api_expect_js_1.ApiExpect(resp);
|
|
53
60
|
return resp;
|
|
54
61
|
}
|
|
55
62
|
}
|
|
63
|
+
exports.OpraTestClient = OpraTestClient;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAbsoluteUrl = void 0;
|
|
4
|
+
const url_1 = require("url");
|
|
5
|
+
const isAbsoluteUrl = (urlString) => {
|
|
6
|
+
const url = new url_1.URL(urlString, 'http://opra.test/');
|
|
4
7
|
return url.host !== 'opra.test';
|
|
5
8
|
};
|
|
9
|
+
exports.isAbsoluteUrl = isAbsoluteUrl;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.objectMatches = void 0;
|
|
4
|
+
function objectMatches(received, expected) {
|
|
2
5
|
_objectMatches(received, expected, '');
|
|
3
6
|
}
|
|
7
|
+
exports.objectMatches = objectMatches;
|
|
4
8
|
function _objectMatches(received, expected, path) {
|
|
5
9
|
if (typeof received !== typeof expected)
|
|
6
10
|
expect(typeof received).toStrictEqual('object');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/testing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Opra testing package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
"build:esm": "tsc -b tsconfig-build-esm.json",
|
|
18
18
|
"postbuild": "cp README.md package.json ../../LICENSE ../../build/testing && cp ../../package.cjs.json ../../build/testing/cjs/package.json",
|
|
19
19
|
"lint": "eslint .",
|
|
20
|
-
"test": "
|
|
21
|
-
"cover": "
|
|
20
|
+
"test": "jest",
|
|
21
|
+
"cover": "jest --collect-coverage",
|
|
22
22
|
"clean": "npm run clean:src && npm run clean:dist && npm run clean:cover",
|
|
23
23
|
"clean:src": "ts-cleanup -s src --all && ts-cleanup -s test --all",
|
|
24
24
|
"clean:dist": "rimraf ../../build/testing",
|
|
25
25
|
"clean:cover": "rimraf ../../coverage/testing"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@opra/common": "^0.
|
|
29
|
-
"@opra/node-client": "^0.
|
|
28
|
+
"@opra/common": "^0.16.0",
|
|
29
|
+
"@opra/node-client": "^0.16.0",
|
|
30
30
|
"ansi-colors": "^4.1.3",
|
|
31
31
|
"lodash.isnil": "^4.0.0",
|
|
32
32
|
"lodash.omitby": "^4.6.0",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@types/supertest": "^2.0.12"
|
|
37
37
|
},
|
|
38
38
|
"type": "module",
|
|
39
|
-
"types": "
|
|
39
|
+
"types": "types/index.d.ts",
|
|
40
40
|
"exports": {
|
|
41
41
|
".": {
|
|
42
42
|
"require": "./cjs/index.js",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"bin/",
|
|
54
54
|
"cjs/",
|
|
55
55
|
"esm/",
|
|
56
|
+
"types/",
|
|
56
57
|
"LICENSE",
|
|
57
58
|
"README.md"
|
|
58
59
|
],
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import '../jest-extend/index.js';
|
|
2
|
+
import { Expression } from '@opra/common';
|
|
3
|
+
import { HttpResponse } from '@opra/node-client';
|
|
2
4
|
export declare class ApiExpectCollection {
|
|
3
5
|
readonly response: HttpResponse;
|
|
4
6
|
protected _isNot: boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import '../jest-extend/index.js';
|
|
2
|
+
import { HttpResponse } from '@opra/node-client';
|
|
2
3
|
import { ApiExpectObject } from './api-expect-object.js';
|
|
3
4
|
export declare class ApiExpectError extends ApiExpectObject {
|
|
4
5
|
readonly response: HttpResponse;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import '../jest-extend/index.js';
|
|
2
|
+
import { HttpResponse } from '@opra/node-client';
|
|
2
3
|
import { ApiExpectCollection } from './api-expect-collection.js';
|
|
3
4
|
import { ApiExpectError } from './api-expect-error.js';
|
|
4
5
|
import { ApiExpectObject } from './api-expect-object.js';
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './common.extend.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IncomingMessage, Server, ServerResponse } from 'http';
|
|
3
|
+
import { Type } from 'ts-gems';
|
|
4
|
+
import { HttpCollectionNode, HttpResponse, HttpSingletonNode, OpraHttpClient, OpraHttpClientOptions } from '@opra/node-client';
|
|
5
|
+
import { ApiExpect } from './api-expect/api-expect.js';
|
|
6
|
+
declare type RequestListener = (req: IncomingMessage, res: ServerResponse) => void;
|
|
7
|
+
export type ResponseExt = {
|
|
8
|
+
expect: ApiExpect;
|
|
9
|
+
};
|
|
10
|
+
export declare class OpraTestClient extends OpraHttpClient {
|
|
11
|
+
protected _server: Server;
|
|
12
|
+
constructor(app: Server | RequestListener, options?: OpraHttpClientOptions);
|
|
13
|
+
collection<TType = any>(resourceName: string | Type<TType>): HttpCollectionNode<TType, ResponseExt>;
|
|
14
|
+
singleton<TType = any>(resourceName: string | Type<TType>): HttpSingletonNode<TType, ResponseExt>;
|
|
15
|
+
protected _fetch(urlString: string, req?: RequestInit): Promise<Response>;
|
|
16
|
+
protected _createResponse(init?: HttpResponse.Initiator): HttpResponse;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
package/esm/index.d.ts
DELETED
package/esm/test-client.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { IncomingMessage, Server, ServerResponse } from 'http';
|
|
3
|
-
import { HttpResponse, HttpResponseInit } from '@opra/common';
|
|
4
|
-
import { OpraHttpClientBase, OpraHttpClientOptions } from '@opra/node-client';
|
|
5
|
-
import { ApiExpect } from './api-expect/api-expect.js';
|
|
6
|
-
declare type RequestListener = (req: IncomingMessage, res: ServerResponse) => void;
|
|
7
|
-
export type ResponseExt = {
|
|
8
|
-
expect: ApiExpect;
|
|
9
|
-
};
|
|
10
|
-
export declare class OpraTestClient extends OpraHttpClientBase<ResponseExt> {
|
|
11
|
-
protected _server: Server;
|
|
12
|
-
constructor(app: Server | RequestListener, options?: OpraHttpClientOptions);
|
|
13
|
-
protected _fetch(urlString: string, req?: RequestInit): Promise<Response>;
|
|
14
|
-
protected _createResponse(init?: HttpResponseInit): HttpResponse;
|
|
15
|
-
}
|
|
16
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|