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

Commit b6a4eb5

Browse files
committed
Merge pull request #5915 from adobe/jasonsanjose/specrunner-copy
Implement copy with npm module fs-extra
2 parents e1bc7b6 + f7d5b98 commit b6a4eb5

5 files changed

Lines changed: 61 additions & 71 deletions

File tree

test/SpecRunner.js

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ define(function (require, exports, module) {
8080
var selectedSuites,
8181
params = new UrlParams(),
8282
reporter,
83-
_nodeConnectionDeferred = new $.Deferred(),
8483
reporterView,
8584
_writeResults = new $.Deferred(),
8685
_writeResultsPromise = _writeResults.promise(),
@@ -275,39 +274,6 @@ define(function (require, exports, module) {
275274
}
276275

277276
function init() {
278-
// Start up the node connection, which is held in the
279-
// _nodeConnectionDeferred module variable. (Use
280-
// _nodeConnectionDeferred.done() to access it.
281-
282-
// This is in SpecRunner rather than SpecRunnerUtils because the hope
283-
// is to hook up jasmine-node tests in this test runner.
284-
285-
// TODO: duplicates code from StaticServer
286-
// TODO: can this be done lazily?
287-
288-
var connectionTimeout = setTimeout(function () {
289-
console.error("[SpecRunner] Timed out while trying to connect to node");
290-
_nodeConnectionDeferred.reject();
291-
}, NODE_CONNECTION_TIMEOUT);
292-
293-
var _nodeConnection = new NodeConnection();
294-
_nodeConnection.connect(true).then(function () {
295-
var domainPath = FileUtils.getNativeBracketsDirectoryPath() + "/" + FileUtils.getNativeModuleDirectoryPath(module) + "/../test/node/TestingDomain";
296-
297-
_nodeConnection.loadDomains(domainPath, true)
298-
.then(
299-
function () {
300-
clearTimeout(connectionTimeout);
301-
_nodeConnectionDeferred.resolve(_nodeConnection);
302-
},
303-
function () { // Failed to connect
304-
console.error("[SpecRunner] Failed to connect to node", arguments);
305-
clearTimeout(connectionTimeout);
306-
_nodeConnectionDeferred.reject();
307-
}
308-
);
309-
});
310-
311277
selectedSuites = (params.get("suite") || localStorage.getItem("SpecRunner.suite") || "unit").split(",");
312278

313279
// Create a top-level filter to show/hide performance and extensions tests
@@ -410,19 +376,29 @@ define(function (require, exports, module) {
410376
}, true);
411377
}
412378

413-
/**
414-
* Allows access to the deferred that manages the node connection for tests.
415-
*
416-
* @return {jQuery.Deferred} The deferred that manages the node connection
417-
*/
418-
function getNodeConnectionDeferred() {
419-
return _nodeConnectionDeferred;
379+
function connectToTestDomain() {
380+
var _nodeConnectionDeferred = new $.Deferred(),
381+
_nodeConnection = new NodeConnection();
382+
383+
_nodeConnection.connect(true).then(function () {
384+
var domainPath = FileUtils.getNativeBracketsDirectoryPath() + "/" + FileUtils.getNativeModuleDirectoryPath(module) + "/../test/node/TestingDomain";
385+
386+
_nodeConnection.loadDomains(domainPath, true)
387+
.then(init, function () {
388+
// Failed to connect
389+
console.error("[SpecRunner] Failed to connect to node", arguments);
390+
391+
var container = $('<div class="container-fluid">');
392+
container.append('<div class="alert alert-error">Failed to connect to Node</div>');
393+
394+
$(window.document.body).append(container);
395+
});
396+
});
397+
398+
Async.withTimeout(_nodeConnectionDeferred.promise(), NODE_CONNECTION_TIMEOUT);
399+
400+
brackets.testing = { nodeConnection: _nodeConnection };
420401
}
421402

422-
// this is used by SpecRunnerUtils
423-
brackets.testing = {
424-
getNodeConnectionDeferred: getNodeConnectionDeferred
425-
};
426-
427-
init();
403+
connectToTestDomain();
428404
});

test/node/TestingDomain.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,25 @@ function init(domainManager) {
4949
description: "path to the directory to remove"
5050
}]
5151
);
52+
domainManager.registerCommand(
53+
"testing",
54+
"copy",
55+
fs.copy,
56+
true,
57+
"Copy a file or directory. The directory can have contents. Like cp -r.",
58+
[
59+
{
60+
name: "src",
61+
type: "string",
62+
description: "directory source to copy"
63+
},
64+
{
65+
name: "dest",
66+
type: "string",
67+
description: "destination directory"
68+
}
69+
]
70+
);
5271
}
5372

