Skip to content

Commit 034f461

Browse files
kaylieEBarcanis
authored andcommitted
Add more tests for resolutions feature (#4180)
* add tests with offline mirror * add fixtures
1 parent e96c896 commit 034f461

File tree

8 files changed

+62
-2
lines changed

8 files changed

+62
-2
lines changed

__tests__/commands/install/resolutions.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

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

5+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;
6+
57
test.concurrent('install with simple exact resolutions should override all versions', (): Promise<void> => {
68
return runInstall({}, {source: 'resolutions', cwd: 'simple-exact'}, async config => {
79
expect(await getPackageVersion(config, 'a')).toEqual('1.0.0');
@@ -24,3 +26,28 @@ test.concurrent('install with subtree exact resolutions should override subtree
2426
expect(await getPackageVersion(config, 'c/left-pad')).toEqual('1.1.2');
2527
});
2628
});
29+
30+
test.concurrent('install with exotic resolutions should override versions', (): Promise<void> => {
31+
return runInstall({}, {source: 'resolutions', cwd: 'exotic-version'}, async config => {
32+
expect(await getPackageVersion(config, 'left-pad')).toEqual('1.1.1');
33+
});
34+
});
35+
36+
test.concurrent('install with range resolutions should override versions', (): Promise<void> => {
37+
return runInstall({}, {source: 'resolutions', cwd: 'simple-range'}, async config => {
38+
expect(await getPackageVersion(config, 'left-pad')).toEqual('1.1.1');
39+
});
40+
});
41+
test.concurrent('should warn when resolution entries are incorrrect or incompatible', async (): Promise<void> => {
42+
let error;
43+
44+
try {
45+
await runInstall({}, {source: 'resolutions', cwd: 'invalid-entries'});
46+
} catch (e) {
47+
error = e.message;
48+
}
49+
50+
expect(error).toContain('Resolution field "[email protected]" is incompatible with requested version "left-pad@~1.1.0');
51+
expect(error).toContain('Resolution field "wrongversion" has an invalid version entry and may be ignored');
52+
expect(error).toContain('Resolution field "invalidname/" does not end with a valid package name and will be ignored');
53+
});

__tests__/fixtures/install/resolutions/c-1/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"name": "c",
33
"version": "1.0.0",
44
"dependencies": {
5-
"left-pad": "~1.1.1"
5+
"left-pad": "~1.1.0"
66
}
77
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarn-offline-mirror "./mirror-for-offline"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "project",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"c": "file:../c-1"
6+
},
7+
"resolutions": {
8+
"left-pad": "https://github.com/stevemao/left-pad.git#1.1.1"
9+
}
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "project",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"c": "file:../c-1"
6+
},
7+
"resolutions": {
8+
"c/**/left-pad": "1.0.0",
9+
"invalidname/": "1.0.0",
10+
"**/left-pad": "wrongversion"
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "project",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"c": "file:../c-1"
6+
},
7+
"resolutions": {
8+
"left-pad": "<=1.1.1"
9+
}
10+
}

src/resolution-map.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default class ResolutionMap {
8686
const {pattern, range} = resolutions.find(({globPattern}) => minimatch(modulePath, globPattern)) || {};
8787

8888
if (pattern) {
89-
if (semver.validRange(range) && semver.valid(reqRange) && !semver.satisfies(range, reqRange)) {
89+
if (semver.validRange(reqRange) && semver.valid(range) && !semver.satisfies(range, reqRange)) {
9090
this.reporter.warn(this.reporter.lang('incompatibleResolutionVersion', pattern, reqPattern));
9191
}
9292
}

0 commit comments

Comments
 (0)