Skip to content

Commit

Permalink
Use @webpro/is-subdir + add test
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Dec 19, 2018
1 parent cef3566 commit 522df0c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
4 changes: 1 addition & 3 deletions lib/shell.js
@@ -1,8 +1,8 @@
const path = require('path');
const cpy = require('cpy');
const shell = require('shelljs');
const _ = require('lodash');
const bumpFile = require('bump-file');
const isSubDir = require('@webpro/is-subdir');
const { logExec, logDry } = require('./log');
const { debugShell } = require('./debug');
const { config } = require('./config');
Expand Down Expand Up @@ -71,8 +71,6 @@ const copy = (files, options, target) => {
return cpy(files, target, opts);
};

const isSubDir = (dir = '', base = process.cwd()) => path.relative(dir, base).startsWith('..');

const bump = (files, version) => {
logExec('bump', files, version);
if (config.isDryRun) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -49,6 +49,7 @@
"license": "MIT",
"dependencies": {
"@octokit/rest": "16.1.0",
"@webpro/is-subdir": "1.0.0",
"async-retry": "1.2.3",
"babel-preset-env": "1.7.0",
"babel-register": "6.26.0",
Expand Down
15 changes: 0 additions & 15 deletions test/shell.js
Expand Up @@ -86,21 +86,6 @@ test('copy', async t => {
t.end();
});

test('isSubDir', t => {
t.equal(isSubDir(), false);
t.equal(isSubDir(''), false);
t.equal(isSubDir('.'), false);
t.equal(isSubDir('..'), false);
t.equal(isSubDir('foo'), true);
t.equal(isSubDir('foo/bar'), true);
t.equal(isSubDir('foo', '.'), true);
t.equal(isSubDir('foo/bar', 'foo'), true);
t.equal(isSubDir('', '.'), false);
t.equal(isSubDir('..', '..'), false);
t.equal(isSubDir('..', 'foo'), false);
t.end();
});

test('bump', async t => {
const target = path.resolve(dir);
const manifestA = path.join(target, 'package.json');
Expand Down
27 changes: 26 additions & 1 deletion test/tasks.js
Expand Up @@ -9,7 +9,8 @@ const {
GitCleanWorkingDirError,
GitUpstreamError,
GithubTokenError,
InvalidVersionError
InvalidVersionError,
DistRepoStageDirError
} = require('../lib/errors');

const getMock = config =>
Expand Down Expand Up @@ -124,3 +125,27 @@ test('should throw if invalid increment value is provided', async t => {
shell.rm('-rf', tmp);
t.end();
});

test('should throw if not a subdir is provided for dist.staging', async t => {
const tasks = getMock(
new Config({
increment: 'patch',
'non-interactive': true,
dist: {
repo: 'foo',
stageDir: '..'
}
})
);
shell.mkdir(tmp);
shell.pushd('-q', tmp);
await run('git init');
await run('!touch file1');
await run('git remote add origin foo');
await run('git add file1');
await run('git commit -am "Add file1"');
await t.shouldBailOut(tasks(), DistRepoStageDirError, /`dist.stageDir` \(".."\) must resolve to a sub directory/);
shell.popd('-q');
shell.rm('-rf', tmp);
t.end();
});

0 comments on commit 522df0c

Please sign in to comment.