/**
 * Generate test files unless exist.
 * @function ci.worker.generateTestFiles
 * @param {object} config - Task configuration.
 * @param {string} config.srcDir - Source files directory.
 * @param {string} [config.pattern='*.js'] - Src file name pattern.
 * @param {string} [config.ignore] - Src file name pattern to ignore.
 * @param {string} config.destDir - Destination test directory.
 * @param {function} callback - Callback when done.
 * @author Taka Okunishi
 *
 */
var path = require('path'),
    lib = require('../../lib'),
    object = lib.object,
    fallbackCopy = object.fallbackCopy,
    generateTestFiles = require('./generate_test_files');

exports = module.exports = function (config, callback) {
    var destDir = path.resolve(config.destDir);

    function resolveRelativePath(filename) {
        var dest = path.resolve(destDir, config.pattern || '*.js');
        return path.relative(path.dirname(dest), path.resolve(filename));
    }

    fallbackCopy({
        pattern: '*.js',
        ignore: '**/+(index|_prototype).js',
        data: {
            testResourcePath: resolveRelativePath('test/test_resource'),
            mockInjectorPath: resolveRelativePath('test/mock_injector')
        },
        tmpl: exports._unitTestTmplPath
    }, config);
    generateTestFiles(config, callback);
};
exports._unitTestTmplPath = path.resolve(__dirname, '../../tmpl/js/unit_test.js.hbs');


