Skip to content

Commit

Permalink
Add more tests for resolutions feature (#4180)
Browse files Browse the repository at this point in the history
* add tests with offline mirror

* add fixtures
  • Loading branch information
kaylieEB authored and arcanis committed Aug 16, 2017
1 parent e96c896 commit 034f461
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 2 deletions.
27 changes: 27 additions & 0 deletions __tests__/commands/install/resolutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import {getPackageVersion, isPackagePresent, runInstall} from '../_helpers.js';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;

test.concurrent('install with simple exact resolutions should override all versions', (): Promise<void> => {
return runInstall({}, {source: 'resolutions', cwd: 'simple-exact'}, async config => {
expect(await getPackageVersion(config, 'a')).toEqual('1.0.0');
Expand All @@ -24,3 +26,28 @@ test.concurrent('install with subtree exact resolutions should override subtree
expect(await getPackageVersion(config, 'c/left-pad')).toEqual('1.1.2');
});
});

test.concurrent('install with exotic resolutions should override versions', (): Promise<void> => {
return runInstall({}, {source: 'resolutions', cwd: 'exotic-version'}, async config => {
expect(await getPackageVersion(config, 'left-pad')).toEqual('1.1.1');
});
});

test.concurrent('install with range resolutions should override versions', (): Promise<void> => {
return runInstall({}, {source: 'resolutions', cwd: 'simple-range'}, async config => {
expect(await getPackageVersion(config, 'left-pad')).toEqual('1.1.1');
});
});
test.concurrent('should warn when resolution entries are incorrrect or incompatible', async (): Promise<void> => {
let error;

try {
await runInstall({}, {source: 'resolutions', cwd: 'invalid-entries'});
} catch (e) {
error = e.message;
}

expect(error).toContain('Resolution field "[email protected]" is incompatible with requested version "left-pad@~1.1.0');
expect(error).toContain('Resolution field "wrongversion" has an invalid version entry and may be ignored');
expect(error).toContain('Resolution field "invalidname/" does not end with a valid package name and will be ignored');
});
2 changes: 1 addition & 1 deletion __tests__/fixtures/install/resolutions/c-1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "c",
"version": "1.0.0",
"dependencies": {
"left-pad": "~1.1.1"
"left-pad": "~1.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn-offline-mirror "./mirror-for-offline"
Binary file not shown.
10 changes: 10 additions & 0 deletions __tests__/fixtures/install/resolutions/exotic-version/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "project",
"version": "1.0.0",
"dependencies": {
"c": "file:../c-1"
},
"resolutions": {
"left-pad": "https://github.com/stevemao/left-pad.git#1.1.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "project",
"version": "1.0.0",
"dependencies": {
"c": "file:../c-1"
},
"resolutions": {
"c/**/left-pad": "1.0.0",
"invalidname/": "1.0.0",
"**/left-pad": "wrongversion"
}
}
10 changes: 10 additions & 0 deletions __tests__/fixtures/install/resolutions/simple-range/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "project",
"version": "1.0.0",
"dependencies": {
"c": "file:../c-1"
},
"resolutions": {
"left-pad": "<=1.1.1"
}
}
2 changes: 1 addition & 1 deletion src/resolution-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class ResolutionMap {
const {pattern, range} = resolutions.find(({globPattern}) => minimatch(modulePath, globPattern)) || {};

if (pattern) {
if (semver.validRange(range) && semver.valid(reqRange) && !semver.satisfies(range, reqRange)) {
if (semver.validRange(reqRange) && semver.valid(range) && !semver.satisfies(range, reqRange)) {
this.reporter.warn(this.reporter.lang('incompatibleResolutionVersion', pattern, reqPattern));
}
}
Expand Down

0 comments on commit 034f461

Please sign in to comment.