Launch UI tests in new, clean window

Add utility methods to SpecRunnerUtils.js to setup and teardown new brackets window when running UI-dependent tests.

Add loadProject utility to load testWindow projects.

Update ProjectManager and FileCommandHandlers tests to use new utilities.
This commit is contained in:
Jason San Jose 2012-01-13 14:34:58 -08:00
Родитель eb6b7d8c53
Коммит 575bf29022
5 изменённых файлов: 102 добавлений и 73 удалений

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

@ -173,5 +173,4 @@ define(function(require, exports, module) {
// Internal Use Only
exports._reset = _reset;
exports._setStorageKey = _setStorageKey;
exports._PREFERENCES_KEY = PREFERENCES_KEY;
});

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

@ -9,7 +9,7 @@ define(function(require, exports, module) {
// Unique key for unit testing
var PreferencesManager = require("PreferencesManager");
PreferencesManager.setStorageKey( SpecRunnerUtils.TEST_PREFERENCES_KEY );
PreferencesManager._setStorageKey( SpecRunnerUtils.TEST_PREFERENCES_KEY );
// Load test specs
require("spec/Editor-test.js");

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

@ -7,31 +7,25 @@ define(function(require, exports, module) {
, SpecRunnerUtils = require("./SpecRunnerUtils.js");
;
// FIXME (jasonsj): these tests are ommitted when launching in the main app window
if (window.opener) {
describe("FileCommandHandlers", function() {
var testPath = SpecRunnerUtils.getTestPath("/spec/FileCommandHandlers-test-files");
var TEST_JS_CONTENT = 'var myContent="This is awesome!";';
var TEST_JS_NEW_CONTENT = "hello world";
beforeEach(function() {
// this.app = window.open(SpecRunnerUtils.getBracketsSourceRoot() + "/index.html");
// TODO: this will only work if run from the main Brackets window (not from jasmine.sh)
this.app = window.opener;
// Load module instances from brackets.test
CommandManager = this.app.brackets.test.CommandManager;
Commands = this.app.brackets.test.Commands;
FileCommandHandlers = this.app.brackets.test.FileCommandHandlers;
this.app.location.reload();
this.testPath = SpecRunnerUtils.getTestPath("/spec/FileCommandHandlers-test-files");
var isReady = false;
$(this.app.document).ready(function() {
isReady = true;
SpecRunnerUtils.beforeTestWindow( this, function( testWindow ) {
this.testWindow = testWindow;
// Load module instances from brackets.test
CommandManager = testWindow.brackets.test.CommandManager;
Commands = testWindow.brackets.test.Commands;
FileCommandHandlers = testWindow.brackets.test.FileCommandHandlers;
});
waitsFor(function() { return isReady; }, 5000);
});
afterEach(function() {
SpecRunnerUtils.afterTestWindow();
});
// TODO (jasonsj): test Commands.FILE_NEW. Current implementation of
@ -51,7 +45,7 @@ define(function(require, exports, module) {
waitsFor(function() { return didClose && !gotError; }, 1000);
runs(function() {
expect(this.app.$("#main-toolbar .title").text()).toBe("Untitled");
expect(this.testWindow.$("#main-toolbar .title").text()).toBe("Untitled");
});
});
@ -59,7 +53,7 @@ define(function(require, exports, module) {
var didOpen = false, didClose = false, gotError = false;
runs(function() {
CommandManager.execute(Commands.FILE_OPEN, this.testPath + "/test.js")
CommandManager.execute(Commands.FILE_OPEN, testPath + "/test.js")
.done(function() { didOpen = true; })
.fail(function() { gotError = true; });
});
@ -74,7 +68,7 @@ define(function(require, exports, module) {
waitsFor(function() { return didClose && !gotError; }, 1000);
runs(function() {
expect(this.app.$("#main-toolbar .title").text()).toBe("Untitled");
expect(this.testWindow.$("#main-toolbar .title").text()).toBe("Untitled");
});
});
});
@ -84,7 +78,7 @@ define(function(require, exports, module) {
var didOpen = false, gotError = false;
runs(function() {
CommandManager.execute(Commands.FILE_OPEN, this.testPath + "/test.js")
CommandManager.execute(Commands.FILE_OPEN, testPath + "/test.js")
.done(function() { didOpen = true; })
.fail(function() { gotError = true; });
});
@ -99,7 +93,7 @@ define(function(require, exports, module) {
describe("Save File", function() {
it("should save changes", function() {
var didOpen = false, didSave = false, gotError = false;
var filePath = this.testPath + "/test.js";
var filePath = testPath + "/test.js";
var editor = FileCommandHandlers.getEditor();
runs(function() {
@ -147,7 +141,7 @@ define(function(require, exports, module) {
var didOpen = false, gotError = false;
runs(function() {
CommandManager.execute(Commands.FILE_OPEN, this.testPath + "/test.js")
CommandManager.execute(Commands.FILE_OPEN, testPath + "/test.js")
.done(function() { didOpen = true; })
.fail(function() { gotError = true; });
});
@ -169,7 +163,7 @@ define(function(require, exports, module) {
var didOpen = false, gotError = false;
runs(function() {
CommandManager.execute(Commands.FILE_OPEN, this.testPath + "/test.js")
CommandManager.execute(Commands.FILE_OPEN, testPath + "/test.js")
.done(function() { didOpen = true; })
.fail(function() { gotError = true; });
});
@ -199,7 +193,7 @@ define(function(require, exports, module) {
var didOpen = false, gotError = false;
runs(function() {
CommandManager.execute(Commands.FILE_OPEN, this.testPath + "/test.js")
CommandManager.execute(Commands.FILE_OPEN, testPath + "/test.js")
.done(function() { didOpen = true; })
.fail(function() { gotError = true; });
});
@ -223,5 +217,4 @@ define(function(require, exports, module) {
// TODO (jasonsj): experiment with mocks instead of real UI
});
}
});

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

@ -5,33 +5,20 @@ define(function(require, exports, module) {
, SpecRunnerUtils = require("./SpecRunnerUtils.js")
;
// FIXME (jasonsj): these tests are ommitted when launching in the main app window
if (window.opener) { // (function(){
describe("ProjectManager", function() {
var testPath = SpecRunnerUtils.getTestPath("/spec/ProjectManager-test-files");
beforeEach(function() {
this.app = window.opener;
// Load module instances from brackets.test
ProjectManager = this.app.brackets.test.ProjectManager;
PreferencesManager = this.app.brackets.test.PreferencesManager;
// Temporarily use test key in the main app window
this.oldKey = PreferencesManager._setStorageKey( SpecRunnerUtils.TEST_PREFERENCES_KEY );
this.app.location.reload();
this.testPath = SpecRunnerUtils.getTestPath("/spec/ProjectManager-test-files");
var isReady = false;
$(this.app.document).ready(function() {
isReady = true;
SpecRunnerUtils.beforeTestWindow( this, function( testWindow ) {
// Load module instances from brackets.test
ProjectManager = testWindow.brackets.test.ProjectManager;
PreferencesManager = testWindow.brackets.test.PreferencesManager;
});
waitsFor(function() { return isReady; }, 5000);
});
afterEach(function() {
// restore main app window preferences key
PreferencesManager._setStorageKey( this.oldKey );
SpecRunnerUtils.afterTestWindow();
});
describe("createNewItem", function() {
@ -39,21 +26,18 @@ define(function(require, exports, module) {
it("should create a new file with a given name", function() {
var didCreate = false, gotError = false;
runs(function() {
ProjectManager.loadProject(this.testPath);
});
waitsFor(function() { return ProjectManager.getProjectRoot() }, "loadProject() timeout", 1000);
SpecRunnerUtils.loadProject( testPath );
runs(function() {
// skip rename
ProjectManager.createNewItem(this.testPath, "Untitled.js", true)
ProjectManager.createNewItem(testPath, "Untitled.js", true)
.done(function() { didCreate = true; })
.fail(function() { gotError = true; });
});
waitsFor(function() { return didCreate && !gotError; }, "ProjectManager.createNewItem() timeout", 1000);
var error, stat, complete = false;
var filePath = this.testPath + "/Untitled.js";
var filePath = testPath + "/Untitled.js";
runs(function() {
brackets.fs.stat(filePath, function(err, _stat) {
error = err;
@ -87,14 +71,11 @@ define(function(require, exports, module) {
it("should fail when a file already exists", function() {
var didCreate = false, gotError = false;
runs(function() {
ProjectManager.loadProject(this.testPath);
});
waitsFor(function() { return ProjectManager.getProjectRoot() }, "loadProject() timeout", 1000);
SpecRunnerUtils.loadProject( testPath );
runs(function() {
// skip rename
ProjectManager.createNewItem(this.testPath, "file.js", true)
ProjectManager.createNewItem(testPath, "file.js", true)
.done(function() { didCreate = true; })
.fail(function() { gotError = true; });
});
@ -109,14 +90,11 @@ define(function(require, exports, module) {
it("should fail when a file name matches a directory that already exists", function() {
var didCreate = false, gotError = false;
runs(function() {
ProjectManager.loadProject(this.testPath);
});
waitsFor(function() { return ProjectManager.getProjectRoot() }, "loadProject() timeout", 1000);
SpecRunnerUtils.loadProject( testPath );
runs(function() {
// skip rename
ProjectManager.createNewItem(this.testPath, "directory", true)
ProjectManager.createNewItem(testPath, "directory", true)
.done(function() { didCreate = true; })
.fail(function() { gotError = true; });
});
@ -134,10 +112,7 @@ define(function(require, exports, module) {
var len = chars.length;
var charAt, didCreate, gotError;
runs(function() {
ProjectManager.loadProject(this.testPath);
});
waitsFor(function() { return ProjectManager.getProjectRoot() }, "loadProject() timeout", 1000);
SpecRunnerUtils.loadProject( testPath );
for (i = 0; i < len; i++) {
didCreate = false;
@ -146,7 +121,7 @@ define(function(require, exports, module) {
runs(function() {
// skip rename
ProjectManager.createNewItem(this.testPath, "file" + charAt + ".js", true)
ProjectManager.createNewItem(testPath, "file" + charAt + ".js", true)
.done(function() { didCreate = true; })
.fail(function() { gotError = true; });
});
@ -161,6 +136,4 @@ define(function(require, exports, module) {
});
});
}
});

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

@ -1,6 +1,7 @@
define(function(require, exports, module) {
var TEST_PREFERENCES_KEY = "com.adobe.brackets.test.preferences";
var TEST_PREFERENCES_KEY = "com.adobe.brackets.test.preferences"
, testWindow;
function getTestRoot() {
// /path/to/brackets/test/SpecRunner.html
@ -23,9 +24,72 @@ define(function(require, exports, module) {
return path.join("/");
}
function beforeTestWindow(spec, callback) {
var isReady = false;
runs(function() {
testWindow = window.open( getBracketsSourceRoot() + "/index.html" );
});
waitsFor(function() {
return testWindow.brackets && testWindow.brackets.test;
}, 5000);
runs(function() {
// all test windows should use unit test preferences
testWindow.brackets.test.PreferencesManager._setStorageKey( TEST_PREFERENCES_KEY );
// callback allows specs to query the testWindow before they run
callback.call( spec, testWindow );
isReady = true;
});
waitsFor(function() { return isReady; }, 5000);
}
function afterTestWindow() {
// debug-only to see testWindow state before closing
// waits(500);
runs(function() {
testWindow.close();
});
}
function loadProject( path ) {
var isReady = false
, projectTreeContainer;
runs(function() {
// find the project tree in the testWindow
projectTreeContainer = testWindow.$("#project-files-container");
// begin loading project path
testWindow.brackets.test.ProjectManager.loadProject(path);
});
// wait for file system to finish loading
waitsFor(function() {
return testWindow.brackets.test.ProjectManager.getProjectRoot().fullPath === path;
}, "loadProject() timeout", 1000);
// listen for "loaded.jstree" to signal ready state
runs(function() {
projectTreeContainer.bind("loaded.jstree", function(event, data){
isReady = true;
});
});
waitsFor(function() { return isReady; }, "jstree timeout", 1000);
}
exports.TEST_PREFERENCES_KEY = TEST_PREFERENCES_KEY;
exports.getTestRoot = getTestRoot;
exports.getTestPath = getTestPath;
exports.getBracketsSourceRoot = getBracketsSourceRoot;
exports.beforeTestWindow = beforeTestWindow;
exports.afterTestWindow = afterTestWindow;
exports.loadProject = loadProject;
});