Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/SpecRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,15 @@ define(function (require, exports, module) {
// Reset preferences from previous test runs
localStorage.removeItem("doLoadPreferences");
localStorage.removeItem(SpecRunnerUtils.TEST_PREFERENCES_KEY);

SpecRunnerUtils.runBeforeFirst();
});

afterEach(function () {
// Clean up preferencesKey
localStorage.removeItem("preferencesKey");

SpecRunnerUtils.runAfterLast();
});

jasmineEnv.updateInterval = 1000;
Expand Down
82 changes: 38 additions & 44 deletions test/spec/DocumentCommandHandlers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,75 +23,69 @@


/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, describe, beforeEach, afterEach, it, runs, waits, waitsFor, expect, brackets, waitsForDone, waitsForFail, spyOn */
/*global define, $, describe, beforeEach, afterEach, it, runs, waits, waitsFor, expect, brackets, waitsForDone, waitsForFail, spyOn, beforeFirst, afterLast */

define(function (require, exports, module) {
'use strict';

// Load dependent modules
var CommandManager, // loaded from brackets.test
Commands, // loaded from brackets.test
var CommandManager, // loaded from brackets.test
Commands, // loaded from brackets.test
DocumentCommandHandlers, // loaded from brackets.test
DocumentManager, // loaded from brackets.test
Dialogs, // loaded from brackets.test
FileViewController, // loaded from brackets.test
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
FileUtils = require("file/FileUtils"),
StringUtils = require("utils/StringUtils");
DocumentManager, // loaded from brackets.test
Dialogs, // loaded from brackets.test
FileViewController, // loaded from brackets.test
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
FileUtils = require("file/FileUtils"),
StringUtils = require("utils/StringUtils");

describe("DocumentCommandHandlers", function () {
this.category = "integration";

var topLevelSuite = this,
testPath = SpecRunnerUtils.getTestPath("/spec/DocumentCommandHandlers-test-files"),
var testPath = SpecRunnerUtils.getTestPath("/spec/DocumentCommandHandlers-test-files"),
testWindow,
specCount,
promise;

var TEST_JS_CONTENT = 'var myContent="This is awesome!";';
var TEST_JS_NEW_CONTENT = "hello world";
var TEST_JS_SECOND_NEW_CONTENT = "hello world 2";


beforeFirst(function () {
SpecRunnerUtils.createTestWindowAndRun(this, function (w) {
testWindow = w;

// Load module instances from brackets.test
CommandManager = testWindow.brackets.test.CommandManager;
Commands = testWindow.brackets.test.Commands;
DocumentCommandHandlers = testWindow.brackets.test.DocumentCommandHandlers;
DocumentManager = testWindow.brackets.test.DocumentManager;
Dialogs = testWindow.brackets.test.Dialogs;
FileViewController = testWindow.brackets.test.FileViewController;
});
});

afterLast(function () {
testWindow = null;
CommandManager = null;
Commands = null;
DocumentCommandHandlers = null;
DocumentManager = null;
Dialogs = null;
FileViewController = null;
SpecRunnerUtils.closeTestWindow();
});


beforeEach(function () {
if (specCount === undefined) {
specCount = SpecRunnerUtils.countSpecs(topLevelSuite);
}

if (!testWindow) {
SpecRunnerUtils.createTestWindowAndRun(this, function (w) {
testWindow = w;

// Load module instances from brackets.test
CommandManager = testWindow.brackets.test.CommandManager;
Commands = testWindow.brackets.test.Commands;
DocumentCommandHandlers = testWindow.brackets.test.DocumentCommandHandlers;
DocumentManager = testWindow.brackets.test.DocumentManager;
Dialogs = testWindow.brackets.test.Dialogs;
FileViewController = testWindow.brackets.test.FileViewController;
});
}

// Working set behavior is sensitive to whether file lives in the project or outside it, so make
// the project root a known quantity.
SpecRunnerUtils.loadProjectInTestWindow(testPath);
});

afterEach(function () {
specCount--;
promise = null;
testWindow.closeAllDocuments();

runs(function () {
if (specCount === 0) {
testWindow = null;
CommandManager = null;
Commands = null;
DocumentCommandHandlers = null;
DocumentManager = null;
SpecRunnerUtils.closeTestWindow();
}
});
});


Expand Down
74 changes: 42 additions & 32 deletions test/spec/EditorCommandHandlers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, describe, it, expect, beforeEach, afterEach, waitsFor, waits, runs, $, waitsForDone */
/*global define, describe, it, expect, beforeEach, afterEach, waitsFor, waits, runs, $, waitsForDone, beforeFirst, afterLast */

define(function (require, exports, module) {
'use strict';
Expand Down Expand Up @@ -94,23 +94,24 @@ define(function (require, exports, module) {
}


// Helper function for creating a window with an inline editor
function createWindowWithInlineEditor(spec) {
// Helper function for creating a test window
function createTestWindow(spec) {
SpecRunnerUtils.createTestWindowAndRun(spec, function (w) {
testWindow = w;

// Load module instances from brackets.test
CommandManager = testWindow.brackets.test.CommandManager;
Commands = testWindow.brackets.test.Commands;
EditorManager = testWindow.brackets.test.EditorManager;

SpecRunnerUtils.loadProjectInTestWindow(testPath);
});
}

// Helper function to open a new inline editor
function openInlineEditor(spec) {
var promise;

if (!testWindow) {
SpecRunnerUtils.createTestWindowAndRun(spec, function (w) {
testWindow = w;

// Load module instances from brackets.test
CommandManager = testWindow.brackets.test.CommandManager;
Commands = testWindow.brackets.test.Commands;
EditorManager = testWindow.brackets.test.EditorManager;

SpecRunnerUtils.loadProjectInTestWindow(testPath);
});
}

runs(function () {
promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: testPath + "/test.html"});
waitsForDone(promise, "Open into working set");
Expand Down Expand Up @@ -142,17 +143,13 @@ define(function (require, exports, module) {
});
}

// Helper function for closing the test window. This must be used in the last spec in the suite.
// Helper function for closing the test window
function closeTestWindow() {
runs(function () {
this.after(function () {
SpecRunnerUtils.closeTestWindow();
testWindow = null;
CommandManager = null;
Commands = null;
EditorManager = null;
});
});
testWindow = null;
CommandManager = null;
Commands = null;
EditorManager = null;
SpecRunnerUtils.closeTestWindow();
}


Expand Down Expand Up @@ -2135,8 +2132,16 @@ define(function (require, exports, module) {
" color: red;\n" +
"}";

beforeFirst(function () {
createTestWindow(this);
});

afterLast(function () {
closeTestWindow();
});

beforeEach(function () {
createWindowWithInlineEditor(this);
openInlineEditor(this);
});

afterEach(function () {
Expand Down Expand Up @@ -2192,8 +2197,6 @@ define(function (require, exports, module) {
expect(myEditor.document.getText()).toEqual(expectedText);
expect(myEditor.getFirstVisibleLine()).toBe(0);
expect(myEditor.getLastVisibleLine()).toBe(2);

closeTestWindow();
});
});

Expand Down Expand Up @@ -2625,13 +2628,22 @@ define(function (require, exports, module) {
" color: red;\n" +
"}";

beforeFirst(function () {
createTestWindow(this);
});

afterLast(function () {
closeTestWindow();
});

beforeEach(function () {
createWindowWithInlineEditor(this);
openInlineEditor(this);
});

afterEach(function () {
closeFilesInTestWindow();
});


it("should insert new line above the first line of the inline editor", function () {
myEditor.setSelection({line: 0, ch: 4}, {line: 0, ch: 6});
Expand Down Expand Up @@ -2709,8 +2721,6 @@ define(function (require, exports, module) {
expect(myEditor.document.getText()).toEqual(expectedText);
expect(myEditor.getFirstVisibleLine()).toBe(0);
expect(myEditor.getLastVisibleLine()).toBe(3);

closeTestWindow();
});
});
});
Expand Down
53 changes: 24 additions & 29 deletions test/spec/EditorOptionHandlers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, describe, beforeEach, afterEach, it, runs, waitsFor, expect, brackets, waitsForDone */
/*global define, $, describe, beforeEach, afterEach, it, runs, waitsFor, expect, brackets, waitsForDone, beforeFirst, afterLast */

define(function (require, exports, module) {
"use strict";
Expand Down Expand Up @@ -53,23 +53,32 @@ define(function (require, exports, module) {
BACKSPACE = 8;


beforeEach(function () {
beforeFirst(function () {
// Create a new window that will be shared by ALL tests in this spec.
if (!testWindow) {
SpecRunnerUtils.createTestWindowAndRun(this, function (w) {
testWindow = w;

// Load module instances from brackets.test
CommandManager = testWindow.brackets.test.CommandManager;
Commands = testWindow.brackets.test.Commands;
EditorManager = testWindow.brackets.test.EditorManager;
DocumentManager = testWindow.brackets.test.DocumentManager;
FileViewController = testWindow.brackets.test.FileViewController;
SpecRunnerUtils.createTestWindowAndRun(this, function (w) {
testWindow = w;

// Load module instances from brackets.test
CommandManager = testWindow.brackets.test.CommandManager;
Commands = testWindow.brackets.test.Commands;
EditorManager = testWindow.brackets.test.EditorManager;
DocumentManager = testWindow.brackets.test.DocumentManager;
FileViewController = testWindow.brackets.test.FileViewController;

SpecRunnerUtils.loadProjectInTestWindow(testPath);
});
}
SpecRunnerUtils.loadProjectInTestWindow(testPath);
});
});

afterLast(function () {
testWindow = null;
CommandManager = null;
Commands = null;
EditorManager = null;
DocumentManager = null;
FileViewController = null;
SpecRunnerUtils.closeTestWindow();
});


afterEach(function () {
runs(function () {
Expand Down Expand Up @@ -438,20 +447,6 @@ define(function (require, exports, module) {
checkCloseBraces(editor, {line: 0, ch: 15}, null, SINGLE_QUOTE, "var myContent ='' \"This is awesome!\";");
checkCloseBraces(editor, {line: 1, ch: 7}, null, SINGLE_QUOTE, "// Yes, it is!");
});

// This must be in the last spec in the suite. Note that it's possible to
// run a single test from suite, so this only works when running entire suite.
runs(function () {
this.after(function () {
testWindow = null;
CommandManager = null;
Commands = null;
EditorManager = null;
DocumentManager = null;
FileViewController = null;
SpecRunnerUtils.closeTestWindow();
});
});
});
});
});
Expand Down
23 changes: 10 additions & 13 deletions test/spec/InstallExtensionDialog-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, describe, it, xit, expect, beforeEach, afterEach, waits, waitsFor, runs, $, waitsForDone, spyOn, jasmine */
/*global define, describe, it, xit, expect, beforeEach, afterEach, waits, waitsFor, runs, $, waitsForDone, spyOn, jasmine, beforeFirst, afterLast */
/*unittests: Install Extension Dialog*/

define(function (require, exports, module) {
Expand All @@ -40,12 +40,15 @@ define(function (require, exports, module) {

this.category = "integration";

beforeEach(function () {
if (!testWindow) {
SpecRunnerUtils.createTestWindowAndRun(this, function (w) {
testWindow = w;
});
}
beforeFirst(function () {
SpecRunnerUtils.createTestWindowAndRun(this, function (w) {
testWindow = w;
});
});

afterLast(function () {
testWindow = null;
SpecRunnerUtils.closeTestWindow();
});

afterEach(function () {
Expand Down Expand Up @@ -716,11 +719,5 @@ define(function (require, exports, module) {
deferred.resolve(successfulResult);
});
});

// THIS MUST BE THE LAST SPEC IN THE SUITE
it("should close the test window", function () {
testWindow = null;
SpecRunnerUtils.closeTestWindow();
});
});
});
Loading