Skip to content

Commit 452b168

Browse files
author
Nick Pape
committed
Add tests for PNPM shrinkwrap file
1 parent b74b686 commit 452b168

3 files changed

Lines changed: 50 additions & 3 deletions

File tree

‎apps/rush/src/utilities/ShrinkwrapFile.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ export default abstract class ShrinkwrapFile {
1414
protected _alreadyWarnedSpecs: Set<string> = new Set<string>();
1515

1616
public static loadFromFile(shrinkwrapFilename: string): ShrinkwrapFile | undefined {
17-
return require('./npm/NpmShrinkwrapFile').default.loadFromFile(shrinkwrapFilename)
18-
|| require('./npm/PnpmShrinkwrapFile').default.loadFromFile(shrinkwrapFilename);
17+
try {
18+
return require('./npm/NpmShrinkwrapFile').default.loadFromFile(shrinkwrapFilename);
19+
} catch (e) { /* no-op */ }
20+
try {
21+
return require('./pnpm/PnpmShrinkwrapFile').default.loadFromFile(shrinkwrapFilename);
22+
} catch (e) { /* no-op */ }
23+
throw new Error(`Unable to load shrinkwrap file!`);
1924
}
2025

2126
protected static tryGetValue<T>(dictionary: { [key2: string]: T }, key: string): T | undefined {

‎apps/rush/src/utilities/test/ShrinkwrapFile.test.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as path from 'path';
66

77
import ShrinkwapFile from '../ShrinkwrapFile';
88

9-
describe('ShrinkwrapFile', () => {
9+
describe('NPM ShrinkwrapFile', () => {
1010
const filename: string = path.resolve(path.join(__dirname, './shrinkwrapFile/npm-shrinkwrap.json'));
1111
const shrinkwrapFile: ShrinkwapFile = ShrinkwapFile.loadFromFile(filename)!;
1212

@@ -27,3 +27,26 @@ describe('ShrinkwrapFile', () => {
2727
assert.deepEqual(tempProjectNames, ['@rush-temp/project1', '@rush-temp/project2']);
2828
});
2929
});
30+
31+
describe('PNPM ShrinkwrapFile', () => {
32+
const filename: string = path.resolve(path.join(
33+
__dirname, '../../../src/utilities/test/shrinkwrapFile/shrinkwrap.yaml'));
34+
const shrinkwrapFile: ShrinkwapFile = ShrinkwapFile.loadFromFile(filename)!;
35+
36+
it('verifies root-level dependency', () => {
37+
shrinkwrapFile.hasCompatibleDependency('q', '~1.5.0');
38+
});
39+
40+
it('verifies temp project dependencies', () => {
41+
// Found locally
42+
shrinkwrapFile.hasCompatibleDependency('jquery', '>=2.2.4 <3.0.0');
43+
// Found at root
44+
shrinkwrapFile.hasCompatibleDependency('q', '~1.5.0');
45+
});
46+
47+
it('extracts temp projects successfully', () => {
48+
const tempProjectNames: ReadonlyArray<string> = shrinkwrapFile.getTempProjectNames();
49+
50+
assert.deepEqual(tempProjectNames, ['@rush-temp/project1', '@rush-temp/project2']);
51+
});
52+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
dependencies:
2+
'@rush-temp/project1': 'file:./projects/project1.tgz'
3+
'@rush-temp/project2': 'file:./projects/project2.tgz'
4+
jquery: 2.9.9
5+
q: 1.5.3
6+
packages:
7+
/jquery/2.2.2:
8+
resolution:
9+
integrity: sha1-PjAtxh6zKaIenvrJN9cx8GETTFk=
10+
/q/1.5.3:
11+
resolution:
12+
integrity: sha1-3QG6ydBtMObyGa7LglPunr3DCPE=
13+
registry: 'http://localhost:4873/'
14+
shrinkwrapVersion: 3
15+
specifiers:
16+
'@rush-temp/project1': 'file:./projects/project1.tgz'
17+
'@rush-temp/project2': 'file:./projects/project2.tgz'
18+
jquery: '>=2.2.4 <3.0.0'
19+
q: '~1.5.0'

0 commit comments

Comments
 (0)