Skip to content

Commit

Permalink
Added acceptance test for dryRun.
Browse files Browse the repository at this point in the history
  • Loading branch information
Globegitter committed Apr 1, 2015
1 parent 17a4e5a commit ea5de85
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ results

npm-debug.log
node_modules
tmp
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ $ npm install enpeem --save
var npm = require('enpeem');
```

For all supported options look into the `index.js` `install` and `update` function.

#### npm install

```javascript
Expand All @@ -31,7 +33,11 @@ npm.install({
'[email protected]',
'sails-disk@git://github.com/balderdashy/sails-disk.git#associations',
'lodash'
]
],
prefix: 'custom/path/to/install',
saveDev: true, //--save-dev flag
//saves package to package.json without installing. Only works with save/saveDev option
dryRun: true,
loglevel: 'silent',
'cache-min': 999999999
}, function (err) { /* ... */ });
Expand All @@ -45,5 +51,3 @@ npm.update({
loglevel: 'silent'
}, function (err) { /* ... */ });
```


9 changes: 8 additions & 1 deletion lib/do-npm-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ module.exports = function doNpmCommand(options) {

if ('dryRun' in options && options.dryRun === true) {
if (options.npmCommand === 'install') {
installDryRun(options.cmdArgs, options.cmdOptions);
var result = installDryRun(options.cmdArgs, options.cmdOptions);
return new Promise(function (resolve, reject) {
if (result === true) {
resolve(0);
} else {
reject(result);
}
});
} else {
return new Promise(function (resolve) {
resolve(0);
Expand Down
12 changes: 10 additions & 2 deletions lib/install-dry-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ module.exports = function installDryRun(dependencies, cmdOptions) {
if (cmdOptions.save || cmdOptions['save-dev']) {
var prefix = cmdOptions.prefix || '';
var fileName = path.join(process.cwd(), prefix, 'package.json');
var packageInfo = fs.readFileSync(fileName);
try {
var packageInfo = fs.readFileSync(fileName);
} catch (error) {
return error;
}
var content = JSON.parse(packageInfo);
var packageToSave = '';
var versionToSave = '';
Expand All @@ -47,7 +51,11 @@ module.exports = function installDryRun(dependencies, cmdOptions) {
}
}

fs.writeFileSync(fileName, JSON.stringify(content, null, 2));
try {
fs.writeFileSync(fileName, JSON.stringify(content, null, 2));
} catch (error) {
return error;
}
return true;
}
return true;
Expand Down
10 changes: 7 additions & 3 deletions tests/acceptance/basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ describe('with dryRun option', function () {

before(function () {
tmpdir = tmp.in(tmproot);
this.pathToDep = getPathToDep(dependency, tmpdir);
this.pathToDep = getPathToDep(dependencies[1], tmpdir);
this.pathToPackage = path.resolve(
__dirname, tmpdir, 'package.json'
);
Expand Down Expand Up @@ -268,8 +268,12 @@ describe('with dryRun option', function () {
//require does not work because of caching
var devDependencies = JSON.parse(fs.readFileSync(this.pathToPackage)).devDependencies;
expect(devDependencies).to.include({ 'sane-cli': '^0.0.24', 'koa': '*' });
console.log(fs.lstatSync(this.pathToDep));
// expect(fs.lstatSync(this.pathToDep)).to.be.an('object');
try {
var result = fs.lstatSync(this.pathToDep);
expect(result, 'The module folder should not exist.').to.not.exist; //eslint-disable-line no-unused-expressions
} catch (error) {
expect(error.message).to.include('no such file or directory');
}
});

});
2 changes: 2 additions & 0 deletions tests/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ if (!arg) {
files = 'eslint-test.js';
} else if (arg === 'unit') {
root = 'tests/unit';
} else if (arg === 'acceptance') {
root = 'tests/acceptance';
} else {
root = 'tests/{unit,acceptance}';
}
Expand Down

0 comments on commit ea5de85

Please sign in to comment.