Skip to content

Commit

Permalink
Merge branch 'master' into feature/recursive-generics
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjlowm authored Jun 26, 2020
2 parents 736a1c4 + 4350ef9 commit 57727e6
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 240 deletions.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Ts Auto Mock
# TS auto mock
![Test](https://github.com/Typescript-TDD/ts-auto-mock/workflows/Test/badge.svg)
[![npm version](https://badge.fury.io/js/ts-auto-mock.svg)](https://badge.fury.io/js/ts-auto-mock)
[![Downloads](https://img.shields.io/npm/dw/ts-auto-mock.svg)](https://www.npmjs.com/package/ts-auto-mock)
[![Downloads](https://img.shields.io/npm/dw/ts-auto-mock.svg)](https://www.npmjs.com/package/ts-auto-mock)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

![slack](docs/slack_small.png) Need help? Join us on [Slack](https://join.slack.com/t/typescripttdd/shared_invite/enQtODk3MjQwNzUwNTk2LTMzNjdlZTNmMmY3Nzg2NDNiZDA1YzJmZjk2NjcwZjQwODQ3YzE5NGZjM2Q4MzZjYWNiMWE4MGU0NjEzM2E5YzE)
![Slack](docs/slack_small.png) Need help? Join us on [Slack](https://join.slack.com/t/typescripttdd/shared_invite/enQtODk3MjQwNzUwNTk2LTMzNjdlZTNmMmY3Nzg2NDNiZDA1YzJmZjk2NjcwZjQwODQ3YzE5NGZjM2Q4MzZjYWNiMWE4MGU0NjEzM2E5YzE)

A Typescript transformer that will allow you to create mock for any types (Interfaces, Classes, ...) without need to create manual fakes/mocks.
A TypeScript transformer that will allow you to create mocks for any types (interfaces, classes, etc.) without the need to create manual fakes/mocks.

## [Api Documentation](https://typescript-tdd.github.io/ts-auto-mock)
## [API Documentation](https://typescript-tdd.github.io/ts-auto-mock)

#### [Installation](https://typescript-tdd.github.io/ts-auto-mock/installation)
#### [Usage](https://typescript-tdd.github.io/ts-auto-mock/create-mock)
Expand All @@ -28,15 +28,19 @@ interface Person {
const mock = createMock<Person>();
mock.id // ""
mock.getName() // ""
mock.details // "{phone: 0} "
mock.details // "{ phone: 0 }"
```

* If you are interested to use it with jasmine please go to [jasmine-ts-auto-mock](https://github.com/Typescript-TDD/jasmine-ts-auto-mock)
* If you are interested to use it with jest please go to [jest-ts-auto-mock](https://github.com/Typescript-TDD/jest-ts-auto-mock)

## [Changelog](CHANGELOG.md)

## [Roadmap](https://github.com/Typescript-TDD/ts-auto-mock/wiki/Roadmap)
## Changelog

Find the changelog here: [Changelog](CHANGELOG.md).

## Roadmap

You can find the roadmap of this project on the Wiki page: [Roadmap](https://github.com/Typescript-TDD/ts-auto-mock/wiki/Roadmap).

## Do you want to contribute?
* [Check how to make changes to the code base](https://typescript-tdd.github.io/ts-auto-mock/local-development)
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/definitelyTyped/list.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"id":"756c5f8d-be26-43fc-8831-0a12df4c972e.json","initialDate":"2020-01-11T17:17:58.333Z","lastUpdatedDate":"2020-01-16T00:31:39.270Z","typesProcessed":9999},{"id":"9749238a-cba9-4abd-9fac-f9d0d4ef90e3.json","initialDate":"2020-01-17T20:34:24.904Z","lastUpdatedDate":"2020-02-01T00:40:31.064Z","typesProcessed":9999},{"id":"45e2213b-fa9c-40d1-b066-89413f063ee3.json","initialDate":"2020-02-01T17:11:06.944Z","lastUpdatedDate":"2020-03-07T00:20:59.201Z","typesProcessed":6549},{"id":"532444dd-7414-42ad-8d30-3da2d2e6c9af.json","initialDate":"2020-03-08T08:08:21.638Z","lastUpdatedDate":"2020-03-17T00:55:23.522Z","typesProcessed":9999},{"id":"59fcd50b-ad93-43d9-8777-45cf4cb83abe.json","initialDate":"2020-03-29T00:47:04.041Z","lastUpdatedDate":"2020-05-10T00:20:06.743Z","typesProcessed":6744},{"id":"6dafe6a4-fd96-4cee-a280-2ef999b957ac.json","initialDate":"2020-05-11T00:52:07.109Z","lastUpdatedDate":"2020-06-17T00:33:39.118Z","typesProcessed":6850},{"id":"a4b17491-a90a-4eb8-97e7-f58c8ddbc538.json","initialDate":"2020-06-18T00:57:32.208Z","lastUpdatedDate":"2020-06-20T00:57:16.555Z","typesProcessed":1500}]
[{"id":"756c5f8d-be26-43fc-8831-0a12df4c972e.json","initialDate":"2020-01-11T17:17:58.333Z","lastUpdatedDate":"2020-01-16T00:31:39.270Z","typesProcessed":9999},{"id":"9749238a-cba9-4abd-9fac-f9d0d4ef90e3.json","initialDate":"2020-01-17T20:34:24.904Z","lastUpdatedDate":"2020-02-01T00:40:31.064Z","typesProcessed":9999},{"id":"45e2213b-fa9c-40d1-b066-89413f063ee3.json","initialDate":"2020-02-01T17:11:06.944Z","lastUpdatedDate":"2020-03-07T00:20:59.201Z","typesProcessed":6549},{"id":"532444dd-7414-42ad-8d30-3da2d2e6c9af.json","initialDate":"2020-03-08T08:08:21.638Z","lastUpdatedDate":"2020-03-17T00:55:23.522Z","typesProcessed":9999},{"id":"59fcd50b-ad93-43d9-8777-45cf4cb83abe.json","initialDate":"2020-03-29T00:47:04.041Z","lastUpdatedDate":"2020-05-10T00:20:06.743Z","typesProcessed":6744},{"id":"6dafe6a4-fd96-4cee-a280-2ef999b957ac.json","initialDate":"2020-05-11T00:52:07.109Z","lastUpdatedDate":"2020-06-17T00:33:39.118Z","typesProcessed":6850},{"id":"a4b17491-a90a-4eb8-97e7-f58c8ddbc538.json","initialDate":"2020-06-18T00:57:32.208Z","lastUpdatedDate":"2020-06-26T00:57:26.736Z","typesProcessed":4500}]
2 changes: 1 addition & 1 deletion data/performance.json

Large diffs are not rendered by default.

45 changes: 23 additions & 22 deletions ui/doczrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@ import pkg from './package.json';
const libName = pkg.name;

export default {
typescript: true,
themeConfig: {
initialColorMode: 'dark',
showDarkModeSwitch: false
},
base: `/${libName}/`,
menu: [
{ name: 'Home'},
{ name: 'Installation'},
{ name: 'Create mock', menu: ['Default']},
{ name: 'Create mock list'},
{ name: 'Register mock'},
{ name: 'Extension'},
{ name: 'Types supported'},
{ name: 'Types not supported'},
{ name: 'Config'},
{ name: 'Performance'},
{ name: 'Definitely Typed'},
{ name: 'Local development'}
],
repository: "https://github.com/Typescript-TDD/ts-auto-mock"
}
typescript: true,
themeConfig: {
initialColorMode: 'dark',
showDarkModeSwitch: false
},
title: 'TS auto mock',
base: `/${libName}/`,
menu: [
{ name: 'Home'},
{ name: 'Installation'},
{ name: 'Create mock', menu: ['Default']},
{ name: 'Create mock list'},
{ name: 'Register mock'},
{ name: 'Extension'},
{ name: 'Types supported'},
{ name: 'Types not supported'},
{ name: 'Config'},
{ name: 'Performance'},
{ name: 'Definitely Typed'},
{ name: 'Local development'}
],
repository: "https://github.com/Typescript-TDD/ts-auto-mock"
};
22 changes: 11 additions & 11 deletions ui/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module.exports = {
plugins: [
`gatsby-plugin-sass`,
`gatsby-plugin-offline`,
{
resolve: `gatsby-plugin-google-analytics`,
options: {
trackingId: "UA-37077972-4",
head: false
},
}
]
plugins: [
`gatsby-plugin-sass`,
`gatsby-plugin-offline`,
{
resolve: `gatsby-plugin-google-analytics`,
options: {
trackingId: "UA-37077972-4",
head: false
},
}
]
};
57 changes: 28 additions & 29 deletions ui/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,37 @@ const development = 'development';
const activeEnv = process.env.NODE_ENV || development;

exports.onCreateWebpackConfig = ({
stage,
rules,
loaders,
plugins,
actions,
}) => {

actions.setWebpackConfig({
plugins: [
new WebpackCopyPlugin([
{
from: path.resolve('..', '..', 'data'),
to: 'resources'
},
{
from: path.resolve('..', '_config.yml'),
to: ''
}
]),
new Dotenv({
path: resolveEnvironmentVariables(activeEnv)
})
],
});
stage,
rules,
loaders,
plugins,
actions,
}) => {
actions.setWebpackConfig({
plugins: [
new WebpackCopyPlugin([
{
from: path.resolve('..', '..', 'data'),
to: 'resources'
},
{
from: path.resolve('..', '_config.yml'),
to: ''
}
]),
new Dotenv({
path: resolveEnvironmentVariables(activeEnv)
})
],
});
};

function resolveEnvironmentVariables(env) {
const isDevelopment = activeEnv === development;
const isDevelopment = activeEnv === development;

if (isDevelopment) {
return path.resolve('..', '.env.development');
}
if (isDevelopment) {
return path.resolve('..', '.env.development');
}

return path.resolve('..', '.env');
return path.resolve('..', '.env');
}
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ts-auto-mock",
"version": "1.0.0",
"description": "ts auto mock website",
"description": "ts-auto-mock website",
"main": "index.js",
"scripts": {
"docz:dev": "docz dev",
Expand Down
10 changes: 5 additions & 5 deletions ui/src/copy/copy.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
export const TsAutoMockCopy = {
title: "Typescript transformer to create mocks for any types",
title: "TypeScript transformer to create mocks for any type",
homeButton: "Get Started",
apiButton: "API Documentation",
slack: "Need help? Join us on Slack",
features: {
real: {
title: "Real mocks",
description: "The creation of the mocks is done during typescript compilation, it will preserve all the types information"
title: "Real Mocks",
description: "The creation of mocks is done during TypeScript compilation and preserves all type information."
},
extendible: {
title: "Extendible",
description: "This library can be used with any testing framework. You can provide your own implementation"
description: "This library can be used with any testing framework. You can even provide your own implementation!"
},
typeSafety: {
title: "Type Safety",
description: "No more casting to any to get your spy or your mock. This library provides a mechanism to get your spies and persists the types"
description: "No more casting to `any' to get your spy or mock. This library provides a mechanism to inject your spies while preserving their types."
}
}
}
2 changes: 1 addition & 1 deletion ui/src/core/logo/logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import logoDark from './logo_dark.svg';
export function Logo(): JSX.Element {
const theme = useTheme();
const logo = theme === Theme.LIGHT ? logoLight : logoDark;
return <img src={logo} alt={"ts auto mock logo"}/>
return <img src={logo} alt={"TS auto mock logo"}/>
}
12 changes: 7 additions & 5 deletions ui/src/views/create-mock-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ route: /create-mock-list
---

# Create mock list
createMock list it will create a list of mocks automatically

`createMockList` creates an array of mocks, so you don't have to do that tedious part yourself.

```ts
import { createMockList } from 'ts-auto-mock';
Expand All @@ -16,10 +17,11 @@ const mockList = createMockList<Person>(2);
mockList.length // 2
```

## Default values
You can define a function to overrides specific fields.
## Property overrides

You can supply a function as the second argument to override specific properties.

The function will have access to the current index
The function will be supplied the index of the individual element as the callback argument, e.g.:

```ts
import { createMockList } from 'ts-auto-mock';
Expand All @@ -30,7 +32,7 @@ interface Person {
const mockList = createMockList<Person>(2, (index: number) => {
return {
id: "id" + index
}
};
});
mockList[0].id // id0
mockList[1].id // id1
Expand Down
18 changes: 11 additions & 7 deletions ui/src/views/create-mock.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,33 @@ interface Person {
const mock = createMock<Person>();
mock.id // ""
mock.getName() // ""
mock.details // "{phone: 0} "
mock.details // { phone: 0 }
```

## Default values
## Property overrides

If you desire, you may override the otherwise mocked properties of an interface.

You don't have to provide the entire interface, just a partial object of the one you are mocking.

You can also define default values to overrides specific fields
You dont have to provide the entire interface, just a partial of the one to mock
```ts
import { createMock } from 'ts-auto-mock';

interface Person {
id: string;
getName(): string;
details: {
phone: number
phone: number
}
}

const mock = createMock<Person>({
details: {
phone: 07423232323
phone: 7423232323
}
});

mock.id // ""
mock.getName() // ""
mock.details // "{phone: 07423232323} "
mock.details // { phone: 7423232323 }
```
Loading

0 comments on commit 57727e6

Please sign in to comment.