@opra/testing 0.4.0 → 0.5.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.
@@ -6,6 +6,11 @@ const axiosist = tslib_1.__importStar(require("axiosist"));
6
6
  const client_1 = require("@opra/client");
7
7
  const api_expect_js_1 = require("./api-expect/api-expect.js");
8
8
  class OpraTestClient extends client_1.OpraClient {
9
+ constructor(app, arg1, arg2) {
10
+ super('/', arg1, arg2);
11
+ this._axios.defaults.adapter = axiosist.createAdapter(app);
12
+ this._axios.defaults.validateStatus = () => true;
13
+ }
9
14
  // @ts-ignore
10
15
  collection(name) {
11
16
  return super.collection(name);
@@ -14,19 +19,16 @@ class OpraTestClient extends client_1.OpraClient {
14
19
  singleton(name) {
15
20
  return super.singleton(name);
16
21
  }
17
- async _send(req, options) {
18
- const resp = (await super._send(req, options));
22
+ // @ts-ignore
23
+ async _send(req) {
24
+ const resp = (await super._send(req));
19
25
  resp.expect = new api_expect_js_1.ApiExpect(resp);
20
26
  return resp;
21
27
  }
22
28
  static async create(app, options) {
23
- const instance = await super.create('/', {
24
- validateStatus: false,
25
- ...options,
26
- adapter: axiosist.createAdapter(app)
27
- });
28
- Object.setPrototypeOf(instance, OpraTestClient.prototype);
29
- return instance;
29
+ const client = new this(app, options);
30
+ await client.init();
31
+ return client;
30
32
  }
31
33
  }
32
34
  exports.OpraTestClient = OpraTestClient;
@@ -1,9 +1,9 @@
1
- import { OpraResponse } from '@opra/client';
1
+ import { ClientResponse } from '@opra/client';
2
2
  import { Expression } from '@opra/url';
3
3
  export declare class ApiExpectCollection {
4
- readonly response: OpraResponse;
4
+ readonly response: ClientResponse;
5
5
  protected _isNot: boolean;
6
- constructor(response: OpraResponse, _isNot?: boolean);
6
+ constructor(response: ClientResponse, _isNot?: boolean);
7
7
  get not(): ApiExpectCollection;
8
8
  forEach(callbackfn: (v: any) => void): this;
9
9
  toMatch<T extends {}>(expected: T): this;
@@ -1,8 +1,8 @@
1
- import { OpraResponse } from '@opra/client';
1
+ import { ClientResponse } from '@opra/client';
2
2
  import { ApiExpectObject } from './api-expect-object.js';
3
3
  export declare class ApiExpectError extends ApiExpectObject {
4
- readonly response: OpraResponse;
5
- constructor(response: OpraResponse);
4
+ readonly response: ClientResponse;
5
+ constructor(response: ClientResponse);
6
6
  toContainDetail(...matching: any[]): void;
7
7
  }
8
8
  declare global {
@@ -1,8 +1,8 @@
1
- import { OpraResponse } from '@opra/client';
1
+ import { ClientResponse } from '@opra/client';
2
2
  export declare class ApiExpectObject {
3
- readonly response: OpraResponse;
3
+ readonly response: ClientResponse;
4
4
  protected _isNot: boolean;
5
- constructor(response: OpraResponse, _isNot?: boolean);
5
+ constructor(response: ClientResponse, _isNot?: boolean);
6
6
  get not(): ApiExpectObject;
7
7
  toMatch<T extends {}>(expected: T): this;
8
8
  toHaveFields(fields: string[]): this;
@@ -1,8 +1,8 @@
1
- import { OpraResponse } from '@opra/client';
1
+ import { ClientResponse } from '@opra/client';
2
2
  export declare class ApiExpectOperationResult {
3
- readonly response: OpraResponse;
3
+ readonly response: ClientResponse;
4
4
  protected _isNot: boolean;
5
- constructor(response: OpraResponse, _isNot?: boolean);
5
+ constructor(response: ClientResponse, _isNot?: boolean);
6
6
  get not(): ApiExpectOperationResult;
7
7
  toBeAffectedExact(expected: number): this;
8
8
  toBeAffectedMin(expected: number): this;
@@ -1,12 +1,12 @@
1
- import { OpraResponse } from '@opra/client';
1
+ import { ClientResponse } from '@opra/client';
2
2
  import { ApiExpectCollection } from './api-expect-collection.js';
3
3
  import { ApiExpectError } from './api-expect-error.js';
4
4
  import { ApiExpectObject } from './api-expect-object.js';
5
5
  import { ApiExpectOperationResult } from './api-expect-operation-result.js';
6
6
  export declare class ApiExpect {
7
- readonly response: OpraResponse;
7
+ readonly response: ClientResponse;
8
8
  protected _isNot: boolean;
9
- constructor(response: OpraResponse, _isNot?: boolean);
9
+ constructor(response: ClientResponse, _isNot?: boolean);
10
10
  get not(): ApiExpect;
11
11
  toSuccess(status?: number): this;
12
12
  toFail(status?: number): ApiExpectError;
@@ -1,18 +1,22 @@
1
1
  /// <reference types="node" />
2
2
  import { AxiosRequestConfig } from 'axios';
3
3
  import { IncomingMessage, Server, ServerResponse } from 'http';
4
- import { CollectionService, CommonRequestOptions, OpraClient, OpraClientOptions, OpraResponse } from '@opra/client';
5
- import { SingletonService } from '@opra/client/src/services/singleton-service';
4
+ import { Type } from 'ts-gems';
5
+ import { ClientResponse, CollectionNode, OpraClient, OpraClientOptions } from '@opra/client';
6
+ import { SingletonNode } from '@opra/client/src/services/singleton-node';
7
+ import { OpraDocument } from '@opra/schema/src/index';
6
8
  import { ApiExpect } from './api-expect/api-expect.js';
7
9
  declare type RequestListener = (req: IncomingMessage, res: ServerResponse) => void;
8
10
  declare type Handler = RequestListener | Server;
9
- declare type OpraTestResponse<T = any> = OpraResponse<T> & {
11
+ declare type OpraTestResponse<T = any> = ClientResponse<T> & {
10
12
  expect: ApiExpect;
11
13
  };
12
14
  export declare class OpraTestClient extends OpraClient {
13
- collection<T = any, TResponse extends OpraTestResponse<T> = OpraTestResponse<T>>(name: string): CollectionService<T, TResponse>;
14
- singleton<T = any, TResponse extends OpraTestResponse<T> = OpraTestResponse<T>>(name: string): SingletonService<T, TResponse>;
15
- protected _send(req: AxiosRequestConfig, options: CommonRequestOptions): Promise<OpraTestResponse>;
16
- static create(app: Handler, options?: OpraClientOptions): Promise<OpraTestClient>;
15
+ constructor(app: Handler, options?: OpraClientOptions);
16
+ constructor(app: Handler, metadata: OpraDocument, options?: OpraClientOptions);
17
+ collection<T = any, TResponse extends OpraTestResponse<T> = OpraTestResponse<T>>(name: string): CollectionNode<T, TResponse>;
18
+ singleton<T = any, TResponse extends OpraTestResponse<T> = OpraTestResponse<T>>(name: string): SingletonNode<T, TResponse>;
19
+ protected _send<TResponse extends OpraTestResponse>(req: AxiosRequestConfig): Promise<TResponse>;
20
+ static create<T extends OpraTestClient>(this: Type<T>, app: Handler, options?: OpraClientOptions): Promise<T>;
17
21
  }
18
22
  export {};
@@ -2,6 +2,11 @@ import * as axiosist from 'axiosist';
2
2
  import { OpraClient } from '@opra/client';
3
3
  import { ApiExpect } from './api-expect/api-expect.js';
4
4
  export class OpraTestClient extends OpraClient {
5
+ constructor(app, arg1, arg2) {
6
+ super('/', arg1, arg2);
7
+ this._axios.defaults.adapter = axiosist.createAdapter(app);
8
+ this._axios.defaults.validateStatus = () => true;
9
+ }
5
10
  // @ts-ignore
6
11
  collection(name) {
7
12
  return super.collection(name);
@@ -10,18 +15,15 @@ export class OpraTestClient extends OpraClient {
10
15
  singleton(name) {
11
16
  return super.singleton(name);
12
17
  }
13
- async _send(req, options) {
14
- const resp = (await super._send(req, options));
18
+ // @ts-ignore
19
+ async _send(req) {
20
+ const resp = (await super._send(req));
15
21
  resp.expect = new ApiExpect(resp);
16
22
  return resp;
17
23
  }
18
24
  static async create(app, options) {
19
- const instance = await super.create('/', {
20
- validateStatus: false,
21
- ...options,
22
- adapter: axiosist.createAdapter(app)
23
- });
24
- Object.setPrototypeOf(instance, OpraTestClient.prototype);
25
- return instance;
25
+ const client = new this(app, options);
26
+ await client.init();
27
+ return client;
26
28
  }
27
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/testing",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Opra testing package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -25,9 +25,9 @@
25
25
  "clean:cover": "rimraf ../../coverage/testing"
26
26
  },
27
27
  "dependencies": {
28
- "@opra/schema": "^0.4.0",
29
- "@opra/url": "^0.4.0",
30
- "@opra/client": "^0.4.0",
28
+ "@opra/schema": "^0.5.0",
29
+ "@opra/url": "^0.5.0",
30
+ "@opra/client": "^0.5.0",
31
31
  "ansi-colors": "^4.1.3",
32
32
  "lodash": "^4.17.21",
33
33
  "rule-judgment": "^1.1.5",