Skip to content

Commit c8d1bf5

Browse files
feat: display dependencies
1 parent 1fa2e94 commit c8d1bf5

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

test/commands/package/packageVersion.nut.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,94 @@ describe('package:version:*', () => {
470470
});
471471
});
472472

473+
describe('package:version:displaydependencies', () => {
474+
type PackageVersionCreateRequestResult = {
475+
Id: string;
476+
Package2Version: {
477+
SubscriberPackageVersionId: string;
478+
};
479+
};
480+
let devHubOrg: Org;
481+
let configAggregator: ConfigAggregator;
482+
let testPackageRequestId: string; // 08c ID
483+
let testSubscriberPackageVersionId: string; // 04t ID
484+
485+
before('dependencies project setup', async () => {
486+
const query = 'SELECT Id, Package2Version.SubscriberPackageVersionId FROM Package2VersionCreateRequest LIMIT 10';
487+
configAggregator = await ConfigAggregator.create();
488+
devHubOrg = await Org.create({ aliasOrUsername: configAggregator.getPropertyValue<string>('target-dev-hub') });
489+
const pvRecords = (await devHubOrg.getConnection().tooling.query<PackageVersionCreateRequestResult>(query))
490+
.records;
491+
492+
if (!pvRecords || pvRecords.length === 0) {
493+
throw new Error('No package version create requests found with dependency graph json');
494+
}
495+
const pv = pvRecords[0];
496+
testPackageRequestId = pv.Id;
497+
testSubscriberPackageVersionId = pv.Package2Version.SubscriberPackageVersionId;
498+
});
499+
it('should print the correct DOT code output (default)', () => {
500+
const command = `package:version:displaydependencies -p ${testPackageRequestId}`;
501+
const result = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
502+
expect(result).to.contain('strict digraph G {');
503+
const hasValidNode = result.includes('node_');
504+
expect(hasValidNode).to.be.true;
505+
expect(result).to.match(/label="[^"]*@\d\.\d\.\d\.\d"/);
506+
const hasMultipleNodes = result.split('\n').filter((line) => line.includes('node_')).length > 1;
507+
if (hasMultipleNodes) {
508+
expect(result).to.contain('->');
509+
}
510+
});
511+
it('should print the correct DOT code output (verbose)', () => {
512+
const command = `package:version:displaydependencies -p ${testPackageRequestId} --verbose`;
513+
const result = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
514+
expect(result).to.contain('strict digraph G {');
515+
const hasSubscriberPackageVersionId = /\(04t.{15}\)/.test(result);
516+
const hasVersionBeingBuilt = result.includes('(VERSION_BEING_BUILT)');
517+
expect(hasSubscriberPackageVersionId || hasVersionBeingBuilt).to.be.true;
518+
});
519+
it('should print the correct DOT code output (json)', () => {
520+
const command = `package:version:displaydependencies -p ${testPackageRequestId} --json`;
521+
const result = execCmd<string>(command, { ensureExitCode: 0 });
522+
const dotCode = result.jsonOutput?.result;
523+
expect(dotCode).to.be.a('string');
524+
expect(dotCode).to.contain('strict digraph G {');
525+
});
526+
it('should print the correct DOT code output (root-last)', () => {
527+
const commandRootFirst = `package:version:displaydependencies -p ${testPackageRequestId} --edge-direction root-first`;
528+
const resultRootFirst = execCmd(commandRootFirst, { ensureExitCode: 0 }).shellOutput.stdout;
529+
const commandRootLast = `package:version:displaydependencies -p ${testPackageRequestId} --edge-direction root-last`;
530+
const resultRootLast = execCmd(commandRootLast, { ensureExitCode: 0 }).shellOutput.stdout;
531+
expect(resultRootFirst).to.contain('strict digraph G {');
532+
expect(resultRootLast).to.contain('strict digraph G {');
533+
const hasMultipleNodes = ((resultRootFirst.match(/node_/g) && resultRootLast.match(/node_/g)) || []).length > 1;
534+
if (hasMultipleNodes) {
535+
const edgeLinesFirst = resultRootFirst.match(/\t node_\w+ -> node_\w+/g) || [];
536+
const edgeLinesLast = resultRootLast.match(/\t node_\w+ -> node_\w+/g) || [];
537+
expect(edgeLinesFirst.length).to.equal(edgeLinesLast.length);
538+
expect(resultRootFirst).to.not.equal(resultRootLast);
539+
} else {
540+
expect(resultRootFirst).to.contain('node_');
541+
expect(resultRootLast).to.contain('node_');
542+
}
543+
});
544+
it('should work with 04t package version ID if available', function () {
545+
if (!testSubscriberPackageVersionId) {
546+
this.skip();
547+
}
548+
const command = `package:version:displaydependencies -p ${testSubscriberPackageVersionId}`;
549+
const result = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
550+
expect(result).to.contain('strict digraph G {');
551+
const hasValidNode = result.includes('node_');
552+
expect(hasValidNode).to.be.true;
553+
expect(result).to.match(/label="[^"]*@\d\.\d\.\d\.\d"/);
554+
const hasMultipleNodes = result.split('\n').filter((line) => line.includes('node_')).length > 1;
555+
if (hasMultipleNodes) {
556+
expect(result).to.contain('->');
557+
}
558+
});
559+
});
560+
473561
describe('package:version:ancestrydisplay', () => {
474562
type PackageVersionQueryResult = PackagingSObjects.Package2Version & {
475563
Package2: {

0 commit comments

Comments
 (0)