Skip to content

Commit

Permalink
chore(release): release version v2.0.0 (#53)
Browse files Browse the repository at this point in the history
* chore: turn into monorepo architecture and change return to instance (#51)

* refactor(mock-factory): change the return type of mock factory (#40)

* refactor(mock-factory): change the return type of mock factory

MockFactory will now return an instance of the class and not a plain object

BREAKING CHANGE: MockFactory is now an instance (TClass) and not ClassLiteral<TClass>

* chore: fix typo in the test name

* chore: change methods order

* chore: added source map and some jest configs

* refactor: change some var names and error

* test(class-processor): refactor test turning into integration instead of unit

* chore(lib): move files into lib folder and change imports

* feat(fluent-api): add fluent api (builder) functionality and persistence

Add fluent API to enable methods chaining with ability to persist the mock

BREAKING CHANGE: MockFactory is now a function and not a class, changed the original to
MockGenerator. Add fluent API and ability to persist mock data

closes #42, closes #37

* refactor: change mock names, remove test from tsconfig.json

* refactor: temp change to another class type

* fix: fix broken generic type in mock generator

* test: update integration snapshot and fix path issues

* chore: remove redundant example

* chore(mockingbird): refactor the structure of the project to be monorepo

* chore: fix settings of jest and monorepo

* ci: fix pipeline to work with yarn and lerna

* chore: remove redundant example file

* refactor: split into logical packages (#46)

* chore: monorepo settings and preparation

* refactor: split into logic packages, this is just the first suggested structure

* refactor: rearrange packages - fix broken tests and change names  (#47)

* chore: monorepo settings and preparation

* refactor: split into logic packages, this is just the first suggested structure

* refactor(mockingbird-ts): change processor to parser

* chore(mockingbird-ts): rearrange import style

* refactor(mockingbird-ts): import mock decorator from package

* refactor(mockingbird-ts): change processor to parser

* test(mockingbird-ts): fix and improve array value handler

* refactor(mockingbird-ts): change processor to parser

* chore(mockingbird-ts): rearrange import style

* refactor(mockingbird-ts): import mock decorator from package

* refactor(mockingbird-ts): change processor to parser

* test(mockingbird-ts): fix and improve array value handler

* chore(types): fix exit code

* fix: broken generator (#49)

* chore(types): fix lint typo

* test(mockingbird-ts): fix mock generator broken test

* refactor(parser): remove locale option

* refactor(mockingbird-ts): change names to parser and add locale option

* chore(types): fix lint typo

* test(parser): change file name and faker instance

* chore: add proper files, rearrange dependencies and package.json files (#50)

* chore(mockingbird-ts): update dependencies

* ci(repo): fix commit lint step

* ci(repo): fix commit lint step

* ci(repo): fix broken coverage step

* chore(mockingbird-ts): fix dependencies

* chore(repo): testing linting tactics (#52)

* chore(repo): change jest testing tactic to fully work with monorepo

* chore(mockingbird-ts): remove locale todo

* chore(repo): add root to eslint

* ci(repo): fix step lint in pipeline

* chore(repo): fix test:cov step

* chore(repo): fix test:cov step

* chore(repo): fix test:cov step

* chore(repo): add coverage to ignore

* chore(repo): modify lerna settings

* chore(version): publish

 - @mockinbird/parser@1.0.1-alpha.0
 - @mockinbird/reflect@1.0.1-alpha.0
 - @mockinbird/types@1.0.1-alpha.0

* chore(repo): modify lerna settings

* chore(mockingbird-ts): add test root to jest config

* refactor(mockingbird-ts): change back the name to factory and not generator

* chore(repo): re-version mockingbird-ts and rearrange changelog files

* ci(repo): add release branch to checks, fix release.yml and remove publishing

* refactor(mockingbird-ts): change the name of mock factory to be mock generator (#54)

change MockFactory name to be MockGenerator

BREAKING CHANGE: MockFactory changed to be MockGenerator

re #42

* refactor(mockingbird-ts): arrange classes - change mock-factory to mock-generator (#55)

* refactor(mockingbird-ts): change the name of mock factory to be mock generator

change MockFactory name to be MockGenerator

BREAKING CHANGE: MockFactory changed to be MockGenerator

re #42

* chore(repo): update tsconfig build config

* refactor(types): change 'class' to 'type' with new definition

* refactor(reflect): change 'class' type to 'type' type

* refactor(parser): change 'class' type to 'type'

* refactor(mockingbird-ts): generator now has state and di, remove static method 'create'

* test(mockingbird-ts): add unit test for mock generator

* test(mockingbird-ts): add unit test for mock generator

* refactor(parser): add option to set locale and change static class member (state instead)

* test(mockingbird-ts): remove test of circular mock

* refactor(parser): change faker methods (that were deprecated) to new version (#56)

* test: add some more test cases (and increase code coverage) (#57)

* test(parser): check and spy on faker functions

* test(parser): improve array-value-handler test cases

* test(reflect): add missing test case (branch)

* test(reflect): add missing test for property decorator value

* chore(parser): change method name

* refactor: change generics type, remove 'type' type and add 'class' type (#58)

* refactor(types): remove type 'type' and add 'class' type instead

* refactor(mockingbird-ts): replace 'type' type with 'class' and cancel class generic

* refactor(reflect): change 'type' type to 'class' type genetics

* refactor(parser): remove 'type' type add 'class' instead, change generics types

* chore(release): release packages

 - mockingbird-ts@2.0.0
 - @mockinbird/parser@2.0.0
 - @mockinbird/reflect@2.0.0
 - @mockinbird/types@2.0.0

* revert(repo): release packages

This reverts commit 93d53e4

* chore(repo): change entry points in package.json files and change tsconfig settings (#59)

* feat(mockingbird-ts): add mock factory fluent/builder api (#60)

* fix(types): change faker-static to faker in callback type

* feat(mockingbird-ts): add new mock factory with builder - creating fluent api

* test(mockingbird-ts): add missing test for mock builder

* test(mockingbird-ts): add e2e test for mock factory

* test(mockingbird-ts): mock generator test is now imported from main lib

* refactor(mockingbird-ts): mock generator is no longer exported, using mock factory instead

MockGenerator is not exported anymore and the entry point is now MockFactory with builder API

BREAKING CHANGE: MockGenerator is not exported anymore, use MockFactory instead

closes #42

* ci(repo): add lerna command to publish with temp alpha dist tag

* chore(repo): version packages and add changelogs

* fix(types): add build to export a js file to include the faker instance (for runtime) (#61)

* build(repo): fix tsconfig settings and build strategy

* fix(types): add build to export a js file to include the faker instance (for runtime)

* chore(repo): add coverage settings to jest config files and exclude some files from tsconfig

* chore(repo): add publish access config in package.json for all packages

* chore(release): release packages

 - mockingbird-ts@2.0.0-alpha.1
 - @mockinbird/parser@1.0.1-alpha.2
 - @mockinbird/reflect@1.0.1-alpha.2
 - @mockinbird/types@2.0.0-alpha.1

* chore(repo): add lerna commit message for version command

* docs(repo): update readme and the api docs [skip ci]

* fix(types): change the values inside 'files' array in package.json

* chore(repo): version packages

 - mockingbird-ts@2.0.0-alpha.2
 - @mockinbird/parser@1.0.1-alpha.3
 - @mockinbird/reflect@1.0.1-alpha.3
 - @mockinbird/types@2.0.0-alpha.2

* chore(repo): update docs and sample (#62)

[skip ci]

* feat(mockingbird-ts,parser): add ability to pass an object for extra configuartion (#64)

* feat(types): add class-keys type

* feat(parser): add rich api for overriding and ignoring properties

Add new rich API that enables to override or ignore some properties

closes #63

* refactor(parser): add 'parse' method overloads

* feat(mockingbird-ts): modify generator and builder to work with the new parser (unit tested)

* test(parser): add cases and fix parser test to add callback fn for overrides

* test(mockingbird-ts): add more cases to mock generator integration test

* chore(repo): add lint-staged in git hooks pre-commit

* refactor(types): remove class keys type

* chore(mockingbird-ts): fix lint typo

* chore(mockingbird-ts): remove redundant unrelated code

* chore(repo): add codecov.yml file (#67)

Add new settings for codecov and coverage threshold

* chore(repo): update codecov settings

Add codecov patch default target

* feat(mockingbird-ts): extend builder abilities  (#68)

* chore(repo): remove default options for coverage, add it to test command

* chore(repo): add jest gherkin and refactor some jest settings

* feat(mockingbird-ts): add some more functionality for builder, split into private folder

* chore(repo): add source maps to build

* docs(mockingbird-ts): rewrite some text in readme file

* chore(mockingbird-ts): move generator into dedicated folder

* chore(repo): add jest-gherkin + add to jest config

* test(mockingbird-ts): add some more cases to builder

* ci(repo): refactor some workflow functions

* test(mockingbird-ts): change test commands to gherkin

* refactor(mockingbird-ts): change some methods name and fix tests + add some types

* refactor(types): change class keys type remove faker

* refactor(parser): change override types

* refactor(parser): fix class-parser test after removing faker option when override

* refactor(mockingbird-ts): change the builder api and change the types related to it

* ci(repo): remove release from master

Remove release from master branch
  • Loading branch information
omermorad committed Jul 31, 2021
1 parent a529236 commit f598ef3
Show file tree
Hide file tree
Showing 126 changed files with 10,928 additions and 20,546 deletions.
11 changes: 7 additions & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
deprecated
packages/**/index.js
packages/**/index.d.ts
packages/**/dist/**/*
node_modules/*
coverage/*
dist
dist/*
*.js
*.d.ts
index.ts
jest.config.js
jest.config.base.js
commitlint.config.js
jest.config.js
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"prettier"
// "prettier/@typescript-eslint"
],
"parserOptions": {
"ecmaVersion": 8
Expand Down Expand Up @@ -38,7 +40,6 @@
"trailingComma": "es5"
}
],
"react/forbid-prop-types": 0,
"no-unused-expressions": 0,
"one-var": 0,
"no-underscore-dangle": [
Expand All @@ -60,6 +61,7 @@
"lines-between-class-members": "off"
},
"env": {
"node": true,
"jest": true
}
}
33 changes: 17 additions & 16 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:
branches:
- master
- release

jobs:
build-and-test:
Expand All @@ -20,37 +21,37 @@ jobs:
with:
ref: ${{ github.head_ref }}

- name: Get NPM Cache Directory Path
id: npm-cache-dir
run: echo "::set-output name=dir::$(npm config get cache)"

- name: Lint Commit Message
run: |
npm i -D @commitlint/config-conventional
echo $(git log -1 --pretty=format:"%s") | npx commitlint
- name: Get Yarn Cache Directory Path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Use NodeJS ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: NPM CI
id: npm-cache
- name: Yarn Init
id: yarn-cache
uses: actions/cache@v2
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-
${{ runner.os }}-yarn-
- name: Lint Commit Message
run: |
yarn add -D -W @commitlint/config-conventional
echo $(git log -1 --pretty=format:"%s") | yarn commitlint
- name: Lint Source
run: npm run lint
run: yarn lint-staged

- name: Build
run: npm run build
run: yarn build

- name: Test
run: npm run test:cov
run: yarn test:cov

- name: Upload Report to Codecov
uses: codecov/codecov-action@v1
Expand Down
29 changes: 12 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ name: Release
on:
push:
branches:
- release
- alpha
- beta
- master

jobs:
main:
name: Main
Expand All @@ -21,32 +20,28 @@ jobs:
with:
node-version: 14

- name: Install Dependecies
run: npm install
- name: Yarn Install Dependecies
run: yarn

- name: Lint Commit Message
run: echo $(git log -1 --pretty=format:"%s") | npx commitlint
run: |
yarn add -D -W @commitlint/config-conventional
echo $(git log -1 --pretty=format:"%s") | yarn commitlint
- name: Lint Source
run: npm run lint
run: yarn lint

- name: Build
run: npm run build
run: yarn build

- name: Test
run: npm run test:cov
run: yarn test:cov

- name: Upload Report to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./coverage
fail_ci_if_error: true
fail_ci_if_error: false
files: ./coverage/cobertura-coverage.xml
name: codecov-umbrella

- name: Release
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
name: codecov-umbrella
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ lerna-debug.log*
.DS_Store

# Tests
/coverage
coverage
/sample/coverage
/.nyc_output

Expand All @@ -38,3 +38,4 @@ lerna-debug.log*
junit.xml
.gitconfig
.circleci
!.husky
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
42 changes: 0 additions & 42 deletions .releaserc.json

This file was deleted.

64 changes: 34 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
[![ISC license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
[![npm version](http://img.shields.io/npm/v/mockingbird-ts.svg?style=flat)](https://npmjs.org/package/mockingbird-ts "View this project on npm")
[![Codecov Coverage](https://img.shields.io/codecov/c/github/omermorad/mockingbird-ts/master.svg?style=flat-square)](https://codecov.io/gh/omermorad/mockingbird-ts)
[![Master](https://github.com/omermorad/mockingbird-ts/actions/workflows/release.yml/badge.svg?branch=release)](https://github.com/omermorad/mockingbird-ts/actions)
[![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)
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)

<p align="center">
<img width="450" src="https://raw.githubusercontent.com/omermorad/mockingbird-ts/master/docs/logo.png" alt="Mockingbird Logo" />

<h1 align="center">Mockingbird</h1>

<h3 align="center">
Decorator Powered TypeScript Library for Creating Mocks
The First TypeScript Mocking Framework
</h3>

<h4 align="center">
Expand All @@ -19,10 +18,9 @@
</p>

## Installation
Install the package alongside `faker` and `@types/faker` peer dependencies:

```bash
npm i mockingbird-ts faker @types/faker
npm i -D mockingbird-ts
```

## Usage
Expand All @@ -35,58 +33,64 @@ import { Mock, MockFactory } from 'mockingbird-ts';
class Dog {
@Mock(faker => faker.name.firstName())
readonly name: string;

@Mock()
readonly birthday: Date; // Will generate a recent date

@Mock()
readonly goodPoints: number; // Will generate a random number
}

const result = MockFactory.create<Dog>(Dog);
const oneDog = MockFactory(Dog).one();
const lotsOfDogs = MockFactory(Dog).many(3);
```

## Documentation

There are many more options that you can use with the `@Mock` decorator (and also the `MockFactory`). \
[Click here to jump to the full documentation and explore the full API](https://github.com/omermorad/faker.ts/blob/master/docs/README.md)

**Besides, we have also created a full working example for you; [you can find it under
the sample folder](https://github.com/omermorad/mockingbird-ts/tree/master/sample)**

**Besides, we have also created a full working example for
you; [you can find it under the sample folder](https://github.com/omermorad/mockingbird-ts/tree/master/sample)**

## Playground
**We have created a [REPL Playground](https://repl.it/@omermorad/Mockingbird-Playground) where you can see Mockingbird in action!**

**We have created a [REPL Playground](https://repl.it/@omermorad/Mockingbird-Playground) where you can see Mockingbird
in action!**

## Use Cases
- Generate fake (but reasonable) data for your integration tests
- Prepare as many of different fixtures for your tests
- Persist the

## Motivation
When it comes to writing unit tests of large projects containing different and
diverse entities, mocks are widely used to simulate real data.

Creating mocks can be a tedious and cumbersome process and is usually created
manually or by using libraries like Faker or Chance, which also do not offer a complete solution,
especially not when deciding to develop in TypeScript and most of the code becomes object oriented.
When it comes to writing tests of large projects containing different and diverse entities, mocks (sometimes called "
fixtures") are widely used to simulate real data.

Therefore, we thought of a convenient and efficient solution that allows the use
of only one decorator, Mock decorator that allows to create mocks by placing it above the properties of the class.
Creating mocks (or fixtures) can be a tedious and cumbersome process and is usually created manually or by using
libraries like Faker or Chance, which also do not offer a complete solution, especially not when you write TypeScript
only, and most of the code is object-oriented and arranged with classes.

Mockingbird offers several options for creating mocks, including the use of the
well-known library Faker, which allows you to create information such as a fake email, a fake username,
a fake address and more.
We came up with a simple (and efficient) yet super convenient solution: all you have to do to get fixtures out of the
box is to decorate your classes (whether it's an entity, or a model representing the database layer) and generate simple
or complex fixtures.

### What is faker.js (aka Faker)?
For those of you who are unfamiliar with `faker.js`, it is an old library written
with pure JavaScript, which is used to "generate massive amounts of fake data in
the browser and Node".
Mockingbird offers several options for creating mocks, including the use of the well-known library Faker, which allows
you to create data such as a fake email, a fake username, a fake address and more.u to create information such as a fake
email, a fake username, a fake address and more.

Fake data is usually needed for testing purposes, to assist in the development process itself,
and sometimes, also for the purpose of demonstrations and training.
### What is `faker.js` (aka Faker)?

Mockingbird uses Faker under the hood and making it possible to use faker.js in
a "TypeScript" way, and thereby allows to create mocks that are meaningful like
email, first name, address and many more.
For those of you who are unfamiliar with `faker.js`, it is a library which is used to "generate massive amounts of fake data in the browser and Node".

Mockingbird uses `faker.js` under the hood, making it possible to use Faker in it's "TypeScript" way, and thereby allows
to create mocks that are meaningful like email, first name, address and many more.

## License

Distributed under the MIT License. See `LICENSE` for more information.

## Acknowledgements

[faker.js](https://github.com/marak/Faker.js)
8 changes: 8 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
coverage:
status:
project:
default:
target: 95%
patch:
default:
target: 95%
18 changes: 18 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const {
utils: { getPackages },
} = require('@commitlint/config-lerna-scopes');

module.exports = {
extends: ['@commitlint/config-conventional', '@commitlint/config-lerna-scopes'],
rules: {
'scope-enum': async (ctx) => [
2,
'always',
[
...(await getPackages(ctx)),
'release',
'repo',
],
],
},
};
Loading

0 comments on commit f598ef3

Please sign in to comment.