Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ative into start_packager_before_attach
  • Loading branch information
JiglioNero committed Jul 3, 2020
2 parents 7f3230f + 8152571 commit 246527d
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 110 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -797,6 +797,6 @@
"webpack-bundle-analyzer": "^3.8.0"
},
"extensionDependencies": [
"ms-vscode.js-debug-nightly"
"ms-vscode.js-debug"
]
}
2 changes: 2 additions & 0 deletions src/debugger/debugSessionBase.ts
Expand Up @@ -156,6 +156,8 @@ export abstract class DebugSessionBase extends LoggingDebugSession {
}
}

await logger.dispose();

DebugSessionBase.rootSessionTerminatedEventEmitter.fire({
debugSession: this.session,
args: {
Expand Down
7 changes: 7 additions & 0 deletions src/debugger/rnDebugSession.ts
Expand Up @@ -117,6 +117,10 @@ export class RNDebugSession extends DebugSessionBase {
this.appLauncher.setAppWorker(this.appWorker);

this.appWorker.on("connected", (port: number) => {
if (this.cancellationTokenSource.token.isCancellationRequested) {
return this.appWorker?.stop();
}

logger.log(localize("DebuggerWorkerLoadedRuntimeOnPort", "Debugger worker loaded runtime on port {0}", port));

this.appLauncher.getRnCdpProxy().setApplicationTargetPort(port);
Expand All @@ -135,6 +139,9 @@ export class RNDebugSession extends DebugSessionBase {
}
}
});
if (this.cancellationTokenSource.token.isCancellationRequested) {
return this.appWorker.stop();
}
return this.appWorker.start();
});
});
Expand Down
13 changes: 8 additions & 5 deletions src/extension/android/adb.ts
Expand Up @@ -54,11 +54,7 @@ export class AdbHelper {
private launchActivity: string;

constructor(projectRoot: string, logger?: ILogger, launchActivity: string = "MainActivity") {

// Trying to read sdk location from local.properties file and if we succueded then
// we would run adb from inside it, otherwise we would rely to PATH
const sdkLocation = this.getSdkLocationFromLocalPropertiesFile(projectRoot, logger);
this.adbExecutable = sdkLocation ? `${path.join(sdkLocation, "platform-tools", "adb")}` : "adb";
this.adbExecutable = this.getAdbPath(projectRoot, logger);
this.launchActivity = launchActivity;
}

Expand Down Expand Up @@ -162,6 +158,13 @@ export class AdbHelper {
return sdkLocation;
}

public getAdbPath(projectRoot: string, logger?: ILogger): string {
// Trying to read sdk location from local.properties file and if we succueded then
// we would run adb from inside it, otherwise we would rely to PATH
const sdkLocation = this.getSdkLocationFromLocalPropertiesFile(projectRoot, logger);
return sdkLocation ? `"${path.join(sdkLocation, "platform-tools", "adb")}"` : "adb";
}

private parseConnectedDevices(input: string): IDevice[] {
let result: IDevice[] = [];
let regex = new RegExp("^(\\S+)\\t(\\S+)$", "mg");
Expand Down
20 changes: 20 additions & 0 deletions test/extension/android/androidPlatform.test.ts
Expand Up @@ -386,11 +386,31 @@ suite("androidPlatform", function () {
mockPlatform("win32");
testPaths(String.raw`C\:\\Users\\User1\\AndroidSdk`, String.raw`C:\Users\User1\AndroidSdk`);
testPaths(String.raw`\\\\Network\\Shared\\Folder`, String.raw`\\Network\Shared\Folder`);
testPaths(String.raw`\\\\Network\\Shared\\Folder\\Android SDK`, String.raw`\\Network\Shared\Folder\Android SDK`);
testPaths(String.raw`C\:\\Users\\User1\\Android Sdk`, String.raw`C:\Users\User1\Android Sdk`);

mockPlatform("darwin");
testPaths(String.raw`/var/lib/some/path`, String.raw`/var/lib/some/path`);
testPaths(String.raw`~/Library`, String.raw`~/Library`);
testPaths(String.raw`/Users/User1/home/path`, String.raw`/Users/User1/home/path`);
testPaths(String.raw`/Users/User1/home/path/Android SDK`, String.raw`/Users/User1/home/path/Android SDK`);
testPaths(String.raw`/Volumes/Macintosh HD/Users/foo/Library/Android/sdk/platform-tools`, String.raw`/Volumes/Macintosh HD/Users/foo/Library/Android/sdk/platform-tools`);
});

test("AdbHelper getAdbPath function should correctly parse Android Sdk Location from local.properties and wrap with quotes", () => {
function testPaths(expectedPath: string, projectRoot: string) {
const adbHelper = new adb.AdbHelper(projectRoot);
const resultPath = adbHelper.getAdbPath(projectRoot);
assert.equal(resultPath, expectedPath);
}

if (process.platform == "win32") {
const mockProjectRoot = path.join(__dirname, "..", "..", "..", "test", "resources", "auxiliaryFiles", "templateProject", "win");
testPaths(String.raw`"C:\Android\android sdk\platform-tools\adb"`, mockProjectRoot);
} else {
const mockProjectRoot = path.join(__dirname, "..", "..", "..", "test", "resources", "auxiliaryFiles", "templateProject", "others");
testPaths(String.raw`"/Volumes/Macintosh HD/Users/foo/Library/Android/sdk/platform-tools/adb"`, mockProjectRoot);
}
});
});
});
Expand Down
@@ -0,0 +1 @@
sdk.dir=/Volumes/Macintosh HD/Users/foo/Library/Android/sdk/
@@ -0,0 +1 @@
sdk.dir=C\:\\Android\\android sdk
2 changes: 1 addition & 1 deletion test/smoke/docs/run-locally.md
Expand Up @@ -28,7 +28,7 @@ Tests are running using [VS Code automation package](https://github.com/microsof
* **Mac**:
```bash
brew tap caskroom/versions
brew cask install java8
brew cask install adoptopenjdk/openjdk/adoptopenjdk8
brew cask install android-studio
brew install git
brew install watchman
Expand Down
6 changes: 3 additions & 3 deletions test/smoke/package/config.json
Expand Up @@ -5,7 +5,7 @@
"IOS_VERSION": "12.4",
"CODE_VERSION": "1.45.1",
"EXPO_XDL_VERSION": "57.8.32",
"RN_VERSION": "0.62.0",
"PURE_RN_VERSION": "0.59.8",
"PURE_EXPO_VERSION": "36.0.2"
"RN_VERSION": "0.62.2",
"PURE_RN_VERSION": "0.62.2",
"PURE_EXPO_VERSION": "38.0.4"
}
37 changes: 0 additions & 37 deletions test/smoke/package/resources/ExpoSample/App.js

This file was deleted.

24 changes: 24 additions & 0 deletions test/smoke/package/resources/ExpoSample/App.tsx
@@ -0,0 +1,24 @@
console.log("Test output from debuggee");
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { SafeAreaProvider } from 'react-native-safe-area-context';

import useCachedResources from './hooks/useCachedResources';
import useColorScheme from './hooks/useColorScheme';
import Navigation from './navigation';

export default function App() {
const isLoadingComplete = useCachedResources();
const colorScheme = useColorScheme();

if (!isLoadingComplete) {
return null;
} else {
return (
<SafeAreaProvider>
<Navigation colorScheme={colorScheme} />
<StatusBar />
</SafeAreaProvider>
);
}
}
77 changes: 47 additions & 30 deletions test/smoke/package/src/debugAndroid.test.ts
Expand Up @@ -5,7 +5,7 @@ import * as assert from "assert";
import * as path from "path";
import { AppiumHelper, Platform, AppiumClient } from "./helpers/appiumHelper";
import { AndroidEmulatorHelper } from "./helpers/androidEmulatorHelper";
import { sleep, findStringInFile, findExpoURLInLogFile, ExpoLaunch, findExpoSuccessAndFailurePatterns } from "./helpers/utilities";
import { sleep, findStringInFile, findExpoURLInLogFile, ExpoLaunch, findExpoSuccessAndFailurePatterns, waitForRunningPackager } from "./helpers/utilities";
import { SmokeTestsConstants } from "./helpers/smokeTestsConstants";
import { ExpoWorkspacePath, pureRNWorkspacePath, RNworkspacePath, prepareReactNativeProjectForHermesTesting, runVSCode } from "./main";
import { SetupEnvironmentHelper } from "./helpers/setupEnvironmentHelper";
Expand All @@ -22,7 +22,7 @@ const RNHermesAttachConfigName = "Attach to Hermes application - Experimental";
const ExpoDebugConfigName = "Debug in Exponent";
const ExpoLanDebugConfigName = "Debug in Exponent (LAN)";
const ExpoLocalDebugConfigName = "Debug in Exponent (Local)";

const STOP_PACKAGER_COMMAND = "React Native (Preview): Stop Packager";

const RNSetBreakpointOnLine = 1;
const RNHermesSetBreakpointOnLine = 11;
Expand All @@ -48,38 +48,55 @@ export function setup(testParameters?: TestRunArguments) {
}
});

async function expoTest(testName: string, workspacePath: string, debugConfigName: string, triesToLaunchApp: number) {
app = await runVSCode(workspacePath);
console.log(`${testName}: ${workspacePath} directory is opened in VS Code`);
await app.workbench.quickaccess.openFile("App.js");
await app.workbench.editors.scrollTop();
console.log(`${testName}: App.js file is opened`);
await app.workbench.debug.setBreakpointOnLine(ExpoSetBreakpointOnLine);
console.log(`${testName}: Breakpoint is set on line ${ExpoSetBreakpointOnLine}`);
console.log(`${testName}: Chosen debug configuration: ${debugConfigName}`);
async function runExpoDebugScenario(logFilePath: string, testName: string, workspacePath: string, debugConfigName: string, triesToLaunchApp: number) {
console.log(`${testName}: Starting debugging`);
// Scan logs only if launch retries provided (Expo Tunnel scenarios)
if (triesToLaunchApp <= 1) {
await app.workbench.quickaccess.runDebugScenario(debugConfigName);
} else {
if (process.env.REACT_NATIVE_TOOLS_LOGS_DIR) {
for (let retry = 1; retry <= triesToLaunchApp; retry++) {
let expoLaunchStatus: ExpoLaunch;
await app.workbench.quickaccess.runDebugScenario(debugConfigName);
expoLaunchStatus = await findExpoSuccessAndFailurePatterns(path.join(process.env.REACT_NATIVE_TOOLS_LOGS_DIR, SmokeTestsConstants.ReactNativeLogFileName), SmokeTestsConstants.ExpoSuccessPattern, SmokeTestsConstants.ExpoFailurePattern);
if (expoLaunchStatus.successful) {
break;
} else {
if (retry === triesToLaunchApp) {
assert.fail(`App start has failed after ${retry} retries`);
}
console.log(`Attempt to start #${retry} failed, retrying...`);
for (let retry = 1; retry <= triesToLaunchApp; retry++) {
let expoLaunchStatus: ExpoLaunch;
await app.workbench.quickaccess.runDebugScenario(debugConfigName);
expoLaunchStatus = await findExpoSuccessAndFailurePatterns(logFilePath, SmokeTestsConstants.ExpoSuccessPattern, SmokeTestsConstants.ExpoFailurePattern);
if (expoLaunchStatus.successful) {
break;
} else {
if (retry === triesToLaunchApp) {
assert.fail(`App start has failed after ${retry} retries`);
}
console.log(`Attempt to start #${retry} failed, retrying...`);
}
} else {
assert.fail("REACT_NATIVE_TOOLS_LOGS_DIR is not defined");
}
}
}

