This commit is contained in:
Quan Jin 2022-07-18 16:21:26 +08:00
Родитель c53a584c98
Коммит 40ad35814b
21 изменённых файлов: 30365 добавлений и 13478 удалений

3
.gitignore поставляемый
Просмотреть файл

@ -14,4 +14,5 @@ nls.*.json
# Compiled files
src/**/*.js
test/**/*.js
**/*.js.map
**/*.js.map
*-report

16
.vscode/tasks.json поставляемый
Просмотреть файл

@ -8,7 +8,9 @@
"args": [],
"group": "build",
"isBackground": true,
"problemMatcher": ["$tsc"]
"problemMatcher": [
"$tsc"
]
},
{
"label": "build",
@ -17,7 +19,9 @@
"args": [],
"group": "build",
"isBackground": true,
"problemMatcher": ["$tsc"]
"problemMatcher": [
"$tsc"
]
},
{
"label": "watch-build-test",
@ -25,6 +29,14 @@
"command": "gulp",
"group": "test",
"isBackground": true
},
{
"type": "npm",
"script": "build",
"group": "build",
"problemMatcher": [],
"label": "gulp: build-src",
"detail": "gulp build"
}
]
}

41928
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -4,8 +4,9 @@
import * as nls from "vscode-nls";
import { TargetType } from "../debugger/cordovaDebugSession";
import { MobileTargetManager } from "../utils/mobileTargetManager";
import AbstractPlatform from "./abstractPlatform";
import { IDebuggableMobileTarget, IMobileTarget, MobileTarget } from "../utils/mobileTarget";
import AbstractPlatform from "./abstractPlatform";
nls.config({
messageFormat: nls.MessageFormat.bundle,
bundleFormat: nls.BundleFormat.standalone,
@ -133,6 +134,7 @@ export default abstract class AbstractMobilePlatform<
);
}
});
if (targetsBySpecifiedType.length) {
return targetsBySpecifiedType[0];
} else if (targets.length) {
@ -144,14 +146,14 @@ export default abstract class AbstractMobilePlatform<
),
);
return targets[0];
} else {
throw Error(
localize(
"IosThereIsNoAnyOnlineDebuggableTarget",
"There is no any iOS debuggable online target",
),
);
}
throw Error(
localize(
"IosThereIsNoAnyOnlineDebuggableTarget",
"There is no any iOS debuggable online target",
),
);
}
protected addTargetToRunArgs(target: Target): void {

Просмотреть файл

@ -41,18 +41,13 @@ export default abstract class AbstractPlatform {
if (optIdx > -1) {
result = binary ? true : runArguments[optIdx + 1];
} else {
for (let i = 0; i < runArguments.length; i++) {
const arg = runArguments[i];
if (arg.indexOf(optName) > -1) {
for (const arg of runArguments) {
if (arg.includes(optName)) {
if (binary) {
result = true;
} else {
const tokens = arg.split("=");
if (tokens.length > 1) {
result = tokens[1].trim();
} else {
result = undefined;
}
result = tokens.length > 1 ? tokens[1].trim() : undefined;
}
}
}
@ -61,10 +56,9 @@ export default abstract class AbstractPlatform {
// Binary parameters can either exists (e.g. be true) or be absent. You can not pass false binary parameter.
if (binary) {
if (result === undefined) {
return undefined;
} else {
return true;
return false;
}
return true;
}
if (result) {
@ -88,8 +82,8 @@ export default abstract class AbstractPlatform {
let isComplexOpt = false;
let optIdx = runArguments.indexOf(optName);
if (optIdx === -1) {
for (let i = 0; i < runArguments.length; i++) {
if (runArguments[i].includes(optName)) {
for (const [i, runArgument] of runArguments.entries()) {
if (runArgument.includes(optName)) {
optIdx = i;
isComplexOpt = true;
}
@ -113,8 +107,8 @@ export default abstract class AbstractPlatform {
let isComplexOpt = false;
let optIdx = runArguments.indexOf(optName);
if (optIdx === -1) {
for (let i = 0; i < runArguments.length; i++) {
if (runArguments[i].includes(optName)) {
for (const [i, runArgument] of runArguments.entries()) {
if (runArgument.includes(optName)) {
optIdx = i;
isComplexOpt = true;
}

Просмотреть файл

@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
import * as nls from "vscode-nls";
import * as fs from "fs";
import * as path from "path";
import * as url from "url";
import * as nls from "vscode-nls";
import { DebugConsoleLogger, TargetType, WebviewData } from "../../debugger/cordovaDebugSession";
import { CordovaIosDeviceLauncher } from "../../debugger/cordovaIosDeviceLauncher";
import { cordovaRunCommand } from "../../debugger/extension";
@ -20,6 +20,7 @@ import {
IOSTarget,
IOSTargetManager,
} from "../../utils/ios/iOSTargetManager";
nls.config({
messageFormat: nls.MessageFormat.bundle,
bundleFormat: nls.BundleFormat.standalone,
@ -288,17 +289,16 @@ export default class IosPlatform extends AbstractMobilePlatform<IOSTarget, IOSTa
if (this.platformOpts.target.toLowerCase() === TargetType.Device) {
const packageId = await CordovaIosDeviceLauncher.getBundleIdentifier(this.projectRoot);
return CordovaIosDeviceLauncher.getPathOnDevice(packageId);
} else {
const entries = await fs.promises.readdir(
path.join(this.projectRoot, "platforms", "ios", "build", "emulator"),
);
// TODO requires changes in case of implementing debugging on iOS simulators
const filtered = entries.filter(entry => /\.app$/.test(entry));
if (filtered.length > 0) {
return filtered[0];
} else {
throw new Error(localize("UnableToFindAppFile", "Unable to find .app file"));
}
}
const entries = await fs.promises.readdir(
path.join(this.projectRoot, "platforms", "ios", "build", "emulator"),
);
// TODO requires changes in case of implementing debugging on iOS simulators
const filtered = entries.filter(entry => /\.app$/.test(entry));
if (filtered.length > 0) {
return filtered[0];
}
throw new Error(localize("UnableToFindAppFile", "Unable to find .app file"));
}
}

Просмотреть файл

@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
import { ProjectType } from "../utils/cordovaProjectHelper";
import { CordovaWorkspaceManager } from "./cordovaWorkspaceManager";
import * as vscode from "vscode";
import { ProjectType } from "../utils/cordovaProjectHelper";
import IonicDevServer from "../utils/ionicDevServer";
import { CordovaWorkspaceManager } from "./cordovaWorkspaceManager";
import { PluginSimulator } from "./simulate";
export interface IGeneralPlatformOptions {

Просмотреть файл

@ -3,9 +3,10 @@
import * as nls from "vscode-nls";
import { QuickPickOptions, window } from "vscode";
import { OutputChannelLogger } from "./log/outputChannelLogger";
import { TargetType } from "../debugger/cordovaDebugSession";
import { OutputChannelLogger } from "./log/outputChannelLogger";
import { IMobileTarget, MobileTarget } from "./mobileTarget";
nls.config({
messageFormat: nls.MessageFormat.bundle,
bundleFormat: nls.BundleFormat.standalone,

Просмотреть файл

@ -2,8 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the project root for details.
import * as path from "path";
import * as vscode from "vscode";
import * as assert from "assert";
import * as vscode from "vscode";
import { Connection, Server, WebSocketTransport } from "vscode-cdp-proxy";
import { convertWindowsPathToUnixOne } from "../testUtils";
import { generateRandomPortNumber, delay } from "../../src/utils/extensionHelper";
@ -18,7 +18,7 @@ import { LogLevel } from "../../src/utils/log/logHelper";
import { DebuggerEndpointHelper } from "../../src/debugger/cdp-proxy/debuggerEndpointHelper";
import { PlatformType } from "../../src/debugger/cordovaDebugSession";
interface ICDPProxyInternalEntities {
interface ICdpProxyInternalEntities {
attachArgs: ICordovaAttachRequestArgs;
projectType: ProjectType;
sourcemapPathTransformer: SourcemapPathTransformer;
@ -37,10 +37,10 @@ suite("cordovaCDPProxy", function () {
: path.join(__dirname, "..", "resources", "testCordovaProject");
let proxy: CordovaCDPProxy;
let cancellationTokenSource: vscode.CancellationTokenSource =
const cancellationTokenSource: vscode.CancellationTokenSource =
new vscode.CancellationTokenSource();
let wsTargetPort = generateRandomPortNumber();
const wsTargetPort = generateRandomPortNumber();
let wsTargetServer: Server | null;
let targetConnection: Connection | null;
@ -61,7 +61,7 @@ suite("cordovaCDPProxy", function () {
}
await proxy.stopServer();
if (wsTargetServer) {
await wsTargetServer.dispose();
wsTargetServer.dispose();
wsTargetServer = null;
}
}
@ -69,20 +69,18 @@ suite("cordovaCDPProxy", function () {
function prepareCDPProxyInternalEntities(
debugType: "ionic" | "cordova" | "simulate",
cdpHandlerType: "chrome" | "safari",
): ICDPProxyInternalEntities {
let attachArgs: ICordovaAttachRequestArgs;
let projectType: ProjectType;
): ICdpProxyInternalEntities {
let sourcemapPathTransformer: SourcemapPathTransformer;
let cdpMessageHandler: CDPMessageHandlerBase;
projectType = new ProjectType(
const projectType: ProjectType = new ProjectType(
false, // isMeteor
false, // isMobileFirst
false, // isPhonegap
true, // isCordova
);
attachArgs = {
const attachArgs: ICordovaAttachRequestArgs = {
cwd: path.resolve(__dirname, "..", "resources", "testCordovaProject"),
platform: PlatformType.Android,
ionicLiveReload: false,
@ -144,7 +142,7 @@ suite("cordovaCDPProxy", function () {
}
suiteSetup(async () => {
let cdpProxyInternalEntities = prepareCDPProxyInternalEntities("cordova", "chrome");
const cdpProxyInternalEntities = prepareCDPProxyInternalEntities("cordova", "chrome");
proxy = new CordovaCDPProxy(
cdpProxyHostAddress,
cdpProxyPort,
@ -171,6 +169,7 @@ suite("cordovaCDPProxy", function () {
// Due to the time limit, sooner or later this cycle will end
while (!targetConnection) {
// eslint-disable-next-line no-await-in-loop
await delay(1000);
}
});
@ -183,7 +182,7 @@ suite("cordovaCDPProxy", function () {
suite("ChromeCDPMessageHandler", () => {
suite("Pure Cordova", () => {
suiteSetup(() => {
let cdpProxyInternalEntities = prepareCDPProxyInternalEntities(
const cdpProxyInternalEntities = prepareCDPProxyInternalEntities(
"cordova",
"chrome",
);
@ -224,7 +223,7 @@ suite("cordovaCDPProxy", function () {
suite("Simulate", () => {
suiteSetup(() => {
let cdpProxyInternalEntities = prepareCDPProxyInternalEntities(
const cdpProxyInternalEntities = prepareCDPProxyInternalEntities(
"simulate",
"chrome",
);
@ -239,7 +238,7 @@ suite("cordovaCDPProxy", function () {
params: {
url: `file://${
process.platform === "win32"
? "/" + testProjectPath
? `/${testProjectPath}`
: testProjectPath
}/www/js/index.js`,
},
@ -267,7 +266,7 @@ suite("cordovaCDPProxy", function () {
suite("Ionic", () => {
suiteSetup(() => {
let cdpProxyInternalEntities = prepareCDPProxyInternalEntities(
const cdpProxyInternalEntities = prepareCDPProxyInternalEntities(
"ionic",
"chrome",
);
@ -282,7 +281,7 @@ suite("cordovaCDPProxy", function () {
params: {
url: `file://${
process.platform === "win32"
? "/" + testProjectPath
? `/${testProjectPath}`
: testProjectPath
}/www/main.js`,
},
@ -321,13 +320,13 @@ suite("cordovaCDPProxy", function () {
let testUrlRegex;
if (process.platform === "win32") {
const testPathRegex = `${testProjectPath.replace(
/([\/\.])/g,
/([./])/g,
"\\$1",
)}\\\\[wW][wW][wW]\\\\[mM][aA][iI][nN]\\.[jJ][sS]`;
testUrlRegex = `[fF][iI][lL][eE]:\\/\\/${testPathRegex}|${testPathRegex}`;
} else {
const testPathRegex = `${testProjectPath}/www/main.js`.replace(
/([\/\.])/g,
/([./])/g,
"\\$1",
);
testUrlRegex = `file:\\/\\/${testPathRegex}|${testPathRegex}`;
@ -356,7 +355,7 @@ suite("cordovaCDPProxy", function () {
suite("Ionic", () => {
const targetPageId = "page-7";
suiteSetup(() => {
let cdpProxyInternalEntities = prepareCDPProxyInternalEntities(
const cdpProxyInternalEntities = prepareCDPProxyInternalEntities(
"ionic",
"safari",
);

Просмотреть файл

@ -3,15 +3,15 @@
import * as assert from "assert";
import * as path from "path";
import { delay } from "../src/utils/extensionHelper";
import * as rimraf from "rimraf";
import * as vscode from "vscode";
import * as testUtils from "./testUtils";
import { delay } from "../src/utils/extensionHelper";
import { CordovaProjectHelper } from "../src/utils/cordovaProjectHelper";
import * as testUtils from "./testUtils";
suite("extensionContext", () => {
let testProjectPath: string = path.resolve(__dirname, "resources", "testCordovaProject");
let cordovaTypeDefDir: string =
const testProjectPath: string = path.resolve(__dirname, "resources", "testCordovaProject");
const cordovaTypeDefDir: string =
CordovaProjectHelper.getOrCreateTypingsTargetPath(testProjectPath);
suiteTeardown(() => {
@ -23,10 +23,10 @@ suite("extensionContext", () => {
test("Verify that the commands registered by Cordova extension are loaded", () => {
return vscode.commands.getCommands(true).then(results => {
let cordovaCmdsAvailable = results.filter((commandName: string) => {
return commandName.indexOf("cordova.") > -1;
const cordovaCommandsAvailable = results.filter((commandName: string) => {
return commandName.includes("cordova.");
});
assert.deepStrictEqual(cordovaCmdsAvailable, [
assert.deepStrictEqual(cordovaCommandsAvailable, [
"cordova.restart",
"cordova.prepare",
"cordova.build",
@ -50,7 +50,7 @@ suite("extensionContext", () => {
return delay(10000);
})
.then(_res => {
let androidBuildPath = path.resolve(
const androidBuildPath = path.resolve(
testProjectPath,
"platforms",
"android",

Просмотреть файл

@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
import * as should from "should";
import * as fs from "fs";
import * as sinon from "sinon";
import * as should from "should";
import Sinon = require("sinon");
import * as plist from "plist";
import { CordovaIosDeviceLauncher } from "../../src/debugger/cordovaIosDeviceLauncher";
@ -19,17 +19,16 @@ suite("cordovaIosDeviceLauncher", function () {
parseMock.restore();
});
test("should be able to find the bundle identifier", () => {
readdirMock = (sinon.stub(fs.promises, "readdir") as any).returns(
test("should be able to find the bundle identifier", async () => {
readdirMock = (Sinon.stub(fs.promises, "readdir") as any).returns(
Promise.resolve(["foo", "bar.xcodeproj"]),
);
readFileSyncMock = sinon.stub(fs, "readFileSync").returns("");
parseMock = sinon
.stub(plist, "parse")
.returns({ CFBundleIdentifier: "test.bundle.identifier" });
return CordovaIosDeviceLauncher.getBundleIdentifier("testApp").then(bundleId => {
should.equal(bundleId, "test.bundle.identifier");
readFileSyncMock = Sinon.stub(fs, "readFileSync").returns("");
parseMock = Sinon.stub(plist, "parse").returns({
CFBundleIdentifier: "test.bundle.identifier",
});
const bundleId = await CordovaIosDeviceLauncher.getBundleIdentifier("testApp");
should.equal(bundleId, "test.bundle.identifier");
});
});

Просмотреть файл

@ -1,7 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
import assert = require("assert");
import * as vscode from "vscode";
import * as nls from "vscode-nls";
import Sinon = require("sinon");
import AbstractMobilePlatform from "../../src/extension/abstractMobilePlatform";
import { CordovaWorkspaceManager } from "../../src/extension/cordovaWorkspaceManager";
import { IGeneralAttachResult } from "../../src/extension/platformAttachResult";
@ -12,36 +15,46 @@ import { CordovaProjectHelper, ProjectType } from "../../src/utils/cordovaProjec
import IonicDevServer from "../../src/utils/ionicDevServer";
import { IDebuggableMobileTarget, IMobileTarget, MobileTarget } from "../../src/utils/mobileTarget";
import { MobileTargetManager } from "../../src/utils/mobileTargetManager";
import { TargetType } from "../../src/debugger/cordovaDebugSession";
import assert = require("assert");
import { DebugConsoleLogger, TargetType } from "../../src/debugger/cordovaDebugSession";
suite("AbstractMobilePlatform", function () {
let onlineDevice1: IDebuggableMobileTarget = {
name: "onlineDevice1",
id: "onlineDevice1",
suite.only("AbstractMobilePlatform", function () {
const onlineDevice: IDebuggableMobileTarget = {
name: "DeviceOnline",
id: "DeviceOnline",
isOnline: true,
isVirtualTarget: false,
};
let onlineDevice2: IDebuggableMobileTarget = {
name: "onlineDevice2",
id: "onlineDevice2",
isOnline: true,
const offlineDevice: IDebuggableMobileTarget = {
name: "DeviceOffline",
id: "DeviceOffline",
isOnline: false,
isVirtualTarget: false,
};
let offlineSimulator: IDebuggableMobileTarget = {
name: "offlineSimulator",
id: "offlineSimulator",
const offlineSimulator: IDebuggableMobileTarget = {
name: "emulatorOffline",
id: "emulatorOffline",
isOnline: false,
isVirtualTarget: true,
};
let onlineSimulator: IDebuggableMobileTarget = {
name: "onlineSimulator",
id: "onlineSimulator",
const onlineSimulator: IDebuggableMobileTarget = {
name: "emulatorOnline",
id: "emulatorOnline",
isOnline: true,
isVirtualTarget: true,
};
let collectedTargets: IDebuggableMobileTarget[];
const collectedTargets: IDebuggableMobileTarget[] = [
onlineDevice,
offlineDevice,
offlineSimulator,
onlineSimulator,
];
nls.config({
messageFormat: nls.MessageFormat.bundle,
bundleFormat: nls.BundleFormat.standalone,
})();
const localize = nls.loadMessageBundle();
class TestMobileTarget extends MobileTarget {}
@ -52,6 +65,21 @@ suite("AbstractMobilePlatform", function () {
this.targets = collectedTargets;
}
public async isVirtualTarget(target: string): Promise<boolean> {
if (target === TargetType.Device || target.includes(TargetType.Device)) {
return false;
} else if (target === TargetType.Emulator || target.includes(TargetType.Emulator)) {
return true;
}
throw new Error(
localize(
"CouldNotRecognizeTargetType",
"Could not recognize type of the target {0}",
target,
),
);
}
public async selectAndPrepareTarget(
filter?: (el: IMobileTarget) => boolean,
): Promise<TestMobileTarget> {
@ -73,8 +101,11 @@ suite("AbstractMobilePlatform", function () {
return new TestMobileTarget(emulatorTarget as IDebuggableMobileTarget);
}
protected startSelection(filter?: (el: IMobileTarget) => boolean): Promise<IMobileTarget> {
throw new Error("Method not implemented.");
protected async startSelection(
filter?: (el: IMobileTarget) => boolean,
): Promise<IMobileTarget> {
const selectedTarget = await this.selectTarget(filter);
return selectedTarget;
}
}
@ -82,6 +113,14 @@ suite("AbstractMobilePlatform", function () {
TestMobileTarget,
TestMobileTargetManager
> {
constructor(
protected platformOpts: IGeneralPlatformOptions,
protected log: DebugConsoleLogger,
) {
super(platformOpts, log);
this.targetManager = new TestMobileTargetManager();
}
public async getTargetFromRunArgs(): Promise<MobileTarget | undefined> {
await this.targetManager.collectTargets();
if (this.platformOpts.runArguments && this.platformOpts.runArguments.length > 0) {
@ -119,7 +158,7 @@ suite("AbstractMobilePlatform", function () {
}
public getRunArguments(): string[] {
throw Error("Not implemented yet");
return this.platformOpts.runArguments;
}
}
@ -147,13 +186,29 @@ suite("AbstractMobilePlatform", function () {
port,
};
let showQuickPickStub: Sinon.SinonStub;
suiteSetup(() => {
showQuickPickStub = Sinon.stub(vscode.window, "showQuickPick").callsFake(
async (
items:
| string[]
| Thenable<string[]>
| vscode.QuickPickItem[]
| Thenable<vscode.QuickPickItem[]>,
) => {
return items[0];
},
);
});
suiteTeardown(() => {
showQuickPickStub.restore();
});
const mobilePlatform = new TestMobilePlatform(platformOptions, logger);
suite("resolveMobileTarget", function () {
beforeEach(function () {
collectedTargets = [onlineDevice1, onlineDevice2, offlineSimulator, onlineSimulator];
});
test(`Should resolve any device for target: ${TargetType.Device}`, async function () {
const target = await mobilePlatform.resolveMobileTarget(TargetType.Device);
assert.strictEqual(target.isVirtualTarget, false, "Selected target is not device");
@ -184,10 +239,6 @@ suite("AbstractMobilePlatform", function () {
});
suite("getPreferredTarget", function () {
beforeEach(function () {
collectedTargets = [onlineDevice1, onlineDevice2, offlineSimulator, onlineSimulator];
});
test(`Should resolve any device for target: ${TargetType.Device}`, async function () {
const target = await mobilePlatform.resolveMobileTarget(TargetType.Device);
assert.strictEqual(target.isVirtualTarget, false, "Selected target is not device");

Просмотреть файл

@ -73,7 +73,7 @@ suite("AbstractPlatform", function () {
});
test("Should return false for the not presented binary argument", function () {
getArgumentValueTest(runArguments, notPresentedBooleanArgumentKey, true);
getArgumentValueTest(runArguments, notPresentedBooleanArgumentKey, false);
});
});
@ -88,23 +88,17 @@ suite("AbstractPlatform", function () {
let setValue: string | boolean;
let keyIndex = runArguments.indexOf(key);
if (typeof value === "boolean") {
if (keyIndex > -1) {
setValue = true;
} else {
setValue = false;
}
setValue = keyIndex > -1;
} else if (keyIndex > -1) {
setValue = runArguments[keyIndex + 1];
} else {
if (keyIndex > -1) {
setValue = runArguments[keyIndex + 1];
} else {
for (let i = 0; i < runArguments.length; i++) {
if (runArguments[i].includes(key)) {
keyIndex = i;
break;
}
for (const [i, runArgument] of runArguments.entries()) {
if (runArgument.includes(key)) {
keyIndex = i;
break;
}
setValue = runArguments[keyIndex].split("=")[1];
}
setValue = runArguments[keyIndex].split("=")[1];
}
assert.strictEqual(setValue, value);
@ -146,24 +140,24 @@ suite("AbstractPlatform", function () {
isBinary: boolean,
isSeparatedArgument?: boolean,
) {
const argsLenghtBefore = runArguments.length;
const argsLengthBefore = runArguments.length;
AbstractPlatform.removeRunArgument(runArguments, key, isBinary);
const keyIndex = runArguments.indexOf(key);
if (isBinary || argsLenghtBefore - runArguments.length === 2) {
if (isBinary || argsLengthBefore - runArguments.length === 2) {
if (keyIndex > -1) {
assert.fail("Binary argument was not removed");
}
} else if (isSeparatedArgument) {
if (keyIndex > -1 || argsLenghtBefore - runArguments.length !== 2) {
if (keyIndex > -1 || argsLengthBefore - runArguments.length !== 2) {
assert.fail("Separated argument was not removed");
}
} else {
if (argsLenghtBefore - runArguments.length !== 1) {
if (argsLengthBefore - runArguments.length !== 1) {
assert.fail("United argument was not removed");
}
for (let i = 0; i < runArguments.length; i++) {
if (runArguments[i].includes(key)) {
for (const runArgument of runArguments) {
if (runArgument.includes(key)) {
assert.fail("United argument was not removed");
}
}

Просмотреть файл

@ -4,10 +4,10 @@
import * as path from "path";
import * as assert from "assert";
import Sinon = require("sinon");
import { QuickPickItem, window } from "vscode";
import { AdbHelper } from "../../src/utils/android/adb";
import { AndroidTarget, AndroidTargetManager } from "../../src/utils/android/androidTargetManager";
import { IDebuggableMobileTarget, IMobileTarget } from "../../src/utils/mobileTarget";
import { QuickPickItem, window } from "vscode";
suite("AndroidTargetManager", function () {
const testProjectPath = path.join(__dirname, "..", "resources", "testCordovaProject");
@ -119,10 +119,10 @@ suite("AndroidTargetManager", function () {
});
suiteTeardown(() => {
getAbdsNamesStub.reset();
getOnlineTargetsStub.reset();
launchSimulatorStub.reset();
showQuickPickStub.reset();
getAbdsNamesStub.restore();
getOnlineTargetsStub.restore();
launchSimulatorStub.restore();
showQuickPickStub.restore();
});
suite("Target identification", function () {

Просмотреть файл

@ -4,7 +4,7 @@
import * as assert from "assert";
import * as path from "path";
import * as fs from "fs";
import * as sinon from "sinon";
import Sinon = require("sinon");
import { TelemetryHelper } from "../../src/utils/telemetryHelper";
import { CordovaProjectHelper } from "../../src/utils/cordovaProjectHelper";
@ -12,31 +12,28 @@ suite("telemetryHelper", function () {
const testProjectPath = path.join(__dirname, "..", "resources", "testCordovaProject");
suite("determineProjectTypes", function () {
test("should detect Ionic project", () => {
test("should detect Ionic project", async () => {
const ionicProjectPath = path.join(__dirname, "..", "resources", "testIonicProject");
sinon
.stub(fs, "existsSync")
.callsFake(p => p === path.join(ionicProjectPath, "package.json"));
sinon
.stub(fs, "readFileSync")
.callsFake(
(path: string, options?: string | { encoding?: string; flag?: string }) => {
return JSON.stringify({
dependencies: { "@ionic/angular": "5.0.0" },
devDependencies: { "@ionic-native/core": "5.0.0" },
});
},
);
Sinon.stub(fs, "existsSync").callsFake(
(p: string) => p === path.join(ionicProjectPath, "package.json"),
);
Sinon.stub(fs, "readFileSync").callsFake(
(path: string, options?: string | { encoding?: string; flag?: string }) => {
return JSON.stringify({
dependencies: { "@ionic/angular": "5.0.0" },
devDependencies: { "@ionic-native/core": "5.0.0" },
});
},
);
return TelemetryHelper.determineProjectTypes(ionicProjectPath)
.then(projectType => {
assert.strictEqual(projectType.ionicMajorVersion, 5);
})
.finally(() => {
(fs.readFileSync as any).restore();
(fs.existsSync as any).restore();
});
try {
const projectType = await TelemetryHelper.determineProjectTypes(ionicProjectPath);
assert.strictEqual(projectType.ionicMajorVersion, 5);
} finally {
(fs.readFileSync as any).restore();
(fs.existsSync as any).restore();
}
});
suite("not Ionic projects", function () {
@ -44,19 +41,18 @@ suite("telemetryHelper", function () {
(CordovaProjectHelper.exists as any).restore();
});
test("should detect Cordova and Meteor project", () => {
sinon
.stub(CordovaProjectHelper, "exists")
.callsFake((filename: string): Promise<boolean> => {
test("should detect Cordova and Meteor project", async () => {
Sinon.stub(CordovaProjectHelper, "exists").callsFake(
(filename: string): Promise<boolean> => {
return Promise.resolve(
filename.toString().includes(".meteor") ||
filename.toString().includes("config.xml"),
);
});
},
);
return TelemetryHelper.determineProjectTypes(testProjectPath).then(projectType => {
assert.ok(projectType.isCordova && projectType.isMeteor);
});
const projectType = await TelemetryHelper.determineProjectTypes(testProjectPath);
assert.ok(projectType.isCordova && projectType.isMeteor);
});
});
});

Просмотреть файл

@ -3,9 +3,9 @@
import * as path from "path";
import * as fs from "fs";
import * as sinon from "sinon";
import { CordovaProjectHelper } from "../../src/utils/cordovaProjectHelper";
import * as assert from "assert";
import Sinon = require("sinon");
import { CordovaProjectHelper } from "../../src/utils/cordovaProjectHelper";
suite("cordovaProjectHelper", function () {
const testProjectPath = path.join(__dirname, "..", "resources", "testCordovaProject");
@ -39,17 +39,15 @@ suite("cordovaProjectHelper", function () {
devDep: Record<string, string>,
existsSyncFake: (path: fs.PathLike) => boolean,
) {
sinon.stub(fs, "existsSync").callsFake(existsSyncFake);
sinon
.stub(fs, "readFileSync")
.callsFake(
(path: string, options?: string | { encoding?: string; flag?: string }) => {
return JSON.stringify({
dependencies: dep,
devDependencies: devDep,
});
},
);
Sinon.stub(fs, "existsSync").callsFake(existsSyncFake);
Sinon.stub(fs, "readFileSync").callsFake(
(path: string, options?: string | { encoding?: string; flag?: string }) => {
return JSON.stringify({
dependencies: dep,
devDependencies: devDep,
});
},
);
const processedMajorVersion =
CordovaProjectHelper.determineIonicMajorVersion(ionicProjectPath);
@ -106,7 +104,7 @@ suite("cordovaProjectHelper", function () {
suite("getEnvArgument", function () {
function checkEnvData(envData: any, envFileData: any = {}) {
let launchArgs: any = {
const launchArgs: any = {
cwd: testProjectPath,
platform: "android",
ionicLiveReload: false,
@ -115,7 +113,7 @@ suite("cordovaProjectHelper", function () {
env: envData,
};
let envRef = Object.assign({}, process.env);
const envRef = Object.assign({}, process.env);
if (Object.keys(envFileData).length > 0) {
launchArgs.envFile = path.join(testProjectPath, ".env");
Object.assign(envRef, envFileData);
@ -139,14 +137,12 @@ suite("cordovaProjectHelper", function () {
}
}
function checkEnvDataFromFile(env: any, envFile: any, envStrRepres: string) {
sinon
.stub(fs, "readFileSync")
.callsFake(
(path: string, options?: string | { encoding?: string; flag?: string }) => {
return envStrRepres;
},
);
function checkEnvDataFromFile(env: any, envFile: any, envStrRepresent: string) {
Sinon.stub(fs, "readFileSync").callsFake(
(path: string, options?: string | { encoding?: string; flag?: string }) => {
return envStrRepresent;
},
);
checkEnvData(env, envFile);

Просмотреть файл

@ -10,6 +10,15 @@ export function run(): Promise<void> {
ui: "tdd",
grep: "smokeTestsContext",
color: true,
reporter: "mocha-multi-reporters",
reporterOptions: {
reporterEnabled: "spec, mochawesome",
mochawesomeReporterOptions: {
reportDir: `${path.resolve(__dirname, "..")}/mochawesome-report`,
reportFilename: "Cordova-Test-Report",
quiet: true,
},
},
timeout: 150000,
});

Просмотреть файл

@ -0,0 +1,8 @@
{
"reporterEnabled": "spec, mochawesome",
"mochawesomeReporterOptions": {
"reportDir": "../mochawesome-report",
"reportFilename": "Cordova-Test-Report",
"quiet": true,
}
}

Просмотреть файл

@ -22,7 +22,7 @@ async function launchTests() {
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [testWorkspace],
version: "1.53.2",
version: "stable",
});
} catch (err) {
console.error(err);

Просмотреть файл

@ -10,9 +10,9 @@ import { CordovaProjectHelper } from "../src/utils/cordovaProjectHelper";
export function executeCordovaCommand(cwd: string, command: string): Promise<any> {
return new Promise((resolve, reject) => {
let cordovaCmd = os.platform() === "win32" ? "cordova.cmd" : "cordova";
let commandToExecute = cordovaCmd + " " + command;
let process = child_process.exec(commandToExecute, { cwd: cwd });
const cordovaCmd = os.platform() === "win32" ? "cordova.cmd" : "cordova";
const commandToExecute = `${cordovaCmd} ${command}`;
const process = child_process.exec(commandToExecute, { cwd });
let stderr = "";
process.stderr.on("data", (data: Buffer) => {
@ -39,7 +39,7 @@ export function executeCordovaCommand(cwd: string, command: string): Promise<any
}
export function createCordovaProject(cwd: string, projectName: string): Promise<any> {
let cordovaCommandToRun = "create " + projectName;
const cordovaCommandToRun = `create ${projectName}`;
return executeCordovaCommand(cwd, cordovaCommandToRun);
}
@ -48,7 +48,7 @@ export function addCordovaComponents(
projectRoot: string,
componentsToAdd: string[],
): Promise<any> {
let cordovaCommandToRun = componentName + " add " + componentsToAdd.join(" ");
const cordovaCommandToRun = `${componentName} add ${componentsToAdd.join(" ")}`;
return executeCordovaCommand(projectRoot, cordovaCommandToRun);
}
@ -57,19 +57,18 @@ export function removeCordovaComponents(
projectRoot: string,
componentsToRemove: string[],
): Promise<any> {
let cordovaCommandToRun = componentName + " remove " + componentsToRemove.join(" ");
const cordovaCommandToRun = `${componentName} remove ${componentsToRemove.join(" ")}`;
return executeCordovaCommand(projectRoot, cordovaCommandToRun);
}
export function enumerateListOfTypeDefinitions(projectRoot: string): string[] {
let typeDefsFolder = CordovaProjectHelper.getCordovaPluginTypeDefsPath(projectRoot);
const typeDefsFolder = CordovaProjectHelper.getCordovaPluginTypeDefsPath(projectRoot);
// look for all the type defs in the typings folder
if (!CordovaProjectHelper.existsSync(typeDefsFolder)) {
return [];
} else {
return fs.readdirSync(typeDefsFolder);
}
return fs.readdirSync(typeDefsFolder);
}
export function isUrlReachable(url: string): Promise<boolean> {
@ -83,6 +82,6 @@ export function isUrlReachable(url: string): Promise<boolean> {
});
}
export function convertWindowsPathToUnixOne(path: string) {
export function convertWindowsPathToUnixOne(path: string): string {
return path.replace(/\\/g, "/");
}