diff --git a/package.json b/package.json index b28ba07b..cae95685 100644 --- a/package.json +++ b/package.json @@ -419,13 +419,13 @@ "scripts": { "vscode:prepublish": "yarn run compile", "lint": "eslint . --ext .ts", - "pretest": "yarn run lint && tsc --strict --skipLibCheck", + "pretest": "tsc --strict --skipLibCheck", "test:integration": "ts-node ./test/integrationTest.ts", "test:web-client": "mocha web/test/*.test.mjs", "test:system": "ts-node test/systemTest.ts", "test:unit": "mocha test/unit/**/*.test.[tj]s", "test:unit:some": "mocha", - "test": "yarn test:unit && yarn test:web-client && yarn test:integration && yarn test:system", + "test": "yarn test:integration scanner/performAsAppMapsAreModified.test.js", "compile": "NODE_ENV=production tsup --config tsup.config.ts", "watch": "tsup --config tsup.config.ts --watch", "package": "vsce package", diff --git a/src/services/nodeDependencyProcess.ts b/src/services/nodeDependencyProcess.ts index d836d794..a26cda42 100644 --- a/src/services/nodeDependencyProcess.ts +++ b/src/services/nodeDependencyProcess.ts @@ -111,6 +111,15 @@ export class ProcessLog extends Array { } export async function getModulePath(options: ProgramOptions): Promise { + const workspaceFolders = vscode.workspace.workspaceFolders; + if ( + options.dependency === ProgramName.Scanner && + workspaceFolders && + workspaceFolders.length > 0 + ) { + const root = path.resolve(workspaceFolders[0].uri.fsPath, '..', '..', '..', '..'); + return path.join(root, 'appmap-js', 'packages', 'scanner', 'built', 'cli.js'); + } const localToolsPath = ExtensionSettings.appMapCommandLineToolsPath; if (localToolsPath) { let packageName: string; diff --git a/src/services/nodeProcessService.ts b/src/services/nodeProcessService.ts index 5d05b307..104492b5 100644 --- a/src/services/nodeProcessService.ts +++ b/src/services/nodeProcessService.ts @@ -209,7 +209,7 @@ export class NodeProcessService implements WorkspaceService { +// const watches = await executeWorkspaceOSCommand('ps -ef | grep -e --watch', ProjectA); +// console.log('Watches: ', watches); +// } + +async function logIndexDir(): Promise { + const indexDir = await executeWorkspaceOSCommand(`ls -al ${ExampleAppMapIndexDir}`, ProjectA); + console.log(`\nIndex Dir: ${indexDir}`); +} describe('Scanner', () => { + let services: AppMapService; withAuthenticatedUser(); beforeEach(async () => { await initializeWorkspace(); - await waitForAppMapServices( + services = await waitForAppMapServices( 'tmp/appmap/minitest/Microposts_controller_can_get_microposts_as_JSON.appmap.json' ); - await waitFor('Index directory exists', async () => { - return Boolean(await promisify(stat)(ExampleAppMapIndexDir)); - }); + await waitFor('Index directory exists', () => existsSync(ExampleAppMapIndexDir)); }); afterEach(initializeWorkspace); it('is performed as AppMaps are modified', async () => { - await vscode.commands.executeCommand('appmap.deleteAllAppMaps'); + async function removeAndReindex() { + await logIndexDir(); + await vscode.commands.executeCommand('appmap.deleteAllAppMaps'); + rmSync(ExampleAppMapIndexDir, { force: true, recursive: true }); + mkdirSync(ExampleAppMapIndexDir); + await logIndexDir(); + + await waitFor('AppMaps to be deleted', () => services.localAppMaps.appMaps.length === 0); + await waitFor('Diagnostics to be cleared', hasNoDiagnostics); + + const appMapPath = relative(ProjectA, ExampleAppMap); + await restoreFile(appMapPath); + + assert(existsSync(ExampleAppMap)); - await waitFor('Diagnostics were not cleared', hasNoDiagnostics); + await waitFor('AppMap to be re-indexed', () => + existsSync(join(ExampleAppMapIndexDir, 'mtime')) + ); + await logIndexDir(); + } - // KEG: Remove this, as it's failing due to an issue either with IndexJanitor or with the test itself. - // await waitFor( - // `AppMap index dir should be removed`, - // async () => !(await promisify(exists)(ExampleAppMapIndexDir)) - // ); + await removeAndReindex(); - const appMapPath = relative(ProjectA, ExampleAppMap); - await repeatUntil( - async () => await restoreFile(appMapPath), - `AppMap should be reindexed`, - async () => promisify(exists)(join(ExampleAppMapIndexDir, 'mtime')) + await logIndexDir(); + await repeatUntil(removeAndReindex, 'Findings to be generated', () => + existsSync(join(ExampleAppMapIndexDir, 'appmap-findings.json')) ); + await logIndexDir(); - await repeatUntil( - async () => await restoreFile(appMapPath), - 'No Diagnostics were created for Microposts_controller_can_get_microposts_as_JSON', - async () => { - return getDiagnosticsForAppMap(ExampleAppMap).length > 0; - } + await waitFor( + 'diagnostics to be created', + () => getDiagnosticsForAppMap(ExampleAppMap).length > 0 ); const diagnostic = getDiagnosticsForAppMap(ExampleAppMap)[0]; @@ -63,5 +82,6 @@ describe('Scanner', () => { diagnostic.uri.fsPath, join(ProjectA, 'app/controllers/microposts_controller.rb') ); + assert(false); }); }); diff --git a/test/integration/util.ts b/test/integration/util.ts index f9e51eff..684cf3dc 100644 --- a/test/integration/util.ts +++ b/test/integration/util.ts @@ -237,15 +237,18 @@ async function closeAllEditors(): Promise { await vscode.commands.executeCommand('workbench.action.closeAllEditors'); } -export async function executeWorkspaceOSCommand(cmd: string, workspaceName: string): Promise { - return new Promise((resolve, reject) => { +export async function executeWorkspaceOSCommand( + cmd: string, + workspaceName: string +): Promise { + return new Promise((resolve, reject) => { exec(cmd, { cwd: workspaceName }, (err, stdout, stderr) => { if (err) { console.log(stdout); console.warn(stderr); return reject(err); } - resolve(); + resolve(stdout); }); }); } diff --git a/test/integrationTest.ts b/test/integrationTest.ts index 83733996..ea979840 100644 --- a/test/integrationTest.ts +++ b/test/integrationTest.ts @@ -142,6 +142,8 @@ async function integrationTest() { userDataDir, // '--disable-extensions', '--disable-gpu', + '--disable-keytar', + '--password-store=basic', workspaceDir, ], });