🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

fixturify-project

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fixturify-project - npm Package Compare versions

Comparing version

to
1.1.0

43

index.js

@@ -16,3 +16,7 @@ 'use strict';

this.validate();
this.files = {};
this.files = {
'index.js': `
'use strict';
module.exports = {};`
};
this.isDependency = true;

@@ -123,2 +127,10 @@ }

removeDependency(name) {
delete this._dependencies[name];
}
removeDevDependency(name) {
delete this._devDependencies[name];
}
addDevDependency(name, version, cb) {

@@ -163,10 +175,2 @@ let dep;

addFile(file, contents) {
if (file === 'package.json') {
throw new Error('cannot add package.json');
}
this.files[file] = contents;
}
toJSON() {

@@ -192,5 +196,24 @@ return {

function parseScoped(name) {
let matched = name.match(/@([^@\/]+)\/(.*)/);
if (matched) {
return {
scope: matched[1],
name: matched[2],
};
}
return null;
}
function depsAsObject(modules) {
let obj = {};
modules.forEach(dep => obj[dep.name] = dep.toJSON()[dep.name]);
modules.forEach(dep => {
let scoped = parseScoped(dep.name);
if (scoped) {
let root = obj['@' + scoped.scope] = obj['@' + scoped.scope] || {};
root[scoped.name] = dep.toJSON()[dep.name];
} else {
obj[dep.name] = dep.toJSON()[dep.name];
}
});
return obj;

@@ -197,0 +220,0 @@ }

{
"name": "fixturify-project",
"version": "1.0.1",
"version": "1.1.0",
"main": "index.js",

@@ -17,4 +17,5 @@ "repository": "git@github.com:stefanpenner/node-fixturify-project",

"scripts": {
"test": "mocha test"
"test": "mocha test",
"test:debug": "mocha debug test"
}
}

@@ -5,3 +5,3 @@ # node-fixturify-project

A complementary project to [node-fixturify](https://github.com/joliss/node-fixturify)
A complementary project to [fixturify](https://github.com/joliss/node-fixturify)

@@ -12,4 +12,4 @@ When implementing JS build tooling it is common to have complete projects as

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
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.

@@ -45,3 +45,3 @@

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

@@ -60,3 +60,3 @@ ```js

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

@@ -63,0 +63,0 @@

@@ -22,13 +22,24 @@ 'use strict';

function read(file) {
return fs.readFileSync(file, 'UTF8');
}
function readDir(path) {
return fs.readdirSync(path);
}
it('has the basic', function() {
let project = new Project('rsvp', '3.1.4');
project.addFile('index.js', `module.exports = "Hello, World!";`);
project.files['index.js'] = `module.exports = "Hello, World!";`;
project.addDependency('ember-cli', '3.1.1', cli => cli.addDependency('console-ui', '3.3.3')).addDependency('rsvp', '3.1.4');
project.addDevDependency('ember-source', '3.1.1');
project.addDevDependency('@ember/ordered-set', '3.1.1');
project.writeSync(ROOT);
let index = fs.readFileSync(`${ROOT}/rsvp/index.js`, 'UTF8');
let nodeModules = fs.readdirSync(`${ROOT}/rsvp/node_modules`);
let index = read(`${ROOT}/rsvp/index.js`, 'UTF8');
let nodeModules = readDir(`${ROOT}/rsvp/node_modules`);
expect(read(`${ROOT}/rsvp/index.js`)).to.eql(`module.exports = "Hello, World!";`);
expect(readJSON(`${ROOT}/rsvp/package.json`, 'UTF8')).to.eql({

@@ -42,2 +53,3 @@ name: 'rsvp',

devDependencies: {
'@ember/ordered-set': '3.1.1',
'ember-source': '3.1.1'

@@ -47,2 +59,5 @@ },

expect(read(`${ROOT}/rsvp/node_modules/ember-source/index.js`)).to.contain(`module.exports`);
expect(require(`${ROOT}/rsvp/node_modules/ember-source/index.js`)).to.eql({});
expect(readJSON(`${ROOT}/rsvp/node_modules/ember-source/package.json`, 'UTF8')).to.eql({

@@ -67,2 +82,8 @@ name: 'ember-source',

expect(read(`${ROOT}/rsvp/node_modules/ember-cli/node_modules/console-ui/index.js`)).to.contain(`module.exports`);
expect(require(`${ROOT}/rsvp/node_modules/ember-cli/node_modules/console-ui/index.js`)).to.eql({});
expect(read(`${ROOT}/rsvp/node_modules/@ember/ordered-set/index.js`)).to.contain(`module.exports`);
expect(require(`${ROOT}/rsvp/node_modules/@ember/ordered-set/index.js`)).to.eql({});
expect(readJSON(`${ROOT}/rsvp/node_modules/ember-cli/node_modules/console-ui/package.json`, 'UTF8')).to.eql({

@@ -76,4 +97,4 @@ name: 'console-ui',

expect(nodeModules.sort()).to.eql([
'@ember',
'ember-cli',

@@ -86,2 +107,18 @@ 'ember-source'

it('supports removing packages', function() {
const input = new Project('foo', '3.1.2');
input.addDependency('rsvp', '4.4.4', rsvp => rsvp.addDependency('mkdirp', '4.4.4'));
input.addDevDependency('omg', '4.4.4', omg => omg.addDependency('fs-extra', '5.5.5.'));
expect(input.dependencies().map(dep => dep.name)).to.eql(['rsvp']);
expect(input.devDependencies().map(dep => dep.name)).to.eql(['omg']);
input.removeDependency('rsvp');
input.removeDevDependency('omg');
expect(input.dependencies().map(dep => dep.name)).to.eql([]);
expect(input.devDependencies().map(dep => dep.name)).to.eql([]);
});
it('requires name and version', function() {

@@ -88,0 +125,0 @@ expect(() => new Project('rsvp', null)).to.throw(/rsvp is missing a version/);