Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
factory-mate
Advanced tools
FactoryMate is a TypeScript-based fixture library for instatiating domain objects for testing purposes.
FactoryMate can be installed via NPM:
npm install --save-dev factory-mate
Given a simple domain object:
// GroceryItem.ts
export class GroceryItem {
public groceryName = '';
}
A factory can be registered using FactoryMate.define()
:
import { FactoryMate } from 'factory-mate';
import { GroceryItem } from './GroceryItem';
FactoryMate.define(GroceryItem, (): GroceryItem => {
const groceryItem = new GroceryItem();
groceryItem.groceryName = 'crispy chips';
return groceryItem;
});
FactoryMate.define()
takes two arguments:
Every time FactoryMate is used to create an instance of the registered object, that instance's properties will have the same values as those defined in template. To build an instance of a registered class:
const groceryItem: GroceryItem = FactoryMate.build(GroceryItem.name);
console.log(JSON.stringify(groceryItem)); // '{"groceryName":"crispy chips"}'
It is recommended that a factory class be created for each domain object. Factory classes can be created by annotating the new class with @FactoryMateAware
and calling the static FactoryMate.define()
method in that class:
// GroceryItemFactory.ts
import { FactoryMate, FactoryMateAware } from 'factory-mate';
import { GroceryItem } from './GroceryItem';
@FactoryMateAware
export class GroceryItemFactory {
// The @FactoryMateAware annotation will automatically call the define() funtion at runtime
public define() {
FactoryMate.define(GroceryItem, (): GroceryItem => {
const groceryItem = new GroceryItem();
groceryItem.groceryName = 'crispy chips';
return groceryItem;
});
}
}
If for specific tests there is a need to override one or more variables in the template, this can be accomplished via an optional parameter to build
:
const groceryItem: GroceryItem = FactoryMate.build(GroceryItem.name,
(u: GroceryItem) => {
u.groceryName = 'chunky cookies';
});
To build several objects of the same type:
const groceryItems: GroceryItem[] = FactoryMate.buildMany(GroceryItem.name, 3);
An example project using FactoryMate can be found here FactoryMateConsumer
FactoryMate is distributed under the MIT license
v1.0.1 - July 9, 2017
npm publish
was run from the wrong local directory
for v1.0.0 and therefore had to be republished with a new patch version)FAQs
TypeScript library for building domain objects
The npm package factory-mate receives a total of 2 weekly downloads. As such, factory-mate popularity was classified as not popular.
We found that factory-mate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.