This repository was archived by the owner on Aug 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
Implement npm install foo --save equivalent #118
Open
wombleton
wants to merge
6
commits into
caolan:master
Choose a base branch
from
wombleton:save
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
02f6d1a
Implement npm install foo --save equivalent
wombleton 3d54c94
Remove save-dev and all for running from any directory.
wombleton 3470920
Add test to scripts property
wombleton 9df9888
Add integration test for install --save
wombleton ff8288a
Handle error for cpDir
wombleton 2a60f02
Handle dependencies being at top level
wombleton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /** | ||
| * Test description | ||
| * ================ | ||
| * | ||
| * Tests that jam install --save adds to package.json | ||
| * | ||
| * Starting with project with *ranged* deps in package.json | ||
| * - jam publish package-one @ 0.0.1 | ||
| * - jam publish package-two @ 0.0.1 | ||
| * - jam install package-one --save, test package.json updated | ||
| */ | ||
|
|
||
|
|
||
| var couchdb = require('../../lib/couchdb'), | ||
| logger = require('../../lib/logger'), | ||
| env = require('../../lib/env'), | ||
| utils = require('../utils'), | ||
| async = require('async'), | ||
| http = require('http'), | ||
| path = require('path'), | ||
| ncp = require('ncp').ncp, | ||
| fs = require('fs'), | ||
| _ = require('underscore'); | ||
|
|
||
|
|
||
| var pathExists = fs.exists || path.exists; | ||
|
|
||
|
|
||
| logger.clean_exit = true; | ||
|
|
||
| // CouchDB database URL to use for testing | ||
| var TESTDB = process.env['JAM_TEST_DB'], | ||
| BIN = path.resolve(__dirname, '../../bin/jam.js'), | ||
| ENV = {JAM_TEST: 'true', JAM_TEST_DB: TESTDB}; | ||
|
|
||
| if (!TESTDB) { | ||
| throw 'JAM_TEST_DB environment variable not set'; | ||
| } | ||
|
|
||
| // remove trailing-slash from TESTDB URL | ||
| TESTDB = TESTDB.replace(/\/$/, ''); | ||
|
|
||
|
|
||
| exports.setUp = function (callback) { | ||
| // change to integration test directory before running test | ||
| this._cwd = process.cwd(); | ||
| process.chdir(__dirname); | ||
|
|
||
| // recreate any existing test db | ||
| couchdb(TESTDB).deleteDB(function (err) { | ||
| if (err && err.error !== 'not_found') { | ||
| return callback(err); | ||
| } | ||
| // create test db | ||
| couchdb(TESTDB).createDB(callback); | ||
| }); | ||
| }; | ||
|
|
||
| exports.tearDown = function (callback) { | ||
| // change back to original working directory after running test | ||
| process.chdir(this._cwd); | ||
| // delete test db | ||
| couchdb(TESTDB).deleteDB(callback); | ||
| }; | ||
|
|
||
|
|
||
| exports['project with ranged dependencies in package.json'] = { | ||
|
|
||
| setUp: function (callback) { | ||
| this.project_dir = path.resolve(env.temp, 'jamtest-' + Math.random()); | ||
| // set current project to empty directory | ||
| ncp('./fixtures/project-rangedeps', this.project_dir, callback); | ||
| }, | ||
|
|
||
| /* | ||
| tearDown: function (callback) { | ||
| var that = this; | ||
| // clear current project | ||
| //utils.myrimraf(that.project_dir, callback); | ||
| }, | ||
| */ | ||
|
|
||
| 'publish, install, ls, remove': function (test) { | ||
| test.expect(1); | ||
| var that = this; | ||
| process.chdir(that.project_dir); | ||
|
|
||
| async.series([ | ||
| async.apply( | ||
| utils.runJam, | ||
| ['publish', path.resolve(__dirname, 'fixtures', 'package-one')], | ||
| {env: ENV} | ||
| ), | ||
| async.apply( | ||
| utils.runJam, | ||
| ['publish', path.resolve(__dirname, 'fixtures', 'package-two')], | ||
| {env: ENV} | ||
| ), | ||
| async.apply(utils.runJam, ['install', 'package-one', '--save'], {env: ENV}), | ||
| function (cb) { | ||
| fs.readFile(path.resolve(that.project_dir, 'package.json'), function(err, data) { | ||
| data = JSON.parse(data); | ||
|
|
||
| test.same(data.jam.dependencies, { | ||
| "package-one": "0.0.1", | ||
| "package-two": "<=0.0.2" | ||
| }); | ||
| cb(); | ||
| }); | ||
| } | ||
| ], | ||
| test.done); | ||
| } | ||
|
|
||
| }; | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes the dependences are stored in the jam property. storing dependencies on the root of the package.json is acceptable. So you should test which way the current package is setup (if any)