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

Commit

Permalink
Merge pull request #2301 from adobe/jasonsanjose/issue-517
Browse files Browse the repository at this point in the history
Copy unit test files into a temporary directory
  • Loading branch information
redmunds committed Dec 11, 2012
2 parents 46ceac1 + 2e6e053 commit 211f899
Show file tree
Hide file tree
Showing 8 changed files with 503 additions and 288 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ src/extensions/disabled

#OSX .DS_Store files
.DS_Store

# unit test working directory
test/temp
39 changes: 15 additions & 24 deletions src/extensions/default/JavaScriptQuickEdit/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,24 @@ define(function (require, exports, module) {

var extensionPath = FileUtils.getNativeModuleDirectoryPath(module),
testPath = extensionPath + "/unittest-files/syntax",
tempPath = SpecRunnerUtils.getTempDirectory(),
testWindow,
initInlineTest;

function rewriteProject(spec) {
var result = new $.Deferred();

FileIndexManager.getFileInfoList("all").done(function (allFiles) {
// convert fileInfos to fullPaths
allFiles = allFiles.map(function (fileInfo) {
return fileInfo.fullPath;
});

// parse offsets and save
SpecRunnerUtils.saveFilesWithoutOffsets(allFiles).done(function (offsetInfos) {
spec.infos = offsetInfos;
var result = new $.Deferred(),
infos = {},
options = {
parseOffsets : true,
infos : infos,
removePrefix : true
};

// install after function to restore file content
spec.after(function () {
runs(function () {
waitsForDone(SpecRunnerUtils.saveFilesWithOffsets(spec.infos), "saveFilesWithOffsets");
});
});

result.resolve();
}).fail(function () {
result.reject();
});
SpecRunnerUtils.copyPath(testPath, tempPath, options).done(function () {
spec.infos = infos;
result.resolve();
}).fail(function () {
result.reject();
});

return result.promise();
Expand All @@ -92,12 +83,12 @@ define(function (require, exports, module) {
workingSet = workingSet || [];
expectInline = (expectInline !== undefined) ? expectInline : true;

SpecRunnerUtils.loadProjectInTestWindow(testPath);

runs(function () {
waitsForDone(rewriteProject(spec), "rewriteProject");
});

SpecRunnerUtils.loadProjectInTestWindow(tempPath);

runs(function () {
workingSet.push(openFile);
waitsForDone(SpecRunnerUtils.openProjectFiles(workingSet), "openProjectFiles");
Expand Down
33 changes: 32 additions & 1 deletion src/file/NativeFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ define(function (require, exports, module) {
*
* @param {!string} path
* @param {!function(FileSystem)} successCallback
* @param {!function(number)} errorCallback (TODO #2057: should pass a FileError)
* @param {!function(FileError)} errorCallback (TODO #2057: should pass a DOMError)
*/
requestNativeFileSystem: function (path, successCallback, errorCallback) {
brackets.fs.stat(path, function (err, data) {
Expand All @@ -119,6 +119,31 @@ define(function (require, exports, module) {
}
});
},

/**
* NativeFileSystem implementation of LocalFileSystem.resolveLocalFileSystemURL()
*
* @param {!string} url
* @param {!function(Entry)} successCallback
* @param {!function(FileError)} errorCallback (TODO #2057: should pass a DOMError)
*/
resolveNativeFileSystemPath: function (path, successCallback, errorCallback) {
brackets.fs.stat(path, function (err, stats) {
if (!err) {
var entry;

if (stats.isDirectory()) {
entry = new NativeFileSystem.DirectoryEntry(path);
} else {
entry = new NativeFileSystem.FileEntry(path);
}

successCallback(entry);
} else if (errorCallback) {
errorCallback(NativeFileSystem._nativeToFileError(err));
}
});
},

/**
* Converts a brackets.fs.ERR_* error code to a FileError.* error code
Expand Down Expand Up @@ -761,6 +786,12 @@ define(function (require, exports, module) {
var entries = [];
var lastError = null;

// call success immediately if this directory has no files
if (filelist.length === 0) {
successCallback(entries);
return;
}

// stat() to determine type of each entry, then populare entries array with objects
var masterPromise = Async.doInParallel(filelist, function (filename, index) {

Expand Down
4 changes: 2 additions & 2 deletions test/spec/DocumentCommandHandlers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ define(function (require, exports, module) {

// clean up
runs(function () {
promise = SpecRunnerUtils.deleteFile(crlfPath);
promise = SpecRunnerUtils.deletePath(crlfPath);
waitsForDone(promise, "Remove CRLF test file");
});
runs(function () {
promise = SpecRunnerUtils.deleteFile(lfPath);
promise = SpecRunnerUtils.deletePath(lfPath);
waitsForDone(promise, "Remove LF test file");
});
});
Expand Down
76 changes: 30 additions & 46 deletions test/spec/InlineEditorProviders-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ define(function (require, exports, module) {
var Commands, // loaded from brackets.test
EditorManager, // loaded from brackets.test
FileSyncManager, // loaded from brackets.test
FileIndexManager, // loaded from brackets.test
DocumentManager, // loaded from brackets.test
FileViewController, // loaded from brackets.test
Dialogs = require("widgets/Dialogs"),
Expand All @@ -42,6 +41,7 @@ define(function (require, exports, module) {
describe("InlineEditorProviders", function () {

var testPath = SpecRunnerUtils.getTestPath("/spec/InlineEditorProviders-test-files"),
tempPath = SpecRunnerUtils.getTempDirectory(),
testWindow,
initInlineTest;

Expand All @@ -50,42 +50,26 @@ define(function (require, exports, module) {
}

function rewriteProject(spec) {
var result = new $.Deferred();

FileIndexManager.getFileInfoList("all").done(function (allFiles) {
// convert fileInfos to fullPaths
allFiles = allFiles.map(function (fileInfo) {
return fileInfo.fullPath;
});

// parse offsets and save
SpecRunnerUtils.saveFilesWithoutOffsets(allFiles).done(function (offsetInfos) {
spec.infos = offsetInfos;
var result = new $.Deferred(),
infos = {},
options = {
parseOffsets : true,
infos : infos,
removePrefix : true
};

// install after function to restore file content
spec.after(function () {
var done = false;

runs(function () {
SpecRunnerUtils.saveFilesWithOffsets(spec.infos).done(function () {
done = true;
});
});

waitsFor(function () { return done; }, "saveFilesWithOffsets timeout", 1000);
});

result.resolve();
}).fail(function () {
result.reject();
});
SpecRunnerUtils.copyPath(testPath, tempPath, options).done(function () {
spec.infos = infos;
result.resolve();
}).fail(function () {
result.reject();
});

return result.promise();
}

/**
* Performs setup for an inline editor test. Parses offsets (saved to Spec.offsets) for all files in
* Performs setup for an inline editor test. Parses offsets (saved to Spec.infos) for all files in
* the test project (testPath) and saves files back to disk without offset markup.
* When finished, open an editor for the specified project relative file path
* then attempts opens an inline editor at the given offset. Installs an after()
Expand All @@ -108,8 +92,6 @@ define(function (require, exports, module) {

expectInline = (expectInline !== undefined) ? expectInline : true;

SpecRunnerUtils.loadProjectInTestWindow(testPath);

// load project to set CSSUtils scope
runs(function () {
rewriteProject(spec)
Expand All @@ -119,6 +101,8 @@ define(function (require, exports, module) {

waitsFor(function () { return rewriteDone && !rewriteErr; }, "rewriteProject timeout", 1000);

SpecRunnerUtils.loadProjectInTestWindow(tempPath);

runs(function () {
workingSet.push(openFile);
SpecRunnerUtils.openProjectFiles(workingSet).done(function (documents) {
Expand Down Expand Up @@ -176,7 +160,6 @@ define(function (require, exports, module) {
Commands = testWindow.brackets.test.Commands;
EditorManager = testWindow.brackets.test.EditorManager;
FileSyncManager = testWindow.brackets.test.FileSyncManager;
FileIndexManager = testWindow.brackets.test.FileIndexManager;
DocumentManager = testWindow.brackets.test.DocumentManager;
FileViewController = testWindow.brackets.test.FileViewController;
});
Expand Down Expand Up @@ -246,6 +229,9 @@ define(function (require, exports, module) {
afterEach(function () {
//debug visual confirmation of inline editor
//waits(1000);
runs(function () {
SpecRunnerUtils.deletePath(tempPath);
});

// revert files to original content with offset markup
SpecRunnerUtils.closeTestWindow();
Expand Down Expand Up @@ -553,11 +539,13 @@ define(function (require, exports, module) {

it("should close inline editor when file deleted on disk", function () {
// Create an expendable CSS file
var fileToWrite = new NativeFileSystem.FileEntry(testPath + "/tempCSS.css");
var savedTempCSSFile = false;
var fileToWrite,
savedTempCSSFile = false;

runs(function () {
FileUtils.writeText(fileToWrite, "#anotherDiv {}")
.done(function () {
SpecRunnerUtils.createTextFile(tempPath + "/tempCSS.css", "#anotherDiv {}")
.done(function (entry) {
fileToWrite = entry;
savedTempCSSFile = true;
});
});
Expand All @@ -569,19 +557,15 @@ define(function (require, exports, module) {
});
// initInlineTest() inserts a waitsFor() automatically, so must end runs() block here

// Delete the file
var fileDeleted = false;
runs(function () {
var hostEditor = EditorManager.getCurrentFullEditor();
expect(hostEditor.getInlineWidgets().length).toBe(1);

brackets.fs.unlink(fileToWrite.fullPath, function (err) {
if (!err) {
fileDeleted = true;
}
});
});
waitsFor(function () { return fileDeleted; }, 1000);

// Delete the file
runs(function () {
waitsForDone(SpecRunnerUtils.deletePath(fileToWrite.fullPath));
});

// Ping FileSyncManager to recognize the deletion
runs(function () {
Expand Down
Loading

0 comments on commit 211f899

Please sign in to comment.