Skip to content

Commit

Permalink
fix: mock package json instead of fs
Browse files Browse the repository at this point in the history
  • Loading branch information
amphro committed Oct 12, 2020
1 parent 70c8ef8 commit 8cba4d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/sfdxProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export class SfdxProjectJson extends ConfigFile<ConfigFile.Options> {
// Always end in a path sep for standardization on folder paths
const fullPath = `${dirname(this.getPath())}${sep}${name}${sep}`;

if (!fs.existsSync(fullPath)) {
if (!this.doesPackageExist(fullPath)) {
throw new SfdxError(
'InvalidPackageDirectory',
this.messages.getMessage('InvalidPackageDirectory', [packageDir.path])
Expand Down Expand Up @@ -304,6 +304,10 @@ export class SfdxProjectJson extends ConfigFile<ConfigFile.Options> {
return this.getContents().packageDirectories && this.getContents().packageDirectories.length > 1;
}

private doesPackageExist(packagePath: string) {
return fs.existsSync(packagePath);
}

private validateKeys(): void {
// Verify that the configObject does not have upper case keys; throw if it does. Must be heads down camel case.
const upperCaseKey = sfdc.findUpperCaseKeys(this.toObject(), SfdxProjectJson.BLOCKLIST);
Expand Down
5 changes: 2 additions & 3 deletions src/testSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ import { Crypto } from './crypto';
import { Logger } from './logger';
import { Messages } from './messages';
import { SfdxError } from './sfdxError';
import { SfdxProject } from './sfdxProject';
import { SfdxProject, SfdxProjectJson } from './sfdxProject';
import { CometClient, CometSubscription, StreamingExtension } from './status/streamingClient';
import { fs } from './util/fs';

/**
* Different parts of the system that are mocked out. They can be restored for
Expand Down Expand Up @@ -345,7 +344,7 @@ export const stubContext = (testContext: TestContext) => {
testContext.rootPathRetrieverSync(isGlobal, testContext.id)
);

testContext.SANDBOXES.DEFAULT.stub(fs, 'existsSync').callsFake(() => true);
stubMethod(testContext.SANDBOXES.PROJECT, SfdxProjectJson.prototype, 'doesPackageExist').callsFake(() => true);

const initStubForRead = (configFile: ConfigFile<ConfigFile.Options>): ConfigStub => {
const stub: ConfigStub = testContext.configStubs[configFile.constructor.name] || {};
Expand Down

0 comments on commit 8cba4d1

Please sign in to comment.