-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from forcedotcom/jj/W-15640497
NEW (Extension) @W-15640497@ Delta runs on SFGE - Phase 1
- Loading branch information
Showing
6 changed files
with
275 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2024, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import * as fs from 'fs'; | ||
|
||
export function getDeltaRunTarget(sfgecachepath:string, savedFilesCache:Set<string>): string[] { | ||
// Read and parse the JSON file at sfgecachepath | ||
const fileContent = fs.readFileSync(sfgecachepath, 'utf-8'); | ||
const parsedData = JSON.parse(fileContent) as CacheData; | ||
|
||
const matchingEntries: string[] = []; | ||
|
||
// Iterate over each file entry in the data | ||
parsedData.data.forEach((entry: { filename: string, entries: string[] }) => { | ||
// Check if the filename is in the savedFilesCache | ||
if (savedFilesCache.has(entry.filename)) { | ||
// If it matches, add the individual entries to the result array | ||
matchingEntries.push(...entry.entries); | ||
} | ||
}); | ||
|
||
return matchingEntries; | ||
} | ||
|
||
interface CacheEntry { | ||
filename: string; | ||
entries: string[]; | ||
} | ||
|
||
interface CacheData { | ||
data: CacheEntry[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright (c) 2024, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import {expect} from 'chai'; | ||
import Sinon = require('sinon'); | ||
import proxyquire from 'proxyquire'; | ||
|
||
// You can import and use all API from the 'vscode' module | ||
// as well as import your extension to test it | ||
import * as vscode from 'vscode'; | ||
|
||
suite('Delta Run Test Suite', () => { | ||
suite('#getDeltaRunTarget', () => { | ||
let readFileSyncStub: Sinon.SinonStub; | ||
let getDeltaRunTarget: Function; | ||
|
||
// Set up stubs and mock the fs module | ||
setup(() => { | ||
readFileSyncStub = Sinon.stub(); | ||
|
||
// Load the module with the mocked fs dependency | ||
const mockedModule = proxyquire('../../../deltarun/delta-run-service', { | ||
fs: { | ||
readFileSync: readFileSyncStub | ||
} | ||
}); | ||
|
||
// Get the function from the module | ||
getDeltaRunTarget = mockedModule.getDeltaRunTarget; | ||
}); | ||
|
||
teardown(() => { | ||
Sinon.restore(); | ||
}); | ||
|
||
test('Returns matching entries when files in cache match JSON data', () => { | ||
// Setup the mock return value for readFileSync | ||
const sfgecachepath = '/path/to/sfgecache.json'; | ||
const savedFilesCache = new Set<string>([ | ||
'/some/user/path/HelloWorld.cls' | ||
]); | ||
|
||
const jsonData = `{ | ||
"data": [ | ||
{ | ||
"entries": ["/some/user/path/HelloWorld.cls#getProducts", "/some/user/path/HelloWorld.cls#getSimilarProducts"], | ||
"filename": "/some/user/path/HelloWorld.cls" | ||
} | ||
] | ||
}`; | ||
|
||
readFileSyncStub.withArgs(sfgecachepath, 'utf-8').returns(jsonData); | ||
|
||
// Test | ||
const result = getDeltaRunTarget(sfgecachepath, savedFilesCache); | ||
|
||
// Assertions | ||
expect(result).to.deep.equal([ | ||
'/some/user/path/HelloWorld.cls#getProducts', | ||
'/some/user/path/HelloWorld.cls#getSimilarProducts' | ||
]); | ||
|
||
Sinon.assert.calledOnce(readFileSyncStub); | ||
}); | ||
|
||
test('Returns an empty array when no matching files are found in cache', () => { | ||
// ===== SETUP ===== | ||
const sfgecachepath = '/path/to/sfgecache.json'; | ||
const savedFilesCache = new Set<string>([ | ||
'/some/user/path/HelloWorld.cls' | ||
]); | ||
|
||
const jsonData = `{ | ||
"data": [ | ||
{ | ||
"filename": "/some/user/path/NotHelloWorld.cls", | ||
"entries": ["/some/user/path/NotHelloWorld.cls#getProducts"] | ||
} | ||
] | ||
}`; | ||
|
||
// Stub the file read to return the JSON data | ||
readFileSyncStub.withArgs(sfgecachepath, 'utf-8').returns(jsonData); | ||
|
||
// ===== TEST ===== | ||
const result = getDeltaRunTarget(sfgecachepath, savedFilesCache); | ||
|
||
// ===== ASSERTIONS ===== | ||
expect(result).to.deep.equal([]); | ||
|
||
Sinon.assert.calledOnce(readFileSyncStub); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.