Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Use one window for all specs in the suite on more integration tests #4635

Merged
merged 1 commit into from
Aug 2, 2013
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
209 changes: 101 additions & 108 deletions test/spec/CSSUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
*/

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

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

var NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
Async = require("utils/Async"),
Expand Down Expand Up @@ -568,7 +568,7 @@ define(function (require, exports, module) {
}); // describe("CSSUtils")


describe("CSS Parsing: ", function () {
describe("CSS Parsing", function () {

var lastCssCode,
match,
Expand Down Expand Up @@ -639,7 +639,7 @@ define(function (require, exports, module) {
});


describe("Simple selectors: ", function () {
describe("Simple selectors", function () {

it("should match a lone type selector given a type", function () {
var result = match("div { color:red }", { tag: "div" });
Expand Down Expand Up @@ -1366,143 +1366,136 @@ define(function (require, exports, module) {

}); // describe("Known Issues")


describe("Working with real public CSSUtils API", function () {
this.category = "integration";

var CSSUtils;

beforeEach(function () {
SpecRunnerUtils.createTestWindowAndRun(this, function (testWindow) {
// Load module instances from brackets.test
CSSUtils = testWindow.brackets.test.CSSUtils;

// Load test project
var testPath = SpecRunnerUtils.getTestPath("/spec/CSSUtils-test-files");
SpecRunnerUtils.loadProjectInTestWindow(testPath);
});
});
afterEach(function () {
CSSUtils = null;
SpecRunnerUtils.closeTestWindow();
});

it("should include comment preceding selector (issue #403)", function () {
var rules;
runs(function () {
CSSUtils.findMatchingRules("#issue403")
.done(function (result) { rules = result; });
});
waitsFor(function () { return rules !== undefined; }, "CSSUtils.findMatchingRules() timeout", 1000);

runs(function () {
expect(rules.length).toBe(1);
expect(rules[0].lineStart).toBe(4);
expect(rules[0].lineEnd).toBe(7);
});
});

});


describe("Working with unsaved changes", function () {
describe("CSS Intgration Tests", function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This File is a mess, but I just moved both integration suits from this file to this new suite used to create and destroy the window.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

this.category = "integration";

var testPath = SpecRunnerUtils.getTestPath("/spec/CSSUtils-test-files"),
testWindow,
CSSUtils,
DocumentManager,
FileViewController;

beforeEach(function () {
SpecRunnerUtils.createTestWindowAndRun(this, function (testWindow) {

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

// Load module instances from brackets.test
CSSUtils = testWindow.brackets.test.CSSUtils;
DocumentManager = testWindow.brackets.test.DocumentManager;
FileViewController = testWindow.brackets.test.FileViewController;


// Load test project
SpecRunnerUtils.loadProjectInTestWindow(testPath);
});
});

afterEach(function () {
afterLast(function () {
CSSUtils = null;
DocumentManager = null;
FileViewController = null;
SpecRunnerUtils.closeTestWindow();
});

it("should return the correct offsets if the file has changed", function () {
var didOpen = false,
gotError = false;

runs(function () {
FileViewController.openAndSelectDocument(testPath + "/simple.css", FileViewController.PROJECT_MANAGER)
.done(function () { didOpen = true; })
.fail(function () { gotError = true; });
});

waitsFor(function () { return didOpen && !gotError; }, "FileViewController.addToWorkingSetAndSelect() timeout", 1000);

var rules = null;
afterEach(function () {
testWindow.closeAllFiles();
});


describe("Working with real public CSSUtils API", function () {

runs(function () {
var doc = DocumentManager.getCurrentDocument();

// Add several blank lines at the beginning of the text
doc.setText("\n\n\n\n" + doc.getText());

// Look for ".FIRSTGRADE"
CSSUtils.findMatchingRules(".FIRSTGRADE")
.done(function (result) { rules = result; });
it("should include comment preceding selector (issue #403)", function () {
var rules;
runs(function () {
CSSUtils.findMatchingRules("#issue403")
.done(function (result) { rules = result; });
});
waitsFor(function () { return rules !== undefined; }, "CSSUtils.findMatchingRules() timeout", 1000);

doc = null;
});

waitsFor(function () { return rules !== null; }, "CSSUtils.findMatchingRules() timeout", 1000);

runs(function () {
expect(rules.length).toBe(1);
expect(rules[0].lineStart).toBe(16);
expect(rules[0].lineEnd).toBe(18);
runs(function () {
expect(rules.length).toBe(1);
expect(rules[0].lineStart).toBe(4);
expect(rules[0].lineEnd).toBe(7);
});
});
});

it("should return a newly created rule in an unsaved file", function () {
var didOpen = false,
gotError = false;

runs(function () {
FileViewController.openAndSelectDocument(testPath + "/simple.css", FileViewController.PROJECT_MANAGER)
.done(function () { didOpen = true; })
.fail(function () { gotError = true; });
});
describe("Working with unsaved changes", function () {

waitsFor(function () { return didOpen && !gotError; }, "FileViewController.addToWorkingSetAndSelect() timeout", 1000);

var rules = null;

runs(function () {
var doc = DocumentManager.getCurrentDocument();
it("should return the correct offsets if the file has changed", function () {
var didOpen = false,
gotError = false;

// Add a new selector to the file
doc.setText(doc.getText() + "\n\n.TESTSELECTOR {\n font-size: 12px;\n}\n");
runs(function () {
FileViewController.openAndSelectDocument(testPath + "/simple.css", FileViewController.PROJECT_MANAGER)
.done(function () { didOpen = true; })
.fail(function () { gotError = true; });
});

// Look for the selector we just created
CSSUtils.findMatchingRules(".TESTSELECTOR")
.done(function (result) { rules = result; });

doc = null;
waitsFor(function () { return didOpen && !gotError; }, "FileViewController.addToWorkingSetAndSelect() timeout", 1000);

var rules = null;

runs(function () {
var doc = DocumentManager.getCurrentDocument();

// Add several blank lines at the beginning of the text
doc.setText("\n\n\n\n" + doc.getText());

// Look for ".FIRSTGRADE"
CSSUtils.findMatchingRules(".FIRSTGRADE")
.done(function (result) { rules = result; });

doc = null;
});

waitsFor(function () { return rules !== null; }, "CSSUtils.findMatchingRules() timeout", 1000);

runs(function () {
expect(rules.length).toBe(1);
expect(rules[0].lineStart).toBe(16);
expect(rules[0].lineEnd).toBe(18);
});
});

waitsFor(function () { return rules !== null; }, "CSSUtils.findMatchingRules() timeout", 1000);

runs(function () {
expect(rules.length).toBe(1);
expect(rules[0].lineStart).toBe(24);
expect(rules[0].lineEnd).toBe(26);
it("should return a newly created rule in an unsaved file", function () {
var didOpen = false,
gotError = false;

runs(function () {
FileViewController.openAndSelectDocument(testPath + "/simple.css", FileViewController.PROJECT_MANAGER)
.done(function () { didOpen = true; })
.fail(function () { gotError = true; });
});

waitsFor(function () { return didOpen && !gotError; }, "FileViewController.addToWorkingSetAndSelect() timeout", 1000);

var rules = null;

runs(function () {
var doc = DocumentManager.getCurrentDocument();

// Add a new selector to the file
doc.setText(doc.getText() + "\n\n.TESTSELECTOR {\n font-size: 12px;\n}\n");

// Look for the selector we just created
CSSUtils.findMatchingRules(".TESTSELECTOR")
.done(function (result) { rules = result; });

doc = null;
});

waitsFor(function () { return rules !== null; }, "CSSUtils.findMatchingRules() timeout", 1000);

runs(function () {
expect(rules.length).toBe(1);
expect(rules[0].lineStart).toBe(24);
expect(rules[0].lineEnd).toBe(26);
});
});
});
});

}); //describe("CSS Parsing")

// Unit Tests: "HTMLUtils (css)"
Expand Down
11 changes: 6 additions & 5 deletions test/spec/ExtensionUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
*
*/


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

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

var ExtensionUtils,
var ExtensionUtils, // Load from brackets.test
FileUtils = require("file/FileUtils"),
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
LESS_RESULT = require("text!spec/ExtensionUtils-test-files/less.text");
Expand All @@ -38,7 +39,7 @@ define(function (require, exports, module) {

var testWindow;

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

Expand All @@ -47,7 +48,7 @@ define(function (require, exports, module) {
});
});

afterEach(function () {
afterLast(function () {
testWindow = null;
ExtensionUtils = null;
SpecRunnerUtils.closeTestWindow();
Expand Down
Loading