Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/batrdn/mocking-bird
mocking-bird provides a set of simple, yet accurate and context-aware fixture generation tools for schema or database models. Currently mongoose and graphql fixture generation is supported
https://github.com/batrdn/mocking-bird
faker javascript mock-data mock-data-generator mongoose-fixture nodejs testing-tools typescript
Last synced: about 1 month ago
JSON representation
mocking-bird provides a set of simple, yet accurate and context-aware fixture generation tools for schema or database models. Currently mongoose and graphql fixture generation is supported
- Host: GitHub
- URL: https://github.com/batrdn/mocking-bird
- Owner: batrdn
- License: mit
- Created: 2024-02-10T14:24:58.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-03-30T15:01:19.000Z (9 months ago)
- Last Synced: 2024-11-16T02:38:58.798Z (about 2 months ago)
- Topics: faker, javascript, mock-data, mock-data-generator, mongoose-fixture, nodejs, testing-tools, typescript
- Language: TypeScript
- Homepage:
- Size: 992 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Mocking Bird
![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)
Testing with real-world data scenarios is crucial, but creating such data shouldn't be a chore. Therefore, this project
aims to provide a simple and easy, yet accurate and context-aware data generation for your models or
schemas, so that it makes your testing experience smooth. Whether it is for unit tests, integration tests or stress
tests, you can use it to easily generate fake data with flexible custom options and constraints.What does it mean to be context-aware? It means that the generated data is not just some random-random value, but it's
generated in a way that it's suitable for the fields and constraints of your model or schema.For example, if you have a field
`workEmail` in your model, the generated data will be a valid email address, and not just a random string.# Packages
Mocking Bird is a package-based repo using [Nx](https://nx.dev/). To see how individual packages work in detail, please refer to the respective READMEs.
- [@mocking-bird/core](./packages/core)
- [@mocking-bird/mongoose](./packages/mongoose/README.md)
- [@mocking-bird/graphql](./packages/graphql/README.md)To contribute to the project with a new package, please refer to the [contribution guidelines](CONTRIBUTING.md).
# Examples
### Mongoose Fixture
```typescript
import { Schema } from 'mongoose';
import { MongooseFixture } from '@mocking-bird/mongoose';const schema = new Schema({
name: String,
email: String,
age: { type: Number, min: 18, max: 100 },
workEmail: String,
address: {
street: String,
city: String,
country: String,
},
createdAt: Date,
updatedAt: Date,
});const fixture = new MongooseFixture(schema);
const data = fixture.generate();
```**Example output:**
```json
{
"name": "Turner, Thompson and Mueller",
"email": "[email protected]",
"age": 55,
"workEmail": "[email protected]",
"address": {
"street": "Apt. 123 1234",
"city": "Lake Ethylburgh",
"country": "Gambia"
},
"createdAt": "2023-09-11T05:38:59.576Z",
"updatedAt": "2024-02-26T08:25:16.412Z",
"_id": "a84f58e2fcff9dfaf148d7bf"
}
```### GraphQL Fixture
```typescript
import { GraphQLFixture } from '@mocking-bird/graphql';
import { GraphQLSchema } from 'graphql';const typeDefs = `
type User {
name: String
email: String
age: Int
workEmail: String
address: Address
createdAt: Date
updatedAt: Date
}type Address {
street: String
city: String
country: String
}
`;GraphQLSchema.registerSchema(typeDefs);
// TypedDocumentNode is a fully typed graphql document node
// For more information: https://github.com/dotansimha/graphql-typed-document-node
const fixture = new GraphQLFixture(TypedDocumentNode);
const data = fixture.generate();
```# Running tests
Depending on which directory you are in, you can run the tests for the respective package.
`npm run test`
In the root directory, it will run the tests for only affected packages.
Alternatively, you could directly use `nx` to run the tests.
```
npx nx affected -t test --parallel
npx nx run-many --target=test --all
```# License
The MIT License (MIT) 2024 - [Bat-Erdene Tsogoo](https://github.com/batrdn). Please have a look at the
[LICENSE](LICENSE.md) for more details.