5473
exports.init = init;

test/spec/LiveDevelopment-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ define(function (require, exports, module) {
547547

548548
// copy files to temp directory
549549
runs(function () {
550-
waitsForDone(SpecRunnerUtils.copyPath(testPath, tempDir), "copy temp files");
550+
waitsForDone(SpecRunnerUtils.copy(testPath, tempDir), "copy temp files");
551551
});
552552

553553
// open project

test/spec/LowLevelFileIO-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ define(function (require, exports, module) {
9696
runs(function () {
9797
// create the test folder and init the test files
9898
var testFiles = SpecRunnerUtils.getTestPath("/spec/LowLevelFileIO-test-files");
99-
waitsForDone(SpecRunnerUtils.copyPath(testFiles, baseDir), "copy temp files");
99+
waitsForDone(SpecRunnerUtils.copy(testFiles, baseDir), "copy temp files");
100100
});
101101
runs(function () {
102102
// Pre-test setup - set permissions on special directories

test/spec/SpecRunnerUtils.js

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ define(function (require, exports, module) {
5454
_rootSuite = { id: "__brackets__" },
5555
_unitTestReporter;
5656

57-
5857
/**
5958
* Delete a path
6059
* @param {string} fullPath
@@ -110,35 +109,30 @@ define(function (require, exports, module) {
110109
return deferred.promise();
111110
}
112111

112+
function testDomain() {
113+
return brackets.testing.nodeConnection.domains.testing;
114+
}
115+
113116
/**
114117
* Remove a directory (recursively) or file
115118
*
116119
* @param {!string} path Path to remove
117120
* @return {$.Promise} Resolved when the path is removed, rejected if there was a problem
118121
*/
119122
function remove(path) {
120-
var d = new $.Deferred();
121-
var nodeDeferred = brackets.testing.getNodeConnectionDeferred();
122-
nodeDeferred
123-
.done(function (connection) {
124-
if (connection.connected()) {
125-
connection.domains.testing.remove(path)
126-
.done(function () {
127-
d.resolve();
128-
})
129-
.fail(function () {
130-
d.reject();
131-
});
132-
} else {
133-
d.reject();
134-
}
135-
})
136-
.fail(function () {
137-
d.reject();
138-
});
139-
return d.promise();
123+
return testDomain().remove(path);
124+
}
125+
126+
/**
127+
* Copy a directory (recursively) or file
128+
*
129+
* @param {!string} src Path to copy
130+
* @param {!string} dest Destination directory
131+
* @return {$.Promise} Resolved when the path is copied, rejected if there was a problem
132+
*/
133+
function copy(src, dest) {
134+
return testDomain().copy(src, dest);
140135
}
141-
142136

143137
/**
144138
* Resolves a path string to a File or Directory
@@ -1248,6 +1242,7 @@ define(function (require, exports, module) {
12481242

12491243
exports.chmod = chmod;
12501244
exports.remove = remove;
1245+
exports.copy = copy;
12511246
exports.getTestRoot = getTestRoot;
12521247
exports.getTestPath = getTestPath;
12531248
exports.getTempDirectory = getTempDirectory;

0 commit comments

Comments
 (0)