Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Show name and context on package validation fail
Browse files Browse the repository at this point in the history
  • Loading branch information
LawrenceLoz committed May 21, 2021
1 parent 25db638 commit 44c3f88
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/sfpowerscripts-cli/src/ProjectValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ export default class ProjectValidation {
pkg.versionNumber.match(pattern) &&
(packageType === "Source" || packageType === "Data")
) {
throw new Error('The build-number keywords "NEXT" & "LATEST" are not supported for Source & Data packages. Please use 0 instead');
throw new Error(
'sfdx-project.json validation failed for package "'+pkg["package"]+ '".'
+ ' Build-number keywords "NEXT" & "LATEST" are not supported for '+packageType+' packages.'
+ '\nTry the following:'
+ '\n - If package should be built as a '+packageType+' package, use 0 instead of NEXT/LATEST'
+ '\n - If package should be built as an Unlocked package, ensure the package has been created in the Devhub and the ID included in packageAliases of sfdx-project.json'
);
}
});
}
Expand Down
77 changes: 77 additions & 0 deletions packages/sfpowerscripts-cli/tests/ProjectValidation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,81 @@ describe("Given a sfdx-project.json, it should be validated against the scehma",
expect(() => { new ProjectValidation().validateSFDXProjectJSON(); }).toThrow();
});


it("should not throw an package-specific error for sfdx-project.json when version number is used correctly", () => {

// sfdx-project.json includes one source package with specific build number (valid) and one unlocked package using NEXT keyword (also valid)
let sfdx_project={
"packageDirectories": [
{
"path": "packages/temp",
"default": true,
"package": "temp",
"type": "source",
"versionName": "temp",
"versionNumber": "1.0.0.0"
},
{
"path": "packages/domains/core",
"package": "core",
"default": false,
"versionName": "core",
"versionNumber": "1.0.0.NEXT"
}
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "50.0",
"packageAliases":
{ "core":"04t000000000000" }
};

const projectConfigMock = jest.spyOn(ProjectConfig, "getSFDXPackageManifest");
projectConfigMock.mockImplementation(()=>{return sfdx_project})
expect(() => { new ProjectValidation().validatePackageBuildNumbers(); }).not.toThrow();
});


it("should throw a package-specific error for sfdx-project.json when version number is used incorrectly", () => {

// sfdx-project.json includes two source packages. One with specific build number (valid), one using NEXT keyword (invalid)
let sfdx_project={
"packageDirectories": [
{
"path": "packages/temp",
"default": true,
"package": "temp",
"type": "source",
"versionName": "temp",
"versionNumber": "1.0.0.0"
},
{
"path": "packages/domains/core",
"package": "invalid_core_pkg",
"default": false,
"type": "source",
"versionName": "core",
"versionNumber": "1.0.0.NEXT"
}
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "50.0"
};

const projectConfigMock = jest.spyOn(ProjectConfig, "getSFDXPackageManifest");
projectConfigMock.mockImplementation(()=>{return sfdx_project});

let excep;
try {
new ProjectValidation().validatePackageBuildNumbers();
}
catch(error) {
excep = error;
}

expect(excep);
expect(excep.message).toContain('invalid_core_pkg');
});

});

0 comments on commit 44c3f88

Please sign in to comment.