Skip to content

Commit 8c54e37

Browse files
committed
feat: Refactor test imports and platform handling for improved architecture compatibility
1 parent 7cabfe0 commit 8c54e37

File tree

2 files changed

+199
-21
lines changed

2 files changed

+199
-21
lines changed
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
declare module "@srcpush/plugin-testing-framework" {
2+
import Q = require("q");
3+
4+
namespace Platform {
5+
interface IPlatform {
6+
getName(): string;
7+
getCommandLineFlagName(): string;
8+
getServerUrl(): string;
9+
getEmulatorManager(): IEmulatorManager;
10+
getDefaultDeploymentKey(): string;
11+
}
12+
13+
interface IEmulatorManager {
14+
getTargetEmulator(): Q.Promise<string>;
15+
bootEmulator(restartEmulators: boolean): Q.Promise<void>;
16+
launchInstalledApplication(appId: string): Q.Promise<void>;
17+
endRunningApplication(appId: string): Q.Promise<void>;
18+
restartApplication(appId: string): Q.Promise<void>;
19+
resumeApplication(appId: string, delayBeforeResumingMs?: number): Q.Promise<void>;
20+
prepareEmulatorForTest(appId: string): Q.Promise<void>;
21+
uninstallApplication(appId: string): Q.Promise<void>;
22+
}
23+
24+
class Android implements IPlatform {
25+
constructor(emulatorManager: IEmulatorManager);
26+
getName(): string;
27+
getCommandLineFlagName(): string;
28+
getServerUrl(): string;
29+
getEmulatorManager(): IEmulatorManager;
30+
getDefaultDeploymentKey(): string;
31+
}
32+
33+
class IOS implements IPlatform {
34+
constructor(emulatorManager: IEmulatorManager);
35+
getName(): string;
36+
getCommandLineFlagName(): string;
37+
getServerUrl(): string;
38+
getEmulatorManager(): IEmulatorManager;
39+
getDefaultDeploymentKey(): string;
40+
}
41+
42+
class AndroidEmulatorManager implements IEmulatorManager {
43+
getTargetEmulator(): Q.Promise<string>;
44+
bootEmulator(restartEmulators: boolean): Q.Promise<void>;
45+
launchInstalledApplication(appId: string): Q.Promise<void>;
46+
endRunningApplication(appId: string): Q.Promise<void>;
47+
restartApplication(appId: string): Q.Promise<void>;
48+
resumeApplication(appId: string, delayBeforeResumingMs?: number): Q.Promise<void>;
49+
prepareEmulatorForTest(appId: string): Q.Promise<void>;
50+
uninstallApplication(appId: string): Q.Promise<void>;
51+
}
52+
53+
class IOSEmulatorManager implements IEmulatorManager {
54+
getTargetEmulator(): Q.Promise<string>;
55+
bootEmulator(restartEmulators: boolean): Q.Promise<void>;
56+
launchInstalledApplication(appId: string): Q.Promise<void>;
57+
endRunningApplication(appId: string): Q.Promise<void>;
58+
restartApplication(appId: string): Q.Promise<void>;
59+
resumeApplication(appId: string, delayBeforeResumingMs?: number): Q.Promise<void>;
60+
prepareEmulatorForTest(appId: string): Q.Promise<void>;
61+
uninstallApplication(appId: string): Q.Promise<void>;
62+
}
63+
}
64+
65+
namespace PluginTestingFramework {
66+
function initializeTests(
67+
projectManager: ProjectManager,
68+
supportedTargetPlatforms: Platform.IPlatform[],
69+
describeTests: (projectManager: ProjectManager, targetPlatform: Platform.IPlatform) => void
70+
): void;
71+
}
72+
73+
class ProjectManager {
74+
static DEFAULT_APP_VERSION: string;
75+
getPluginName(): string;
76+
setupProject(projectDirectory: string, templatePath: string, appName: string, appNamespace: string, version?: string): Q.Promise<void>;
77+
setupScenario(projectDirectory: string, appId: string, templatePath: string, jsPath: string, targetPlatform: Platform.IPlatform, version?: string): Q.Promise<void>;
78+
createUpdateArchive(projectDirectory: string, targetPlatform: Platform.IPlatform, isDiff?: boolean): Q.Promise<string>;
79+
preparePlatform(projectDirectory: string, targetPlatform: Platform.IPlatform): Q.Promise<void>;
80+
cleanupAfterPlatform(projectDirectory: string, targetPlatform: Platform.IPlatform): Q.Promise<void>;
81+
runApplication(projectDirectory: string, targetPlatform: Platform.IPlatform): Q.Promise<void>;
82+
}
83+
84+
function setupTestRunScenario(projectManager: ProjectManager, targetPlatform: Platform.IPlatform, scenarioJsPath: string, version?: string): Q.Promise<void>;
85+
function setupUpdateScenario(projectManager: ProjectManager, targetPlatform: Platform.IPlatform, scenarioJsPath: string, version: string): Q.Promise<string>;
86+
87+
namespace ServerUtil {
88+
let server: any;
89+
let updateResponse: any;
90+
let testMessageResponse: any;
91+
let testMessageCallback: (requestBody: any) => void;
92+
let updateCheckCallback: (requestBody: any) => void;
93+
let updatePackagePath: string;
94+
95+
function setupServer(targetPlatform: Platform.IPlatform): void;
96+
function cleanupServer(): void;
97+
function createDefaultResponse(): any;
98+
function createUpdateResponse(mandatory?: boolean, targetPlatform?: Platform.IPlatform, randomHash?: boolean): any;
99+
function expectTestMessages(expectedMessages: any[]): Q.Promise<void>;
100+
101+
class TestMessage {
102+
static CHECK_UP_TO_DATE: string;
103+
static CHECK_UPDATE_AVAILABLE: string;
104+
static CHECK_ERROR: string;
105+
static DOWNLOAD_SUCCEEDED: string;
106+
static DOWNLOAD_ERROR: string;
107+
static UPDATE_INSTALLED: string;
108+
static INSTALL_ERROR: string;
109+
static DEVICE_READY_AFTER_UPDATE: string;
110+
static UPDATE_FAILED_PREVIOUSLY: string;
111+
static NOTIFY_APP_READY_SUCCESS: string;
112+
static NOTIFY_APP_READY_FAILURE: string;
113+
static SKIPPED_NOTIFY_APPLICATION_READY: string;
114+
static SYNC_STATUS: string;
115+
static RESTART_SUCCEEDED: string;
116+
static RESTART_FAILED: string;
117+
static PENDING_PACKAGE: string;
118+
static CURRENT_PACKAGE: string;
119+
static SYNC_UP_TO_DATE: number;
120+
static SYNC_UPDATE_INSTALLED: number;
121+
static SYNC_UPDATE_IGNORED: number;
122+
static SYNC_ERROR: number;
123+
static SYNC_IN_PROGRESS: number;
124+
static SYNC_CHECKING_FOR_UPDATE: number;
125+
static SYNC_AWAITING_USER_ACTION: number;
126+
static SYNC_DOWNLOADING_PACKAGE: number;
127+
static SYNC_INSTALLING_UPDATE: number;
128+
}
129+
130+
class TestMessageResponse {
131+
static SKIP_NOTIFY_APPLICATION_READY: string;
132+
}
133+
134+
class AppMessage {
135+
message: string;
136+
args: any[];
137+
constructor(message: string, args: any[]);
138+
static fromString(message: string): AppMessage;
139+
}
140+
}
141+
142+
class TestBuilder {
143+
static describe: {
144+
(description: string, spec: () => void, scenarioPath?: string): void;
145+
only(description: string, spec: () => void, scenarioPath?: string): void;
146+
skip(description: string, spec: () => void, scenarioPath?: string): void;
147+
};
148+
static it: {
149+
(expectation: string, isCoreTest: boolean, assertion: (done: Mocha.Done) => void): void;
150+
only(expectation: string, isCoreTest: boolean, assertion: (done: Mocha.Done) => void): void;
151+
skip(expectation: string, isCoreTest: boolean, assertion: (done: Mocha.Done) => void): void;
152+
};
153+
}
154+
155+
namespace TestConfig {
156+
const TestAppName: string;
157+
const TestNamespace: string;
158+
const AcquisitionSDKPluginName: string;
159+
const templatePath: string;
160+
const thisPluginInstallString: string;
161+
const testRunDirectory: string;
162+
const updatesDirectory: string;
163+
const onlyRunCoreTests: boolean;
164+
const shouldSetup: boolean;
165+
const restartEmulators: boolean;
166+
const isOldArchitecture: boolean;
167+
}
168+
169+
class TestUtil {
170+
static ANDROID_KEY_PLACEHOLDER: string;
171+
static IOS_KEY_PLACEHOLDER: string;
172+
static SERVER_URL_PLACEHOLDER: string;
173+
static INDEX_JS_PLACEHOLDER: string;
174+
static CODE_PUSH_APP_VERSION_PLACEHOLDER: string;
175+
static CODE_PUSH_TEST_APP_NAME_PLACEHOLDER: string;
176+
static CODE_PUSH_APP_ID_PLACEHOLDER: string;
177+
static PLUGIN_VERSION_PLACEHOLDER: string;
178+
179+
static readMochaCommandLineOption(optionName: string, defaultValue?: string): string;
180+
static readMochaCommandLineFlag(optionName: string): boolean;
181+
static getProcessOutput(command: string, options?: any): Q.Promise<string>;
182+
static getPluginName(): string;
183+
static getPluginVersion(): string;
184+
static replaceString(filePath: string, regex: string, replacement: string): void;
185+
static copyFile(source: string, destination: string, overwrite: boolean): Q.Promise<void>;
186+
static archiveFolder(sourceFolder: string, targetFolder: string, archivePath: string, isDiff: boolean): Q.Promise<string>;
187+
static resolveBooleanVariables(variable: string | undefined): boolean;
188+
}
189+
190+
export { Platform, PluginTestingFramework, ProjectManager, setupTestRunScenario, setupUpdateScenario, ServerUtil, TestBuilder, TestConfig, TestUtil };
191+
}

