Skip to content

Commit

Permalink
test: fix cli debug failed in windows (#12050)
Browse files Browse the repository at this point in the history
* test: fix cli debug

* test: fix typo

---------

Co-authored-by: Ivan_Chen <v-ivanchen@microsoft.com>
  • Loading branch information
ayachensiyuan and Ivan_Chen authored Jul 24, 2024
1 parent 43bf088 commit 776f0b1
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import { TemplateProjectFolder } from "../../utils/constants";
import { CaseFactory } from "./sampleCaseFactory";

class MyFirstMettingTestCase extends CaseFactory {}
class MyFirstMeetingTestCase extends CaseFactory {}

new MyFirstMettingTestCase(
TemplateProjectFolder.MyFirstMetting,
new MyFirstMeetingTestCase(
TemplateProjectFolder.MyFirstMeeting,
15277468,
"kaiyan@microsoft.com",
["tab"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { Env } from "../../utils/env";
import { it } from "../../utils/it";
import { validateFileExist } from "../../utils/commonUtils";
import { ChildProcessWithoutNullStreams } from "child_process";
import { ChildProcess, ChildProcessWithoutNullStreams } from "child_process";
import { Executor } from "../../utils/executor";
import { expect } from "chai";
import { VSBrowser } from "vscode-extension-tester";
Expand All @@ -29,10 +29,10 @@ import os from "os";
import { initDebugPort } from "../../utils/commonUtils";

describe("Local Debug Tests", function () {
this.timeout(Timeout.testCase);
this.timeout(Timeout.testAzureCase);
let localDebugTestContext: LocalDebugTestContext;
let devtunnelProcess: ChildProcessWithoutNullStreams | null;
let debugProcess: ChildProcessWithoutNullStreams | null;
let debugProcess: ChildProcess | null;
let successFlag = true;
let errorMessage = "";

Expand Down
6 changes: 3 additions & 3 deletions packages/tests/src/ui-test/localdebug/localdebug-bot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { Env } from "../../utils/env";
import { it } from "../../utils/it";
import { validateFileExist } from "../../utils/commonUtils";
import { ChildProcessWithoutNullStreams } from "child_process";
import { ChildProcess, ChildProcessWithoutNullStreams } from "child_process";
import { Executor } from "../../utils/executor";
import { expect } from "chai";
import { VSBrowser } from "vscode-extension-tester";
Expand All @@ -29,10 +29,10 @@ import { initDebugPort } from "../../utils/commonUtils";
import os from "os";

describe("Local Debug Tests", function () {
this.timeout(Timeout.testCase);
this.timeout(Timeout.testAzureCase);
let localDebugTestContext: LocalDebugTestContext;
let devtunnelProcess: ChildProcessWithoutNullStreams | null;
let debugProcess: ChildProcessWithoutNullStreams | null;
let debugProcess: ChildProcess | null;
let successFlag = true;
let errorMessage = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Env } from "../../utils/env";
import { it } from "../../utils/it";
import { killPort, validateFileExist } from "../../utils/commonUtils";
import { ModalDialog, VSBrowser } from "vscode-extension-tester";
import { ChildProcessWithoutNullStreams } from "child_process";
import { ChildProcess, ChildProcessWithoutNullStreams } from "child_process";
import { Executor } from "../../utils/executor";
import { expect } from "chai";
import { getScreenshotName } from "../../utils/nameUtil";
Expand All @@ -36,10 +36,10 @@ import os from "os";

// TODO: Change preview test to normal test before rc release
describe("Command And Response Bot Local Debug Tests", function () {
this.timeout(Timeout.testCase);
this.timeout(Timeout.testAzureCase);
let localDebugTestContext: LocalDebugTestContext;
let devtunnelProcess: ChildProcessWithoutNullStreams | null;
let debugProcess: ChildProcessWithoutNullStreams | null;
let debugProcess: ChildProcess | null;
let successFlag = true;
let errorMessage = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Env } from "../../utils/env";
import { it } from "../../utils/it";
import { killPort, validateFileExist } from "../../utils/commonUtils";
import { ModalDialog, VSBrowser } from "vscode-extension-tester";
import { ChildProcessWithoutNullStreams } from "child_process";
import { ChildProcess, ChildProcessWithoutNullStreams } from "child_process";
import { Executor } from "../../utils/executor";
import { expect } from "chai";
import { getScreenshotName } from "../../utils/nameUtil";
Expand All @@ -36,10 +36,10 @@ import os from "os";

// TODO: Change preview test to normal test before rc release
describe("Command And Response Bot Local Debug Tests", function () {
this.timeout(Timeout.testCase);
this.timeout(Timeout.testAzureCase);
let localDebugTestContext: LocalDebugTestContext;
let devtunnelProcess: ChildProcessWithoutNullStreams | null;
let debugProcess: ChildProcessWithoutNullStreams | null;
let debugProcess: ChildProcess | null;
let successFlag = true;
let errorMessage = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { Env } from "../../utils/env";
import { it } from "../../utils/it";
import { validateFileExist } from "../../utils/commonUtils";
import { ChildProcessWithoutNullStreams } from "child_process";
import { ChildProcess, ChildProcessWithoutNullStreams } from "child_process";
import { Executor } from "../../utils/executor";
import { expect } from "chai";
import { VSBrowser } from "vscode-extension-tester";
Expand All @@ -30,9 +30,9 @@ import { initDebugPort } from "../../utils/commonUtils";
import os from "os";

describe("Local Debug Tests", function () {
this.timeout(Timeout.testCase);
this.timeout(Timeout.testAzureCase);
let localDebugTestContext: LocalDebugTestContext;
let debugProcess: ChildProcessWithoutNullStreams | null;
let debugProcess: ChildProcess | null;
let successFlag = true;
let errorMessage = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { Env } from "../../utils/env";
import { it } from "../../utils/it";
import { validateFileExist } from "../../utils/commonUtils";
import { ChildProcessWithoutNullStreams } from "child_process";
import { ChildProcess, ChildProcessWithoutNullStreams } from "child_process";
import { Executor } from "../../utils/executor";
import { expect } from "chai";
import { VSBrowser } from "vscode-extension-tester";
Expand All @@ -30,9 +30,9 @@ import { initDebugPort } from "../../utils/commonUtils";
import os from "os";

describe("Local Debug Tests", function () {
this.timeout(Timeout.testCase);
this.timeout(Timeout.testAzureCase);
let localDebugTestContext: LocalDebugTestContext;
let debugProcess: ChildProcessWithoutNullStreams | null;
let debugProcess: ChildProcess | null;
let successFlag = true;
let errorMessage = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Env } from "../../utils/env";
import { it } from "../../utils/it";
import { killPort, validateFileExist } from "../../utils/commonUtils";
import { ModalDialog, VSBrowser } from "vscode-extension-tester";
import { ChildProcessWithoutNullStreams } from "child_process";
import { ChildProcess, ChildProcessWithoutNullStreams } from "child_process";
import { Executor } from "../../utils/executor";
import { expect } from "chai";
import { getScreenshotName } from "../../utils/nameUtil";
Expand All @@ -37,10 +37,10 @@ import os from "os";

// TODO: Change preview test to normal test before rc release
describe("Workflow Bot Local Debug Tests", function () {
this.timeout(Timeout.testCase);
this.timeout(Timeout.testAzureCase);
let localDebugTestContext: LocalDebugTestContext;
let devtunnelProcess: ChildProcessWithoutNullStreams | null;
let debugProcess: ChildProcessWithoutNullStreams | null;
let debugProcess: ChildProcess | null;
let successFlag = true;
let errorMessage = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Env } from "../../utils/env";
import { it } from "../../utils/it";
import { killPort, validateFileExist } from "../../utils/commonUtils";
import { ModalDialog, VSBrowser } from "vscode-extension-tester";
import { ChildProcessWithoutNullStreams } from "child_process";
import { ChildProcess, ChildProcessWithoutNullStreams } from "child_process";
import { Executor } from "../../utils/executor";
import { expect } from "chai";
import { getScreenshotName } from "../../utils/nameUtil";
Expand All @@ -37,10 +37,10 @@ import os from "os";

// TODO: Change preview test to normal test before rc release
describe("Workflow Bot Local Debug Tests", function () {
this.timeout(Timeout.testCase);
this.timeout(Timeout.testAzureCase);
let localDebugTestContext: LocalDebugTestContext;
let devtunnelProcess: ChildProcessWithoutNullStreams | null;
let debugProcess: ChildProcessWithoutNullStreams | null;
let debugProcess: ChildProcess | null;
let successFlag = true;
let errorMessage = "";

Expand Down
4 changes: 2 additions & 2 deletions packages/tests/src/ui-test/samples/sampleCaseFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { Page } from "playwright";
import fs from "fs-extra";
import path from "path";
import { Executor } from "../../utils/executor";
import { ChildProcessWithoutNullStreams } from "child_process";
import { ChildProcess, ChildProcessWithoutNullStreams } from "child_process";
import { initDebugPort } from "../../utils/commonUtils";
import { CliHelper } from "../cliHelper";

Expand Down Expand Up @@ -296,7 +296,7 @@ export abstract class CaseFactory {
let sampledebugContext: SampledebugContext;
let azSqlHelper: AzSqlHelper | undefined;
let devtunnelProcess: ChildProcessWithoutNullStreams;
let debugProcess: ChildProcessWithoutNullStreams;
let debugProcess: ChildProcess;
let dockerProcess: ChildProcessWithoutNullStreams;
let successFlag = true;
let envContent = "";
Expand Down
96 changes: 36 additions & 60 deletions packages/tests/src/utils/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import {
TemplateProjectFolder,
Capability,
LocalDebugError,
Project,
} from "./constants";
import path from "path";
import fs from "fs-extra";
import * as os from "os";
import { spawn, ChildProcessWithoutNullStreams } from "child_process";
import {
spawn,
ChildProcessWithoutNullStreams,
ChildProcess,
} from "child_process";
import { expect } from "chai";
import { Env } from "./env";
import { on } from "events";

export class Executor {
static async execute(
Expand Down Expand Up @@ -257,38 +263,15 @@ export class Executor {
onError?: (data: string) => void,
openOnly?: boolean
) {
let childProcess: ChildProcess | null = null;
console.log(`[start] ${env} debug ... `);
const childProcess = spawn(
os.type() === "Windows_NT"
? v3
? "teamsapp.cmd"
: "teamsfx.cmd"
: v3
? "teamsapp"
: "teamsfx",
[
"preview",
v3 ? "--env" : "",
v3 ? `${env}` : `--${env}`,
openOnly ? "--open-only" : "",
],
{
cwd: projectPath,
env: processEnv ? processEnv : process.env,
}
childProcess = Executor.spawnCommand(
projectPath,
v3 ? "teamsapp" : "teamsfx",
["preview", v3 ? "--env" : "", v3 ? env : `--${env}`],
onData,
onError
);
childProcess.stdout.on("data", (data) => {
const dataString = data.toString();
if (onData) {
onData(dataString);
}
});
childProcess.stderr.on("data", (data) => {
const dataString = data.toString();
if (onError) {
onError(dataString);
}
});
return childProcess;
}

Expand Down Expand Up @@ -513,27 +496,28 @@ export class Executor {
args: string[],
onData?: (data: string) => void,
onError?: (data: string) => void
) {
const childProcess = spawn(
os.type() === "Windows_NT" ? command + ".cmd" : command,
args,
{
cwd: projectPath,
env: process.env,
}
);
): ChildProcessWithoutNullStreams {
const isWindows = os.type() === "Windows_NT";

const childProcess = spawn(command, args, {
cwd: projectPath,
shell: isWindows,
});

childProcess.stdout.on("data", (data) => {
const dataString = data.toString();
if (onData) {
onData(dataString);
}
onData && onData(dataString);
});

childProcess.stderr.on("data", (data) => {
const dataString = data.toString();
if (onError) {
onError(dataString);
}
onError && onError(dataString);
});

childProcess.on("error", (error) => {
onError && onError(`Failed to start process: ${error.message}`);
});

return childProcess;
}

Expand Down Expand Up @@ -594,7 +578,8 @@ export class Executor {
console.log("======= debug with cli ========");
console.log("botFlag: ", includeBot);
let tunnelName = "";
let devtunnelProcess = null;
let devtunnelProcess: ChildProcessWithoutNullStreams | null = null;
let debugProcess: ChildProcess | null = null;
if (includeBot) {
const tunnel = Executor.debugBotFunctionPreparation(projectPath);
tunnelName = tunnel.tunnelName;
Expand All @@ -611,7 +596,7 @@ export class Executor {
console.log(`[Successfully] deploy for ${projectPath}`);
}
}
const debugProcess = Executor.debugProject(
debugProcess = Executor.debugProject(
projectPath,
"local",
true,
Expand All @@ -633,7 +618,7 @@ export class Executor {
}
}
);
await new Promise((resolve) => setTimeout(resolve, 2 * 60 * 1000));
await new Promise((resolve) => setTimeout(resolve, 3 * 60 * 1000));
return {
tunnelName,
devtunnelProcess,
Expand All @@ -658,19 +643,10 @@ export class Executor {
}
}

static async closeProcess(
childProcess: ChildProcessWithoutNullStreams | null
) {
static async closeProcess(childProcess: ChildProcess | null) {
if (childProcess) {
try {
if (os.type() === "Windows_NT") {
console.log(`taskkill /F /PID "${childProcess.pid}"`);
await execAsync(`taskkill /F /PID "${childProcess.pid}"`);
childProcess.kill("SIGKILL");
} else {
console.log("kill process", childProcess.spawnargs.join(" "));
childProcess.kill("SIGKILL");
}
process.kill(-childProcess.pid);
} catch (error) {
console.log(error);
}
Expand Down

0 comments on commit 776f0b1

Please sign in to comment.