npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fixture-repository

v1.4.2

Published

[![CircleCI](https://circleci.com/gh/Trendyol/nodejs-fixture-repository.svg?style=svg)](https://circleci.com/gh/Trendyol/nodejs-fixture-repository)

Downloads

2,478

Readme

CircleCI

Fixture Repository

This package meant to be used for faking object values based on typescript types in order to remove burden of faking data in tests. At the moment it only supports interface declarations with primitive types and nested types. Support for enums, types and classes will come later.

Installation

yarn add -D fixture-repository

Types

interface FrOptions {
  ignoreGlob?: string[];
  additionalFiles?: string[];
}

setup(options?: FrOptions): void;
create(str: string): any;

How to use

Assume you have a personModel.ts file and interface declaration like this:

interface IPerson {
  name: string;
  surname: string;
  age: number;
}   

Easiest way to use is calling setup method before with required options first. It takes a glob pattern to match your model files.

import fr from 'fixture-repository';

fr.setup('**/*Model.ts');

const person: IPerson = fr.create('IPerson');

It would generate required properties. It walks through all matched files and extracts interfaces. Calling setup method in every test is something you probably do not want, since it increases time to run the test drastically. Therefore, it would be a good idea to call it earlier in more general scope.

Example Usage With Jest

Jest sandboxes every test environment based on OS cores. So, there is not a way to initiate a single fr setup. The way I prefer to call setup is via custom test environment. Test enviroment is called only once per worker, and since they work in parallel it reduces time to generate fr container. A simple custom environment would be like this:

const NodeEnvironment = require('jest-environment-node');
const fr = require('fixture-repository').default;

fr.setup('src/**/model*/**/*.ts', {
    ignoreGlob: ['**/client*/**']
});

class CustomEnvironment extends NodeEnvironment {
    constructor(config, context) {
        super(config, context);
        this.testPath = context.testPath;
    }

    async setup() {
        await super.setup();

        this.global.fr = fr;
    }

    async teardown() {
        delete this.global.fr;

        await super.teardown();
    }

    runScript(script) {
        return super.runScript(script);
    }
}

module.exports = CustomEnvironment;

Then in your test you could easily use like this without importing fr ever again.

global.fr.create('IPerson');