From 7c22efbf844815570fbec352efb7c270dc41db61 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Thu, 28 Jan 2016 13:59:21 +0800 Subject: [PATCH] Add tests --- .gitignore | 2 ++ bin/unpm-install | 9 ++++++--- notes.txt | 4 ++-- package.json | 6 +++++- test/index.js | 29 +++++++++++++++++++++++++++++ test/support/prepare.js | 13 +++++++++++++ test/support/sepia.js | 3 +++ 7 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 test/index.js create mode 100644 test/support/prepare.js create mode 100644 test/support/sepia.js diff --git a/.gitignore b/.gitignore index 3c3629e647..b3a3aec6cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +fixtures +.tmp diff --git a/bin/unpm-install b/bin/unpm-install index 98af677276..498e0d524e 100755 --- a/bin/unpm-install +++ b/bin/unpm-install @@ -36,16 +36,19 @@ const cli = require('meow')([ * Perform */ -if (!module.parent) { +function run (cli) { var ctx = {} - getPath() + return getPath() .then(path => updateContext(path)) .then(_ => installMultiple(ctx, cli.input, join(ctx.root, 'node_modules'), cli.flags)) - .catch(require('../lib/err')) function updateContext (root) { ctx.root = root ctx.tmp = join(root, 'node_modules', '.tmp') } } + +module.exports = run + +if (!module.parent) run(cli).catch(require('../lib/err')) diff --git a/notes.txt b/notes.txt index ea9e7ae3d5..903bbc0431 100644 --- a/notes.txt +++ b/notes.txt @@ -1,8 +1,8 @@ todo: - - [ ] put in proper node_modules - - [ ] dedupe by default + - [x] put in proper node_modules - [ ] npm install "rimraf@>2 <3" + - [ ] scoped modules how it should look like: diff --git a/package.json b/package.json index 85698924b9..e7d03e61ef 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "node test | tap-spec" }, "author": "Rico Sta. Cruz ", "license": "MIT", @@ -27,8 +27,12 @@ "unpm-install": "bin/unpm-install" }, "devDependencies": { + "@rstacruz/tap-spec": "4.1.1", "debug": "2.2.0", "mkdirp": "0.5.1", + "nixt": "0.5.0", + "sepia": "2.0.1", + "tape": "4.4.0", "thenify": "3.1.1" } } diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000000..5fcc8e0aad --- /dev/null +++ b/test/index.js @@ -0,0 +1,29 @@ +var test = require('tape') +var join = require('path').join +var prepare = require('./support/prepare') +require('./support/sepia') + +test('small with dependencies (rimraf)', function (t) { + prepare() + require('../bin/unpm-install')({ + input: ['rimraf@2.5.1'] + }) + .then(function (res) { + var rimraf = require(join(process.cwd(), 'node_modules', 'rimraf')) + t.ok(typeof rimraf === 'function', 'rimraf is available') + t.end() + }, t.end) +}) + +test('no dependencies (lodash)', function (t) { + prepare() + require('../bin/unpm-install')({ + input: ['lodash@4.0.0'] + }) + .then(function (res) { + var _ = require(join(process.cwd(), 'node_modules', 'lodash')) + t.ok(typeof _ === 'function', '_ is available') + t.ok(typeof _.clone === 'function', '_.clone is available') + t.end() + }, t.end) +}) diff --git a/test/support/prepare.js b/test/support/prepare.js new file mode 100644 index 0000000000..1a50bfa411 --- /dev/null +++ b/test/support/prepare.js @@ -0,0 +1,13 @@ +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var fs = require('fs') +var join = require('path').join +var root = process.cwd() +process.env.ROOT = root + +module.exports = function prepare () { + rimraf.sync(join(root, '.tmp')) + mkdirp.sync(join(root, '.tmp')) + fs.writeFileSync(join(root, '.tmp', 'package.json'), '{}', 'utf-8') + process.chdir(join(root, '.tmp')) +} diff --git a/test/support/sepia.js b/test/support/sepia.js new file mode 100644 index 0000000000..e26b0c5592 --- /dev/null +++ b/test/support/sepia.js @@ -0,0 +1,3 @@ +process.env.VCR_MODE = 'cache' +require('sepia') +