test/test.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,10 @@ import mkdirp = require("mkdirp");
66
import path = require("path");
77
import slash = require("slash");
88

9-
import PluginTestingFrameworkPackage = require("@srcpush/plugin-testing-framework");
9+
import { Platform, PluginTestingFramework, ProjectManager, setupTestRunScenario, setupUpdateScenario, ServerUtil, TestBuilder, TestConfig, TestUtil } from "@srcpush/plugin-testing-framework";
1010

1111
import Q = require("q");
1212

13-
const Framework: any = PluginTestingFrameworkPackage;
14-
const Platform = Framework.Platform;
15-
const PluginTestingFramework = Framework.PluginTestingFramework;
16-
const ProjectManager = Framework.ProjectManager;
17-
const setupTestRunScenario = Framework.setupTestRunScenario;
18-
const setupUpdateScenario = Framework.setupUpdateScenario;
19-
const ServerUtil = Framework.ServerUtil;
20-
const TestBuilder = Framework.TestBuilder;
21-
const TestConfig = Framework.TestConfig;
22-
const TestUtil = Framework.TestUtil;
23-
24-
type FrameworkPlatform = any;
25-
2613
//////////////////////////////////////////////////////////////////////////////////////////
2714
// Create the platforms to run the tests on.
2815

@@ -265,7 +252,7 @@ class RNIOS extends Platform.IOS implements RNPlatform {
265252
}
266253
}
267254