async function expoTest(appFileName: string, testName: string, workspacePath: string, debugConfigName: string, triesToLaunchApp: number, isPureExpo: boolean = false) {
let logFilePath = "";
app = await runVSCode(workspacePath);
console.log(`${testName}: ${workspacePath} directory is opened in VS Code`);
await app.workbench.quickaccess.openFile(appFileName);
await app.workbench.editors.scrollTop();
console.log(`${testName}: ${appFileName} file is opened`);
await app.workbench.debug.setBreakpointOnLine(ExpoSetBreakpointOnLine);
console.log(`${testName}: Breakpoint is set on line ${ExpoSetBreakpointOnLine}`);
console.log(`${testName}: Chosen debug configuration: ${debugConfigName}`);
if (process.env.REACT_NATIVE_TOOLS_LOGS_DIR) {
logFilePath = path.join(process.env.REACT_NATIVE_TOOLS_LOGS_DIR, SmokeTestsConstants.ReactNativeLogFileName);
} else {
assert.fail("REACT_NATIVE_TOOLS_LOGS_DIR is not defined");
}
await runExpoDebugScenario(logFilePath, testName, workspacePath, debugConfigName, triesToLaunchApp);
// We stop and start Pure Expo debug scenario again, since we faced Metro cache processing problem on
// Expo SDK 38. The debug scenario works fine only on the second and further launches of the packager.
// As soon as this problem is fixed, this condition won't be needed.
if (isPureExpo) {
await waitForRunningPackager(logFilePath);
await sleep(2 * 1000);
await app.workbench.debug.stopDebugging();
await app.workbench.quickaccess.runCommand(STOP_PACKAGER_COMMAND);
await sleep(2 * 1000);
await runExpoDebugScenario(logFilePath, testName, workspacePath, debugConfigName, triesToLaunchApp);
}

await app.workbench.editors.waitForTab("Expo QR Code readonly");
await app.workbench.editors.waitForActiveTab("Expo QR Code readonly");
Expand All @@ -104,7 +121,7 @@ export function setup(testParameters?: TestRunArguments) {
await AppiumHelper.enableRemoteDebugJS(clientInited, Platform.AndroidExpo);
await app.workbench.debug.waitForDebuggingToStart();
console.log(`${testName}: Debugging started`);
await app.workbench.debug.waitForStackFrame(sf => sf.name === "App.js" && sf.lineNumber === ExpoSetBreakpointOnLine, `looking for App.js and line ${ExpoSetBreakpointOnLine}`);
await app.workbench.debug.waitForStackFrame(sf => sf.name === appFileName && sf.lineNumber === ExpoSetBreakpointOnLine, `looking for ${appFileName} and line ${ExpoSetBreakpointOnLine}`);
console.log(`${testName}: Stack frame found`);
await app.workbench.debug.stepOver();
// Wait for debug string to be rendered in debug console
Expand Down Expand Up @@ -198,31 +215,31 @@ export function setup(testParameters?: TestRunArguments) {
this.skip();
}
this.timeout(debugExpoTestTime);
await expoTest("Android Expo Debug test(Tunnel)", ExpoWorkspacePath, ExpoDebugConfigName, 5);
await expoTest("App.tsx","Android Expo Debug test(Tunnel)", ExpoWorkspacePath, ExpoDebugConfigName, 5);
});

