Skip to content

Commit

Permalink
Add tests for getRepositoryRoot fn
Browse files Browse the repository at this point in the history
  • Loading branch information
isachivka committed Oct 13, 2020
1 parent 74756cb commit 70b9da0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module.exports = {
env: {
node: 1,
mocha: 1,
},
parserOptions: {
ecmaVersion: 2020,
Expand Down
8 changes: 7 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@ const getImport = (context, callback) => {
};
};

module.exports = { isSubPath, packages, getImport, pathToImport };
module.exports = {
isSubPath,
packages,
getImport,
pathToImport,
getRepositoryRoot,
};
19 changes: 19 additions & 0 deletions tests/utils/getRepositoryRoot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

const assert = require('assert');
const path = require('path');

describe('getRepositoryRoot', () => {
it('should detect root path in monorepository', () => {
const pkgPath = path.resolve(
__dirname,
'./mocks/repo-with-workspaces/package/',
);

process.chdir(pkgPath);

const utils = require('../../lib/utils');

assert.ok(utils.getRepositoryRoot() === path.resolve(pkgPath, '..'));
});
});
4 changes: 4 additions & 0 deletions tests/utils/mocks/repo-with-workspaces/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"private": true,
"workspaces": ["./"]
}
Empty file.

0 comments on commit 70b9da0

Please sign in to comment.