Skip to content

Commit

Permalink
redo gulpfile testing tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbommarito committed Apr 29, 2016
1 parent 7cafad8 commit 6091eb6
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 100 deletions.
160 changes: 97 additions & 63 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function runTests(callback, options) {
}
if (options.core || getCommandLineFlag("--core")) args.push("--core");
if (options.npm || getCommandLineFlag("--npm")) args.push("--npm");
if (options.nosetup) args.push("--no-setup");
if (options.setup) args.push("--setup");
execCommand(command, args, callback);
}

Expand Down Expand Up @@ -346,31 +346,34 @@ var emulatorTaskNamePrefix = "emulator";
for (var android = 0; android < 2; android++) {
for (var ios = 0; ios < 2; ios++) {
if (!android && !ios) continue;
gulp.task(emulatorTaskNamePrefix + getEmulatorTaskNameSuffix(android, ios), function (callback) {
startEmulators(callback, android, ios);
});

((android, ios) => {
gulp.task(emulatorTaskNamePrefix + getEmulatorTaskNameSuffix(android, ios), function (callback) {
startEmulators(callback, android, ios);
});
})(android, ios);
}
}

////////////////////////////////////////////////////////////////////////
// Test Tasks //////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
// Fast Test Tasks
// Worker Tasks
//
// Runs tests but does not build or start emulators
// Run the tests standalone