it("Pure RN app Expo test(LAN)", async function () {
if (testParameters && testParameters.RunBasicTests) {
this.skip();
}
this.timeout(debugExpoTestTime);
await expoTest("Android pure RN Expo test(LAN)", pureRNWorkspacePath, ExpoLanDebugConfigName, 1);
await expoTest("App.js", "Android pure RN Expo test(LAN)", pureRNWorkspacePath, ExpoLanDebugConfigName, 1, true);
});

it("Expo app Debug test(LAN)", async function () {
if (testParameters && testParameters.RunBasicTests) {
this.skip();
}
this.timeout(debugExpoTestTime);
await expoTest("Android Expo Debug test(LAN)", ExpoWorkspacePath, ExpoLanDebugConfigName, 1);
await expoTest("App.tsx", "Android Expo Debug test(LAN)", ExpoWorkspacePath, ExpoLanDebugConfigName, 1);
});

it("Expo app Debug test(localhost)", async function () {
if (testParameters && testParameters.RunBasicTests) {
this.skip();
}
this.timeout(debugExpoTestTime);
await expoTest("Android Expo Debug test(localhost)", ExpoWorkspacePath, ExpoLocalDebugConfigName, 1);
await expoTest("App.tsx", "Android Expo Debug test(localhost)", ExpoWorkspacePath, ExpoLocalDebugConfigName, 1);
});
});
}

0 comments on commit 246527d

Please sign in to comment.