Skip to content

Commit

Permalink
Test path structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyEckstein committed Nov 16, 2021
1 parent 00898cf commit e08c7e3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
8 changes: 2 additions & 6 deletions lib/index.js
Expand Up @@ -122,8 +122,7 @@ async function getLatestVersion(name, wanted) {
function getInstalledVersion(currentDir, name, logger) {
try {
// console.warn('path inside getInstalledVersion');
return require(`./test_helpers/${path.join(currentDir, 'node_modules', name, 'package.json')}`)
.version;
return require(path.join(currentDir, 'node_modules', name, 'package.json')).version;
} catch (err) {
logger.info(`Error getting a list of installed modules from package.json - ${err}`);
return null;
Expand Down Expand Up @@ -201,10 +200,7 @@ function removeLockedDependencies(deps) {
*/
async function verifyDeps({ autoUpgrade = false, dir = '', logger = console } = {}) {
// console.warn('path inside verifyDeps', path.join(dir, 'package.json'));
const { dependencies = {}, devDependencies = {} } = require(`./test_helpers/${path.join(
dir,
'package.json'
)}`);
const { dependencies = {}, devDependencies = {} } = require(path.join(dir, 'package.json'));
// console.warn('-->', dependencies, devDependencies);
logger.info(blue('Verifying dependencies…\n'));

Expand Down
9 changes: 6 additions & 3 deletions lib/index.test.js
@@ -1,7 +1,7 @@
'use strict';

const { promisify: getMockExecAsync } = require('util');
// const path = require('path');
const path = require('path');

const verifyDeps = require('.');

Expand All @@ -17,8 +17,8 @@ jest.mock('chalk', () => ({
red: (str) => str
}));

// const { join: mockJoin } = path;
// jest.mock('path', () => ({ join: jest.fn() }));
const { join: mockJoin } = path;
jest.mock('path', () => ({ join: jest.fn() }));

const mockExecAsync = getMockExecAsync();

Expand All @@ -32,6 +32,9 @@ describe('lib/index', () => {

test('should upgrade upto patch versions when versions prefixed with ~', async () => {
const dir = 'dir1';

mockJoin.mockImplementation(() => './test_helpers/test1.js');

// jest.mock(
// `dir1/package.json`,
// () => ({ dependencies: { foo1: '~46.45.44' }, devDependencies: {} }),
Expand Down
1 change: 1 addition & 0 deletions lib/test_helpers/dir1/package.json
@@ -1,4 +1,5 @@
{
"version": "46.45.44",
"dependencies": {
"foo1": "~46.45.44"
},
Expand Down
10 changes: 10 additions & 0 deletions lib/test_helpers/test1.js
@@ -0,0 +1,10 @@
'use strict';

const test = {
dependencies: {
foo1: '~46.45.44'
},
devDependencies: {}
};

module.exports = test;

0 comments on commit e08c7e3

Please sign in to comment.