// Run on Android fast
gulp.task("test-android-fast", function (callback) {
// Run on Android standalone
gulp.task("test-run-android", function (callback) {
var options = {
android: true,
android: true
};

runTests(callback, options);
});

// Run on iOS with the UiWebView fast
gulp.task("test-ios-uiwebview-fast", function (callback) {
// Run on iOS with the UiWebView standalone
gulp.task("test-run-ios-uiwebview", function (callback) {
var options = {
ios: true,
uiwebview: true,
Expand All @@ -379,8 +382,8 @@ gulp.task("test-ios-uiwebview-fast", function (callback) {
runTests(callback, options);
});

// Run on iOS with the WkWebView fast
gulp.task("test-ios-wkwebview-fast", function (callback) {
// Run on iOS with the WkWebView standalone
gulp.task("test-run-ios-wkwebview", function (callback) {
var options = {
ios: true,
wkwebview: true,
Expand All @@ -390,95 +393,126 @@ gulp.task("test-ios-wkwebview-fast", function (callback) {
});

////////////////////////////////////////////////////////////////////////
// No-Setup Test Tasks
//
// Does not set up the test project directories.
// Must be run after a test that does set up a project directory!
// Setup Tasks

// Run on iOS with the UiWebView with no setup
gulp.task("test-ios-uiwebview-no-setup", function (callback) {
// Set up the test projects
gulp.task("test-setup", function (callback) {
var options = {
ios: true,
uiwebview: true,
nosetup: true
setup: true
};

runTests(callback, options);
});

// Run on iOS with the WkWebView with no setup
gulp.task("test-ios-wkwebview-no-setup", function (callback) {
var options = {
ios: true,
wkwebview: true,
nosetup: true
};

runTests(callback, options);
// Sets up test projects and starts the Android emulator
gulp.task("test-setup-android", ["test-setup", "emulator-android"]);

// Sets up test projects and starts the iOS emulator
gulp.task("test-setup-ios", ["test-setup", "emulator-ios"]);

// Sets up test projects and starts both emulators
gulp.task("test-setup-both", ["test-setup", "emulator"]);

// Builds, then sets up the test projects
gulp.task("test-setup-build", ["default"], function (callback) {
runSequence("test-run-setup", callback);
});

// Builds, sets up test projects, and starts the Android emulator
gulp.task("test-setup-build-android", ["test-setup-build", "emulator-android"]);

// Builds, sets up test projects, and starts the iOS emulator
gulp.task("test-setup-build-ios", ["test-setup-build", "emulator-ios"]);

// Builds, sets up test projects, and starts both emulators
gulp.task("test-setup-build-both", ["test-setup-build", "emulator"]);

////////////////////////////////////////////////////////////////////////
// Fast Test Tasks
//
// Runs tests but doesn't build or start emulators.

// Run on Android fast
gulp.task("test-android-fast", ["test-setup-android"], function (callback) {
runSequence("test-run-android", callback);
});

// Run on iOS with the UiWebView fast
gulp.task("test-ios-uiwebview-fast", ["test-setup-ios"], function (callback) {
runSequence("test-run-ios-uiwebview", callback);
});

// Run on iOS with the WkWebView fast
gulp.task("test-ios-wkwebview-fast", ["test-setup-ios"], function (callback) {
runSequence("test-run-ios-wkwebview", callback);
});

////////////////////////////////////////////////////////////////////////
// Fast Composition Test Tasks
//
// Runs tests on multiple platforms.
// Does not build or start emulators.
// Runs tests but doesn't build or start emulators.

// Run on iOS with both WebViews fast
gulp.task("test-ios-fast", function (callback) {
runSequence("test-ios-uiwebview-fast", "test-ios-wkwebview-no-setup", callback);
// Run on iOS with the UiWebView fast
gulp.task("test-android-ios-uiwebview-fast", ["test-setup-both"], function (callback) {
runSequence("test-run-android", "test-run-ios-uiwebview", callback);
});

// Run on Android and iOS with the UiWebView fast
gulp.task("test-android-ios-uiwebview-fast", function (callback) {
runSequence("test-android-fast", "test-ios-uiwebview-no-setup", callback);
// Run on iOS with the WkWebView fast
gulp.task("test-android-ios-wkwebview-fast", ["test-setup-both"], function (callback) {
runSequence("test-run-android", "test-run-ios-wkwebview", callback);
});

// Run on Android and iOS with the WkWebView fast
gulp.task("test-android-ios-wkwebview-fast", function (callback) {
runSequence("test-android-fast", "test-ios-wkwebview-no-setup", callback);
// Run on iOS with both WebViews fast
gulp.task("test-ios-fast", ["test-setup-ios"], function (callback) {
runSequence("test-run-ios-uiwebview", "test-run-ios-wkwebview", callback);
});

// Run on Android and iOS with both WebViews fast
gulp.task("test-fast", function (callback) {
runSequence("test-android-ios-uiwebview-fast", "test-ios-wkwebview-no-setup", callback);
// Run on iOS with the WkWebView fast
gulp.task("test-fast", ["test-setup-both"], function (callback) {
runSequence("test-run-android", "test-run-ios-uiwebview", "test-run-ios-wkwebview", callback);
});

////////////////////////////////////////////////////////////////////////
// Test Tasks
//
// Runs tests and builds and starts emulators
// Runs tests, builds, and starts emulators.

// Run on Android
gulp.task("test-android", function (callback) {
runSequence("default", "emulator-android", "test-android-fast", callback);
gulp.task("test-android", ["test-setup-build-android"], function (callback) {
runSequence("test-run-android", callback);
});

// Run on iOS with the UiWebView
gulp.task("test-ios-uiwebview", function (callback) {
runSequence("default", "emulator-ios", "test-ios-uiwebview-fast", callback);
gulp.task("test-ios-uiwebview", ["test-setup-build-ios"], function (callback) {
runSequence("test-run-ios-uiwebview", callback);
});

// Run on iOS with the WkWebView
gulp.task("test-ios-wkwebview", function (callback) {
runSequence("default", "emulator-ios", "test-ios-wkwebview-fast", callback);
gulp.task("test-ios-wkwebview", ["test-setup-build-ios"], function (callback) {
runSequence("test-run-ios-wkwebview", callback);
});

// Run on iOS with both WebViews
gulp.task("test-ios", function (callback) {
runSequence("default", "emulator-ios", "test-ios-fast", callback);
////////////////////////////////////////////////////////////////////////
// Composition Test Tasks
//
// Runs tests, builds, and starts emulators.

// Run on Android and iOS with UiWebViews
gulp.task("test-android-ios-uiwebview", ["test-setup-build-both"], function (callback) {
runSequence("test-run-android", "test-run-ios-uiwebview", callback);
});

// Run on Android and iOS with the UiWebView
gulp.task("test-android-ios-uiwebview", function (callback) {
runSequence("default", "emulator", "test-android-ios-uiwebview-fast", callback);
// Run on Android and iOS with WkWebViews
gulp.task("test-android-ios-wkwebview", ["test-setup-build-both"], function (callback) {
runSequence("test-run-android", "test-run-ios-wkwebview", callback);
});

// Run on Android and iOS with the WkWebView
gulp.task("test-android-ios-wkwebview", function (callback) {
runSequence("default", "emulator", "test-android-ios-wkwebview-fast", callback);
// Run on iOS with both WebViews
gulp.task("test-ios", ["test-setup-build-ios"], function (callback) {
runSequence("test-run-ios-uiwebview", "test-run-ios-wkwebview", callback);
});

// Run on Android and iOS with both WebViews
gulp.task("test", function (callback) {
runSequence("default", "emulator", "test-fast", callback);
gulp.task("test", ["test-setup-build-both"], function (callback) {
runSequence("test-run-android", "test-run-ios-uiwebview", "test-run-ios-wkwebview", callback);
});
66 changes: 34 additions & 32 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var updatesDirectory = testUtil.readTestUpdatesDirectory();
var onlyRunCoreTests = testUtil.readCoreTestsOnly();
var targetPlatforms: platform.IPlatform[] = platform.PlatformResolver.resolvePlatforms(testUtil.readTargetPlatforms());
var shouldUseWkWebView = testUtil.readShouldUseWkWebView();
var shouldSetup: boolean = testUtil.readShouldSetup();

const TestAppName = "TestCodePush";
const TestNamespace = "com.microsoft.codepush.test";
Expand Down Expand Up @@ -63,7 +64,6 @@ var testMessageResponse: any;
var testMessageCallback: (requestBody: any) => void;
var updateCheckCallback: (requestBody: any) => void;
var mockUpdatePackagePath: string;
var isTestsSetup: boolean = testUtil.readNoSetup();

// FUNCTIONS //

Expand All @@ -75,6 +75,22 @@ function cleanupTest(): void {
testMessageResponse = undefined;
}

function setupTests(): void {
it("sets up tests correctly", (done) => {
console.log("Building test project.");
// create the test project
return createTestProject(testRunDirectory)
.then(() => {
console.log("Building update project.");
// create the update project
return createTestProject(updatesDirectory);
})
.then(() => {
return done();
});
});
}

function createTestProject(directory: string): Q.Promise<string> {
return projectManager.setupProject(
directory, templatePath,
Expand Down Expand Up @@ -191,24 +207,6 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo
}
}

function setupTests(): Q.Promise<string> {
return projectManager.uninstallApplication(TestNamespace, targetPlatform)
.then<string>(() => {
// only set up once
if (isTestsSetup) return null;
isTestsSetup = true;

console.log("Building test project.");
// create the test project
return createTestProject(testRunDirectory)
.then(() => {
console.log("Building update project.");
// create the update project
return createTestProject(updatesDirectory);
});
});
}

function prepareTest(): Q.Promise<string> {
return projectManager.prepareEmulatorForTest(TestNamespace, targetPlatform);
}
Expand All @@ -235,12 +233,9 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo
};

describe("window.codePush", function() {

this.timeout(100 * 60 * 1000);

before(() => {
setupServer();
return setupTests()
return projectManager.uninstallApplication(TestNamespace, targetPlatform)
.then(() => {
return projectManager.addPlatform(testRunDirectory, targetPlatform);
})
Expand Down Expand Up @@ -1387,14 +1382,21 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo

// CODE THAT EXECUTES THE TESTS //

targetPlatforms.forEach(platform => {
var prefix: string = "CodePush Cordova Plugin " + (onlyRunCoreTests ? "Core Tests " : "") + thisPluginPath + " on ";
if (platform.getCordovaName() === "ios") {
// handle UIWebView
if (shouldUseWkWebView === 0 || shouldUseWkWebView === 2) describe(prefix + platform.getCordovaName() + " with UIWebView", () => runTests(platform, false));
// handle WkWebView
if (shouldUseWkWebView === 1 || shouldUseWkWebView === 2) describe(prefix + platform.getCordovaName() + " with WkWebView", () => runTests(platform, true));
} else {
describe(prefix + platform.getCordovaName(), () => runTests(platform, false));
describe("CodePush Cordova Plugin", function () {
this.timeout(100 * 60 * 1000);

if (shouldSetup) describe("Setting Up For Tests", () => setupTests());
else {
targetPlatforms.forEach(platform => {
var prefix: string = (onlyRunCoreTests ? "Core Tests " : "Tests ") + thisPluginPath + " on ";
if (platform.getCordovaName() === "ios") {
// handle UIWebView
if (shouldUseWkWebView === 0 || shouldUseWkWebView === 2) describe(prefix + platform.getCordovaName() + " with UIWebView", () => runTests(platform, false));
// handle WkWebView
if (shouldUseWkWebView === 1 || shouldUseWkWebView === 2) describe(prefix + platform.getCordovaName() + " with WkWebView", () => runTests(platform, true));
} else {
describe(prefix + platform.getCordovaName(), () => runTests(platform, false));
}
});
}
});
10 changes: 5 additions & 5 deletions test/testUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class TestUtil {
public static TEST_UPDATES_DIRECTORY: string = "--updates-directory";
public static CORE_TESTS_ONLY: string = "--core";
public static PULL_FROM_NPM: string = "--npm";
public static NO_SETUP: string = "--no-setup";
public static SETUP: string = "--setup";

public static defaultIOSServerUrl = "http://127.0.0.1:3000";
public static defaultAndroidServerUrl = "http://10.0.2.2:3001";
Expand Down Expand Up @@ -88,11 +88,11 @@ export class TestUtil {
}

/**
* Reads whether or not to setup the test directories.
* Reads whether or not to setup the test project directories.
*/
public static readNoSetup(): boolean {
var noSetup = TestUtil.readMochaCommandLineFlag(TestUtil.NO_SETUP);
if (noSetup) console.log("don't setup test directories");
public static readShouldSetup(): boolean {
var noSetup = TestUtil.readMochaCommandLineFlag(TestUtil.SETUP);
if (noSetup) console.log("set up test project directories");
return noSetup;
}

Expand Down

0 comments on commit 6091eb6

Please sign in to comment.