Giter VIP home page Giter VIP logo

node-fixturify-project's Introduction

node-fixturify-project

CI

A complementary project to fixturify

When implementing JS build tooling it is common to have complete projects as fixture data. Unfortunately fixtures committed to disk can be somewhat to maintain and augment.

The fixturify library is a great way to co-locate tests and their file system fixture information. This project embraces fixturify, but aims to reduce the verbosity when building graphs of node modules and dependencies.

Usage

yarn add fixturify-project
const Project = require('fixturify-project');
const project = new Project('rsvp', '3.1.4');

project.addDependency('mocha', '5.2.0');
project.addDependency('chai', '5.2.0');

project.pkg // => the contents of package.json for the given project
project.files['index.js'] = 'module.exports = "Hello, World!"';

project.writeSync('some/root/');

Which the following files (and most importantly the appropriate file contents:

some/root/rsvp/package.json
some/root/rsvp/index.js
some/root/rsvp/node_modules/mocha/package.json
some/root/rsvp/node_modules/chai/package.json

One can also produce JSON, which can be used directly by fixturify:

// continued from above
const fixturify = require('fixturify');

fixturify.writeSync('some/other/root', project.toJSON());

Advanced

Obviously nested dependencies are common, and are not only supported but somewhat ergonomic:

const Project = require('fixturify-project');
const project = new Project('rsvp', '3.1.4');

// version 1
project.addDependency('a', '1.2.3', a => a.addDependency('d', '3.2.1'));

// version 2
let b = project.addDependency('b', '3.2.3');
let c = b.addDependency('c', '4.4.4');

// and this works recursively:
let e = c.addDependency('e', '5.4.4');

project.writeSync('some/root/');

Which produces:

some/root/rsvp/package.json
some/root/rsvp/index.js
some/root/rsvp/node_modules/a/package.json
some/root/rsvp/node_modules/a/node_modules/d/package.json
some/root/rsvp/node_modules/b/package.json
some/root/rsvp/node_modules/b/node_modules/c/package.json
some/root/rsvp/node_modules/b/node_modules/c/node_modules/e/package.json

Other API

  • Project.fromJSON(json, name) consume a given project from JSON
  • Project.fromDir(pathToProject) consume a given project from disk, infer name and version from the existing package.json`
  • Project.fromDir(root, name) consume a given project from disk, assuming it has been written to by Project.prototype.writeSync(root);
  • Project.prototype.root the path that Project.prototype.writeSync will write to by default, if not specified as constructor argument will default to a temp directory
  • Project.prototype.pkg the projects package.json represented as an in-memory POJO.
  • Project.prototype.files a POJO (in the format of fixturify) representing the files within the project root
  • Project.prototype.clone() deep clone a given project
  • Project.prototype.readSync(root) assumes the state of the given root (symmetrical to Project.prototype.writeSync(root))
  • Project.prototype.writeSync(root) writes the project to disk at root
  • Project.prototype.addDependency(name, version) add a dependency to the given project
  • Project.prototype.addDevDependency(name, version) add a devDependency to the given project
  • Project.prototype.dispose() immediately delete the given projects tmp directories. If left not invoked, these files will be deleted when the process exists.

node-fixturify-project's People

Contributors

stefanpenner avatar rwjblue avatar ef4 avatar twokul avatar chadhietala avatar melsumner avatar dependabot[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.