-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ts
More file actions
103 lines (88 loc) · 3.51 KB
/
test.ts
File metadata and controls
103 lines (88 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import type { IPlatform } from "./platform";
import type { ProjectManager } from "./projectManager";
import * as ServerUtil from "./serverUtil";
import * as TestConfig from "./testConfig";
import { TestContext } from "./testBuilder";
import { TestUtil } from "./testUtil";
export function initializeTests(
projectManager: ProjectManager,
supportedTargetPlatforms: IPlatform[],
describeTests: (projectManager: ProjectManager, targetPlatform: IPlatform) => void,
): void {
const targetPlatforms: IPlatform[] = [];
supportedTargetPlatforms.forEach((supportedPlatform) => {
if (TestUtil.readMochaCommandLineFlag(supportedPlatform.getCommandLineFlagName())) {
targetPlatforms.push(supportedPlatform);
}
});
console.log(`Initializing tests for ${TestUtil.getPluginName()}`);
console.log(`${TestConfig.TestAppName}\n${TestConfig.TestNamespace}`);
console.log(`Testing ${TestConfig.thisPluginPath}.`);
targetPlatforms.forEach((platform) => {
console.log(`On ${platform.getName()}`);
});
console.log(`test run directory = ${TestConfig.testRunDirectory}`);
console.log(`updates directory = ${TestConfig.updatesDirectory}`);
if (TestConfig.onlyRunCoreTests) {
console.log("--only running core tests--");
}
if (TestConfig.shouldSetup) {
console.log("--setting up--");
}
if (TestConfig.restartEmulators) {
console.log("--restarting emulators--");
}
function setupTests(): void {
it("sets up tests correctly", async function () {
const platformSetup = targetPlatforms.map((platform) =>
platform.getEmulatorManager().bootEmulator(TestConfig.restartEmulators),
);
console.log("Building test project.");
await Promise.all(platformSetup);
await createTestProject(TestConfig.testRunDirectory);
console.log("Building update project.");
await createTestProject(TestConfig.updatesDirectory);
});
}
function createTestProject(directory: string): Promise<void> {
return projectManager.setupProject(
directory,
TestConfig.templatePath,
TestConfig.TestAppName,
TestConfig.TestNamespace,
);
}
function createAndRunTests(targetPlatform: IPlatform): void {
describe("CodePush", function () {
before(async function () {
ServerUtil.setupServer(targetPlatform);
await targetPlatform.getEmulatorManager().uninstallApplication(TestConfig.TestNamespace);
await projectManager.preparePlatform(TestConfig.testRunDirectory, targetPlatform);
await projectManager.preparePlatform(TestConfig.updatesDirectory, targetPlatform);
});
after(async function () {
ServerUtil.cleanupServer();
await projectManager.cleanupAfterPlatform(TestConfig.testRunDirectory, targetPlatform);
await projectManager.cleanupAfterPlatform(TestConfig.updatesDirectory, targetPlatform);
});
TestContext.projectManager = projectManager;
TestContext.targetPlatform = targetPlatform;
describeTests(projectManager, targetPlatform);
});
}
describe(`CodePush ${projectManager.getPluginName()} Plugin`, function () {
this.timeout(100 * 60 * 1000);
if (TestConfig.shouldSetup) {
describe("Setting Up For Tests", function () {
setupTests();
});
return;
}
targetPlatforms.forEach((platform) => {
const prefix = `${TestConfig.onlyRunCoreTests ? "Core Tests" : "Tests"} ${TestConfig.thisPluginPath} on `;
describe(`${prefix}${platform.getName()}`, function () {
createAndRunTests(platform);
});
});
});
}