This repository was archived by the owner on May 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathtest.js
More file actions
104 lines (104 loc) · 4.87 KB
/
test.js
File metadata and controls
104 lines (104 loc) · 4.87 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
104
"use strict";
var Q = require("q");
var ServerUtil = require("./serverUtil");
var testBuilder_1 = require("./testBuilder");
var TestConfig = require("./testConfig");
var testUtil_1 = require("./testUtil");
//////////////////////////////////////////////////////////////////////////////////////////
/**
* Call this function to initialize the automated tests.
*/
function initializeTests(projectManager, supportedTargetPlatforms, describeTests) {
// DETERMINE PLATFORMS TO TEST //
/** The platforms to test on. */
var targetPlatforms = [];
supportedTargetPlatforms.forEach(function (supportedPlatform) {
if (testUtil_1.TestUtil.readMochaCommandLineFlag(supportedPlatform.getCommandLineFlagName()))
targetPlatforms.push(supportedPlatform);
});
// Log current configuration
console.log("Initializing tests for " + testUtil_1.TestUtil.getPluginName());
console.log(TestConfig.TestAppName + "\n" + TestConfig.TestNamespace);
console.log("Testing " + TestConfig.thisPluginPath + ".");
targetPlatforms.forEach(function (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--");
// FUNCTIONS //
function cleanupTest() {
console.log("Cleaning up!");
ServerUtil.updateResponse = undefined;
ServerUtil.testMessageCallback = undefined;
ServerUtil.updateCheckCallback = undefined;
ServerUtil.testMessageResponse = undefined;
}
/**
* Sets up tests for each platform.
* Creates the test project directory and the test update directory.
* Starts required emulators.
*/
function setupTests() {
it("sets up tests correctly", function (done) {
var promises = [];
targetPlatforms.forEach(function (platform) {
promises.push(platform.getEmulatorManager().bootEmulator(TestConfig.restartEmulators));
});
console.log("Building test project.");
// create the test project
promises.push(createTestProject(TestConfig.testRunDirectory)
.then(function () {
console.log("Building update project.");
// create the update project
return createTestProject(TestConfig.updatesDirectory);
}).then(function () { return null; }));
Q.all(promises).then(function () { done(); }, function (error) { done(error); });
});
}
/**
* Creates a test project directory at the given path.
*/
function createTestProject(directory) {
return projectManager.setupProject(directory, TestConfig.templatePath, TestConfig.TestAppName, TestConfig.TestNamespace);
}
/**
* Creates and runs the tests from the projectManager and TestBuilderDescribe objects passed to initializeTests.
*/
function createAndRunTests(targetPlatform) {
describe("CodePush", function () {
before(function () {
ServerUtil.setupServer(targetPlatform);
return targetPlatform.getEmulatorManager().uninstallApplication(TestConfig.TestNamespace)
.then(projectManager.preparePlatform.bind(projectManager, TestConfig.testRunDirectory, targetPlatform))
.then(projectManager.preparePlatform.bind(projectManager, TestConfig.updatesDirectory, targetPlatform));
});
after(function () {
ServerUtil.cleanupServer();
return projectManager.cleanupAfterPlatform(TestConfig.testRunDirectory, targetPlatform).then(projectManager.cleanupAfterPlatform.bind(projectManager, TestConfig.updatesDirectory, targetPlatform));
});
testBuilder_1.TestContext.projectManager = projectManager;
testBuilder_1.TestContext.targetPlatform = targetPlatform;
// Build the tests.
describeTests(projectManager, targetPlatform);
});
}
// BEGIN TESTING //
describe("CodePush " + projectManager.getPluginName() + " Plugin", function () {
this.timeout(100 * 60 * 1000);
if (TestConfig.shouldSetup)
describe("Setting Up For Tests", function () { return setupTests(); });
else {
targetPlatforms.forEach(function (platform) {
var prefix = (TestConfig.onlyRunCoreTests ? "Core Tests " : "Tests ") + TestConfig.thisPluginPath + " on ";
describe(prefix + platform.getName(), function () { return createAndRunTests(platform); });
});
}
});
}
exports.initializeTests = initializeTests;