268-
const supportedTargetPlatforms: FrameworkPlatform[] = [new RNAndroid(), new RNIOS()];
255+
const supportedTargetPlatforms: Platform.IPlatform[] = [new RNAndroid(), new RNIOS()];
269256

270257
//////////////////////////////////////////////////////////////////////////////////////////
271258
// Create the ProjectManager to use for the tests.
@@ -354,7 +341,7 @@ class RNProjectManager extends ProjectManager {
354341
/**
355342
* Sets up the scenario for a test in an already existing project.
356343
*/
357-
public setupScenario(projectDirectory: string, appId: string, templatePath: string, jsPath: string, targetPlatform: FrameworkPlatform, version?: string): Q.Promise<void> {
344+
public setupScenario(projectDirectory: string, appId: string, templatePath: string, jsPath: string, targetPlatform: Platform.IPlatform, version?: string): Q.Promise<void> {
358345
// We don't need to anything if it is the current scenario.
359346
if (RNProjectManager.currentScenario[projectDirectory] === jsPath) return Q<void>(null);
360347
RNProjectManager.currentScenario[projectDirectory] = jsPath;
@@ -379,7 +366,7 @@ class RNProjectManager extends ProjectManager {
379366
/**
380367
* Creates a CodePush update package zip for a project.
381368
*/
382-
public createUpdateArchive(projectDirectory: string, targetPlatform: FrameworkPlatform, isDiff?: boolean): Q.Promise<string> {
369+
public createUpdateArchive(projectDirectory: string, targetPlatform: Platform.IPlatform, isDiff?: boolean): Q.Promise<string> {
383370
const bundleFolder: string = path.join(projectDirectory, TestConfig.TestAppName, "CodePush/");
384371
const bundleName: string = (<RNPlatform><any>targetPlatform).getBundleName();
385372
const bundlePath: string = path.join(bundleFolder, bundleName);
@@ -409,7 +396,7 @@ class RNProjectManager extends ProjectManager {
409396
/**
410397
* Prepares a specific platform for tests.
411398
*/
412-
public preparePlatform(projectDirectory: string, targetPlatform: FrameworkPlatform): Q.Promise<void> {
399+
public preparePlatform(projectDirectory: string, targetPlatform: Platform.IPlatform): Q.Promise<void> {
413400
const deferred = Q.defer<string>();
414401

415402
const platformsJSONPath = path.join(projectDirectory, RNProjectManager.platformsJSON);
@@ -439,15 +426,15 @@ class RNProjectManager extends ProjectManager {
439426
/**
440427
* Cleans up a specific platform after tests.
441428
*/
442-
public cleanupAfterPlatform(projectDirectory: string, targetPlatform: FrameworkPlatform): Q.Promise<void> {
429+
public cleanupAfterPlatform(projectDirectory: string, targetPlatform: Platform.IPlatform): Q.Promise<void> {
443430
// Can't uninstall from command line, so noop.
444431
return Q<void>(null);
445432
}
446433

447434
/**
448435
* Runs the test app on the given target / platform.
449436
*/
450-
public runApplication(projectDirectory: string, targetPlatform: FrameworkPlatform): Q.Promise<void> {
437+
public runApplication(projectDirectory: string, targetPlatform: Platform.IPlatform): Q.Promise<void> {
451438
console.log("Running project in " + projectDirectory + " on " + targetPlatform.getName());
452439

453440
return Q<void>(null)
@@ -509,7 +496,7 @@ const UpdateNotifyApplicationReadyConditional = "updateNARConditional.js";
509496
// Initialize the tests.
510497

511498
PluginTestingFramework.initializeTests(new RNProjectManager(), supportedTargetPlatforms,
512-
(projectManager: any, targetPlatform: FrameworkPlatform) => {
499+
(projectManager: ProjectManager, targetPlatform: Platform.IPlatform) => {
513500
TestBuilder.describe("#window.codePush.checkForUpdate",
514501
() => {
515502
TestBuilder.it("window.codePush.checkForUpdate.noUpdate", false,

0 commit comments

Comments
 (0)