Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
fixturify-project
Advanced tools
[![Build Status](https://travis-ci.org/stefanpenner/node-fixturify-project.svg?branch=master)](https://travis-ci.org/stefanpenner/node-fixturify-project) [![Build status](https://ci.appveyor.com/api/projects/status/li9y4rjfjt7fmvpc/branch/master?svg=true)
The fixturify-project npm package is a utility for creating and managing file system fixtures in a programmatic way. It is particularly useful for testing and development purposes, allowing you to easily set up and tear down file system states.
Creating a new project
This feature allows you to create a new project with a specified structure. In this example, a new project named 'my-app' is created with a single file 'index.js' containing a simple console log statement.
const { Project } = require('fixturify-project');
const project = new Project('my-app', {
files: {
'index.js': 'console.log("Hello, world!");'
}
});
project.writeSync();
Adding files to an existing project
This feature allows you to add new files to an existing project. In this example, a new file 'new-file.js' is added to the 'my-app' project with a console log statement.
const { Project } = require('fixturify-project');
const project = new Project('my-app');
project.files['new-file.js'] = 'console.log("New file");';
project.writeSync();
Reading project files
This feature allows you to read the files of an existing project. In this example, the files of the 'my-app' project are read and logged to the console.
const { Project } = require('fixturify-project');
const project = new Project('my-app');
project.readSync();
console.log(project.files);
Deleting files from a project
This feature allows you to delete files from an existing project. In this example, the 'index.js' file is deleted from the 'my-app' project.
const { Project } = require('fixturify-project');
const project = new Project('my-app');
delete project.files['index.js'];
project.writeSync();
The mock-fs package allows you to mock the file system in Node.js. It is useful for testing purposes, as it lets you create, read, and manipulate a virtual file system without affecting the real file system. Compared to fixturify-project, mock-fs focuses more on mocking the file system for testing rather than creating and managing project structures.
The memfs package provides an in-memory file system that can be used for testing and development. It allows you to create, read, and manipulate files and directories in memory. Compared to fixturify-project, memfs is more focused on providing an in-memory file system rather than managing project structures.
The fs-extra package extends the native Node.js file system module with additional methods for easier file and directory manipulation. It includes methods for copying, moving, and removing files and directories. Compared to fixturify-project, fs-extra provides more general file system utilities rather than focusing on project structure management.
A complementary project to node-fixturify
When implementing JS build tooling it is common to have complete projects as fixture data. Unfortunately fixtures commited to disk can be somewhat to maintain and augment.
The node-fixturify library is a great way to co-locate tests and their file system fixture information. This project embraces node-fixturify, but aims to reduce the verbosity when building graphs of node modules and dependencies.
yarn add node-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.addFile('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 node-fixturify:
// continued from above
const fixturify = require('fixturify');
fixturify.writeSync('some/other/root', project.toJSON());
Obviously nested dependencies are common, and are not only supported but somewhat ergonomics:
const Project = require('node-fixturify-project');
const project = new Project('rsvp', '3.1.4');
// version 1
project.addDependecy('a', '1.2.3', a => a.addDependency('d', '3.2.1'));
// version 2
let b = project.addDependecy('b', '3.2.3');
let c = b.addDependency('c', '4.4.4');
// and this works recurisively:
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
Project.fromJSON(json, name)
consume a given project from JSONProject.fromDir(root, name)
consume a given project from disk, assuming it has been written to by Project.prototype.writeSync(root)
;Project.prototype.clone()
deep clone a given projectProject.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 projectProject.prototype.addDevDependency(name, version)
add a devDependency to the given projectFAQs
[![npm version](https://badge.fury.io/js/fixturify-project.svg)](https://badge.fury.io/js/fixturify-project) [![CI](https://github.com/stefanpenner/node-fixturify-project/workflows/CI/badge.svg)](https://github.com/stefanpenner/node-fixturify-project/acti
The npm package fixturify-project receives a total of 377,601 weekly downloads. As such, fixturify-project popularity was classified as popular.
We found that fixturify-project demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers 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 researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.