-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CHANGE: @W-16092798@ Update workspace to be optional and add testtools (
#36)
- Loading branch information
1 parent
5d2a2d4
commit 39d669d
Showing
26 changed files
with
166 additions
and
153 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
19 changes: 19 additions & 0 deletions
19
packages/code-analyzer-core/test/conversion-safety.test.ts
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,19 @@ | ||
import {LogLevel, RuleType, SeverityLevel} from "../src"; | ||
import * as engApi from "@salesforce/code-analyzer-engine-api"; | ||
|
||
// Currently the LogLevel, RuleType, and SeverityLevel enums from the engine api have the same values as their | ||
// counterparts in core. But if there values every get out of sync, then this test will serve as a reminder to update | ||
// all of our code where we use the "as" cast operator to convert from one to another. | ||
describe('Tests to check that we can safely convert enums to and from core and the engine api', () => { | ||
it('When converting engApi.LogLevel to LogLevel or vice-verca, make sure the enums are the same', () => { | ||
expect(LogLevel).toEqual(engApi.LogLevel); | ||
}); | ||
|
||
it('When converting engApi.RuleType to RuleType or vice-verca, make sure the enums are the same', () => { | ||
expect(RuleType).toEqual(engApi.RuleType); | ||
}); | ||
|
||
it('When converting engApi.SeverityLevel to SeverityLevel or vice-verca, make sure the enums are the same', () => { | ||
expect(SeverityLevel).toEqual(engApi.SeverityLevel); | ||
}); | ||
}); |
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
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
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,5 @@ | ||
// TODO: We will gradually fill this in with test tools that engines can use for testing purposes | ||
|
||
export { | ||
createWorkspace | ||
} from "./workspace" |
48 changes: 48 additions & 0 deletions
48
packages/code-analyzer-engine-api/src/testtools/workspace.ts
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,48 @@ | ||
import {Workspace} from "../engines"; | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
|
||
export function createWorkspace(absFilesAndFolders: string[], workspaceId: string = 'someWorkspaceId'): Workspace { | ||
return new WorkspaceForTesting(workspaceId, absFilesAndFolders); | ||
} | ||
|
||
class WorkspaceForTesting implements Workspace { | ||
private readonly workspaceId: string; | ||
private readonly filesAndFolders: string[]; | ||
private expandedFiles?: string[]; | ||
|
||
constructor(workspaceId: string, absFilesAndFolders: string[]) { | ||
this.workspaceId = workspaceId; | ||
this.filesAndFolders = absFilesAndFolders; | ||
} | ||
|
||
getWorkspaceId(): string { | ||
return this.workspaceId; | ||
} | ||
|
||
getFilesAndFolders(): string[] { | ||
return this.filesAndFolders; | ||
} | ||
|
||
async getExpandedFiles(): Promise<string[]> { | ||
if (!this.expandedFiles) { | ||
this.expandedFiles = await expandToListAllFiles(this.filesAndFolders); | ||
} | ||
return this.expandedFiles as string[]; | ||
} | ||
} | ||
|
||
export async function expandToListAllFiles(absoluteFileOrFolderPaths: string[]): Promise<string[]> { | ||
const allFiles: string[] = []; | ||
async function processPath(currentPath: string): Promise<void> { | ||
if ((await fs.promises.stat(currentPath)).isDirectory()) { | ||
const subPaths: string[] = await fs.promises.readdir(currentPath); | ||
const absSubPaths: string[] = subPaths.map(f => path.join(currentPath, f)); | ||
await Promise.all(absSubPaths.map(processPath)); // Process subdirectories recursively | ||
} else { | ||
allFiles.push(currentPath); | ||
} | ||
} | ||
await Promise.all(absoluteFileOrFolderPaths.map(processPath)); | ||
return allFiles.sort(); | ||
} |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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,22 @@ | ||
import * as testTools from "../src/testtools"; | ||
import {Workspace} from "../src"; | ||
import path from "node:path"; | ||
|
||
describe('Tests for the various testtools', () => { | ||
it('The createWorkspace tool returns a fully functional workspace for testing purposes', async () => { | ||
const sampleWorkspaceFolder: string = path.resolve(__dirname, 'test-data', 'sampleWorkspace'); | ||
const workspace: Workspace = testTools.createWorkspace([sampleWorkspaceFolder]); | ||
expect(workspace.getWorkspaceId()).toEqual("someWorkspaceId"); | ||
expect(workspace.getFilesAndFolders()).toEqual([sampleWorkspaceFolder]); | ||
expect(await workspace.getExpandedFiles()).toEqual([ | ||
path.join(sampleWorkspaceFolder, 'someFile.txt'), | ||
path.join(sampleWorkspaceFolder, 'sub1', 'someFileInSub1.txt'), | ||
path.join(sampleWorkspaceFolder, 'sub1', 'sub2', 'someFile1InSub2.txt'), | ||
path.join(sampleWorkspaceFolder, 'sub1', 'sub2', 'someFile2InSub2.txt'), | ||
path.join(sampleWorkspaceFolder, 'sub1', 'sub3', 'someFileInSub3.txt'), | ||
]); | ||
|
||
const workspace2: Workspace = testTools.createWorkspace([sampleWorkspaceFolder], 'aDifferentWorkspaceId'); | ||
expect(workspace2.getWorkspaceId()).toEqual('aDifferentWorkspaceId'); | ||
}); | ||
}); |
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
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.