Skip to content

Instantly share code, notes, and snippets.

@dcbartlett
Forked from colinwren/appHelper.js
Last active December 16, 2015 23:39
Show Gist options
  • Save dcbartlett/5515615 to your computer and use it in GitHub Desktop.
Save dcbartlett/5515615 to your computer and use it in GitHub Desktop.
var fs = require('fs-extra');
var wrench = require('wrench');
var exec = require('child_process').exec;
var path = require('path');
var sailsBin = path.resolve('./bin/sails.js');
/**
* Uses the Sails binary to create a namespaced test app
* If no appName is given use 'testApp'
*
* It copies all the files in the fixtures folder into their
* respective place in the test app so you don't need to worry
* about setting up the fixtures.
*/
module.exports.build = function(/* [appName], done */) {
var args = Array.prototype.slice.call(arguments),
done = args.pop(),
appName = 'testApp';
// Allow App Name to be optional
if(args.length > 0) appName = args[0];
// Cleanup old test fixtures
if (fs.existsSync(appName)) {
wrench.rmdirSyncRecursive(path.resolve('./', appName));
}
exec(sailsBin + ' new ' + appName, function(err) {
if (err) done(err);
wrench.copyDirSyncRecursive('./test/http/fixtures', path.resolve('./', appName), {
forceDelete: true
});
//var fixtures = wrench.readdirSyncRecursive('./test/http/fixtures');
//if(fixtures.length < 1) return done();
// If fixtures copy them to the test app
//fixtures.forEach(function(file) {
//var filePath = path.resolve('./test/http/fixtures/', file);
// Check if file is a directory
//var stat = fs.statSync(filePath);
// Ignore directories
//if(stat.isDirectory()) return;
// Copy File to Test App
//var data = fs.readFileSync(filePath);
//fs.createFileSync(path.resolve('./', appName, file));
//fs.writeFileSync(path.resolve('./', appName, file), data);
//});
done();
});
};
/**
* Remove a Test App
*/
module.exports.teardown = function(appName) {
appName = appName ? appName : 'testApp';
var dir = path.resolve('./', appName);
if (fs.existsSync(dir)) {
wrench.rmdirSyncRecursive(dir);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment