Skip to content

Commit 4bbfb73

Browse files
authoredMar 6, 2022
Merge pull request #62 from willryan/update-libraries-and-1.0
Update libraries and 1.0
2 parents 6f1285e + 6103de9 commit 4bbfb73

File tree

7 files changed

+1605
-2914
lines changed

7 files changed

+1605
-2914
lines changed
 

‎.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
build:
88
docker:
99
# specify the version you desire here
10-
- image: circleci/node:14.15
10+
- image: circleci/node:14.17
1111

1212
# Specify service dependencies here if necessary
1313
# CircleCI maintains a library of pre-built images

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [1.0.0] - 2022-03-05
4+
5+
- CONSIDER THIS FILE DEPRECATED. MOVING TO GITHUB RELEASES.
6+
37
## [0.5.1] - 2019-12-06
48

59
- fix typing for combine() and 'required keys'

‎README.md

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# factory.ts
22

3+
[![willryan](https://circleci.com/gh/willryan/factory.ts.svg?style=svg)](https://app.circleci.com/pipelines/github/willryan/factory.ts)
4+
35
A library to ease creation of factories for test data for Typescript
46

57
Given an interface or type definition, create a factory for generating test data. Values for each key may be defaulted or be calculated each time based on a sequence number and the values for other keys.
68

7-
Version 0.3.2 introduces a new set of async factory methods for cases where asynchronicity is required to generate values. See sync.spec.ts for examples.
8-
9-
Version 0.3.3 introduces a pipeline mechanism for building up a key-value set of data. See pipeline.spec.ts for an example.
10-
119
## Installation
1210

1311
Install using yarn:
@@ -42,11 +40,11 @@ interface Person {
4240
import * as Factory from "factory.ts";
4341

4442
const personFactory = Factory.Sync.makeFactory<Person>({
45-
id: Factory.each(i => i),
43+
id: Factory.each((i) => i),
4644
firstName: "Bob",
4745
lastName: "Smith",
4846
fullName: "Robert J. Smith, Jr.",
49-
age: Factory.each(i => 20 + (i % 10))
47+
age: Factory.each((i) => 20 + (i % 10)),
5048
});
5149
```
5250

@@ -57,7 +55,7 @@ You can call `personFactory.build` with a subset of field data (`Partial<Person>
5755
```typescript
5856
const james = personFactory.build({
5957
firstName: "James",
60-
fullName: "James Smith"
58+
fullName: "James Smith",
6159
});
6260
// { id: 1, firstName: 'James', lastName: 'Smith', fullName: 'James Smith', age: 21 };
6361

@@ -89,7 +87,7 @@ Occasionally you may want to extend an existing factory with some changes. For e
8987

9088
```typescript
9189
const anyAgeFactory = personFactory.extend({
92-
age: Factory.each(() => randomAge(0, 100)) // randomAge(min:number, max:number) => number
90+
age: Factory.each(() => randomAge(0, 100)), // randomAge(min:number, max:number) => number
9391
});
9492

9593
anyAgeFactory.build(); // { id: 1, ..., age: <random value> };
@@ -110,7 +108,7 @@ const autoFullNameFactory = personFactory.withDerivation2(
110108

111109
const jamesBond = autoFullNameFactory.build({
112110
firstName: "James",
113-
lastName: "Bond"
111+
lastName: "Bond",
114112
});
115113
// { id: 1, firstName: 'James', lastName: 'Bond', fullName: 'Bond, James Bond', age: 21 };
116114
```
@@ -124,7 +122,7 @@ Alternatively, if you need to read more than 5 properties, or just don't want to
124122
```typescript
125123
const autoFullNameFactory = personFactory.withDerivation(
126124
"fullName",
127-
person => `${person.lName}, ${person.fName} ${person.lName}`
125+
(person) => `${person.lName}, ${person.fName} ${person.lName}`
128126
);
129127
```
130128

@@ -141,10 +139,10 @@ Sometimes you have two factories you want to combine into one. So essentially yo
141139
```typescript
142140
const timeStamps = Sync.makeFactory({
143141
createdAt: Sync.each(() => new Date()),
144-
updatedAt: Sync.each(() => new Date())
142+
updatedAt: Sync.each(() => new Date()),
145143
});
146144
const softDelete = Sync.makeFactory({
147-
isDeleted: false
145+
isDeleted: false,
148146
});
149147
interface Post {
150148
content: string;
@@ -153,7 +151,7 @@ interface Post {
153151
isDeleted: boolean;
154152
}
155153
const postFactory: Sync.Factory<Post> = makeFactory({
156-
content: "lorem ipsum"
154+
content: "lorem ipsum",
157155
})
158156
.combine(timeStamps)
159157
.combine(softDelete);
@@ -179,11 +177,11 @@ interface Person {
179177

180178
const personFactory = Factory.Sync.makeFactoryWithRequired<Person, "parent_id">(
181179
{
182-
id: Factory.each(i => i),
180+
id: Factory.each((i) => i),
183181
firstName: "Bob",
184182
lastName: "Smith",
185183
fullName: "Robert J. Smith, Jr.",
186-
age: Factory.each(i => 20 + (i % 10))
184+
age: Factory.each((i) => 20 + (i % 10)),
187185
}
188186
);
189187

‎jest-setup.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function () {
22
let lastTime = 0;
33
const vendors = ["ms", "moz", "webkit", "o"];
4-
const w: any = window;
4+
const w: any = globalThis;
55
for (let x = 0; x < vendors.length && !w.requestAnimationFrame; ++x) {
66
w.requestAnimationFrame = w[vendors[x] + "RequestAnimationFrame"];
77
w.cancelAnimationFrame =
@@ -27,10 +27,3 @@
2727
};
2828
}
2929
})();
30-
31-
if (process.env.DEBUGGING) {
32-
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5; // five minutes
33-
} else {
34-
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60; // 60 seconds
35-
}
36-

‎package.json

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "factory.ts",
3-
"version": "0.5.2",
3+
"version": "1.0.0",
44
"license": "MIT",
55
"description": "A Typescript test data factory similar to factory_bot and rosie",
66
"scripts": {
@@ -41,23 +41,26 @@
4141
"lib/"
4242
],
4343
"author": "Will Pleasant-Ryan",
44+
"resolutions": {
45+
"@types/istanbul-lib-report": "^3.0.0"
46+
},
4447
"devDependencies": {
45-
"@typescript-eslint/eslint-plugin": "^4.19.0",
46-
"@typescript-eslint/parser": "^4.19.0",
47-
"@types/jest": "^26.0.23",
48-
"@types/node": "^14",
49-
"eslint": "^7.22.0",
50-
"eslint-import-resolver-typescript": "^2.4.0",
51-
"eslint-plugin-import": "^2.22.1",
52-
"eslint-plugin-jest": "^24.3.2",
53-
"jest": "^26.6.3",
48+
"@types/jest": "^27.4.1",
49+
"@types/node": "^17.0.21",
50+
"@typescript-eslint/eslint-plugin": "^5.13.0",
51+
"@typescript-eslint/parser": "^5.13.0",
52+
"eslint": "^8.10.0",
53+
"eslint-import-resolver-typescript": "^2.5.0",
54+
"eslint-plugin-import": "^2.25.4",
55+
"eslint-plugin-jest": "^26.1.1",
56+
"jest": "^27.5.1",
5457
"jest-environment-node-debug": "^2.0.0",
55-
"ts-jest": "^26.5.6",
56-
"ts-node": "^9.1.1",
57-
"typescript": "4.2.4"
58+
"ts-jest": "^27.1.3",
59+
"ts-node": "^10.5.0",
60+
"typescript": "4.5.5"
5861
},
5962
"dependencies": {
6063
"clone-deep": "^4.0.1",
61-
"source-map-support": "^0.5.19"
64+
"source-map-support": "^0.5.21"
6265
}
6366
}

‎spec/sync.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@ describe("factories build stuff", () => {
236236
});
237237

238238
const widgets = widgetFactory.buildList(3);
239-
expect(widgets[2].id).toBe(2);
239+
expect(widgets.map(w => w.id)).toEqual([0, 1, 2]);
240240

241241
widgetFactory.resetSequenceNumber();
242242

243243
const moreWidgets = widgetFactory.buildList(3);
244-
expect(moreWidgets[2].id).toBe(2);
244+
expect(moreWidgets.map(w => w.id)).toEqual([0, 1, 2]);
245245
});
246246
it("Can reset sequence number back to config default", () => {
247247
const widgetFactory = Sync.makeFactory<WidgetType>(

‎yarn.lock

+1,567-2,874
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.