Skip to content

Commit

Permalink
Merge pull request #1 from aspida/develop
Browse files Browse the repository at this point in the history
chore(release): 0.8.0
  • Loading branch information
solufa authored Aug 29, 2020
2 parents c83dfa5 + b7e7dda commit 4e1f087
Show file tree
Hide file tree
Showing 44 changed files with 302 additions and 642 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## 0.8.0 (2020-08-29)


### Features

* add default mockClient ([9e7d0a8](https://github.com/aspida/aspida-mock/commit/9e7d0a85dc7762868e9beb80ba71e3d86530a3f8))
* support aspidaClient ([52cd098](https://github.com/aspida/aspida-mock/commit/52cd098159ade3862d806bb0a09a19e081d885d8))


### Documentation

* update README ([f335786](https://github.com/aspida/aspida-mock/commit/f3357866ea5b51ec3d7a774af70d5e02c9f1632f))
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,24 @@

## Usage

### Installation (@aspida/axios only mock compatible)
### Installation

- Using [npm](https://www.npmjs.com/):

```sh
$ npm install @aspida/axios axios
$ npm install aspida-mock --save-dev
$ npm install aspida-mock @aspida/axios axios
# $ npm install aspida-mock @aspida/fetch
# $ npm install aspida-mock @aspida/node-fetch node-fetch
# $ npm install aspida-mock @aspida/ky ky
```

- Using [Yarn](https://yarnpkg.com/):

```sh
$ yarn add @aspida/axios axios
$ yarn add aspida-mock --dev
$ yarn add aspida-mock @aspida/axios axios
# $ yarn add aspida-mock @aspida/fetch
# $ yarn add aspida-mock @aspida/node-fetch node-fetch
# $ yarn add aspida-mock @aspida/ky ky
```

### Creating API endpoints
Expand Down Expand Up @@ -113,12 +117,13 @@ $ npm run build

<!-- prettier-ignore -->
```ts
import aspidaClient from "@aspida/axios"
import mockClient from "@aspida/axios/dist/mockClient"
import aspidaClient from "@aspida/axios" // "@aspida/fetch", "@aspida/node-fetch", "@aspida/ky"
import api from "./api/$api"
import mock from "./api/$mock"

const client = process.env.NODE_ENV === "development" ? mock(mockClient()) : api(aspidaClient())
const client = process.env.NODE_ENV === "development"
? mock(aspidaClient())
: api(aspidaClient())

;(async () => {
const res = await client.users.post({
Expand Down Expand Up @@ -184,10 +189,10 @@ export default mockMethods<Methods>({

<!-- prettier-ignore -->
```ts
import mockClient from "@aspida/axios/dist/mockClient"
import aspidaClient from "@aspida/axios" // "@aspida/fetch", "@aspida/node-fetch", "@aspida/ky"
import mock from "./api/$mock"

const client = mock(mockClient())
const client = mock(aspidaClient())

;(async () => {
const res = await client.users.get({
Expand All @@ -214,10 +219,10 @@ Simulate response delay.

<!-- prettier-ignore -->
```ts
import mockClient from "@aspida/axios/dist/mockClient"
import aspidaClient from "@aspida/axios" // "@aspida/fetch", "@aspida/node-fetch", "@aspida/ky"
import mock from "./api/$mock"

const client = mock(mockClient(), { delayMSec: 500 })
const client = mock(aspidaClient(), { delayMSec: 500 })

;(async () => {
console.time()
Expand All @@ -232,10 +237,10 @@ Switch request log output.

<!-- prettier-ignore -->
```ts
import mockClient from "@aspida/axios/dist/mockClient"
import aspidaClient from "@aspida/axios" // "@aspida/fetch", "@aspida/node-fetch", "@aspida/ky"
import mock from "./api/$mock"

const client = mock(mockClient(), { log: true })
const client = mock(aspidaClient(), { log: true })

;(async () => {
await client.users.$get({ query: { bar: "baz" }})
Expand Down
8 changes: 4 additions & 4 deletions __tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import mockClient from '@aspida/axios/dist/mockClient'
import { MockRoute, mockMethods, mockMiddleware } from '../src'
import fetchClient from '@aspida/node-fetch'
import { MockRoute, mockMethods, mockMiddleware, mockClient } from '../src'
import api from '../api/$api'

describe('initialize', () => {
const adapter = mockClient()
const adapter = mockClient(fetchClient())
const client = api(adapter)

afterEach(() => adapter.detachRoutes())
Expand All @@ -27,7 +27,7 @@ describe('initialize', () => {
test('get path through', async () => {
adapter.attachRoutes([])
await expect(
client.get({ config: { baseURL: 'https://www.google.com/' } })
client.aspida_mock.get({ config: { baseURL: 'https://github.com/aspida' } })
).resolves.toHaveProperty('status', 200)
})

Expand Down
245 changes: 127 additions & 118 deletions api/$api.ts

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions api/$mock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable */
import { MockClient, MockConfig } from 'aspida-mock'
import { AspidaClient } from 'aspida'
import { MockClient, MockConfig, mockClient } from 'aspida-mock'
import baseMiddleware from './@middleware'
import api from './$api'
import mock0 from './v2.0/index'
Expand All @@ -22,9 +23,10 @@ export const mockRoutes = () => [
{ path: '/_sampleId.json@number', methods: mock7 }
]

export default <U>(client: MockClient<U>, config?: MockConfig) => {
const middleware = [...baseMiddleware, ...(config && config.middleware || [])]
client.attachRoutes(mockRoutes(), { ...config, middleware })
export default <U>(client: AspidaClient<U> | MockClient<U>, config?: MockConfig) => {
const middleware = [...baseMiddleware, ...(config?.middleware || [])]
const mock = 'attachRoutes' in client ? client : mockClient(client)
mock.attachRoutes(mockRoutes(), { ...config, middleware })

return api(client)
return api(mock)
}
5 changes: 5 additions & 0 deletions api/aspida-mock/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type Methods = {
get: {
resBody: string
}
}
18 changes: 0 additions & 18 deletions dist/callMockHandler.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion dist/callMockHandler.d.ts.map

This file was deleted.

130 changes: 0 additions & 130 deletions dist/callMockHandler.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/callMockHandler.js.map

This file was deleted.

7 changes: 0 additions & 7 deletions dist/cli/buildRouteFile.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion dist/cli/buildRouteFile.d.ts.map

This file was deleted.

21 changes: 0 additions & 21 deletions dist/cli/buildRouteFile.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/cli/buildRouteFile.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/cli/createRouteString.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion dist/cli/createRouteString.d.ts.map

This file was deleted.

19 changes: 0 additions & 19 deletions dist/cli/createRouteString.js

This file was deleted.

Loading

0 comments on commit 4e1f087

Please sign in to comment.