var fs = require('fs'),
    testResource = require('../../../test_resource'),
    compileJadeDirectory = require('../../../../task/worker/compile_jade_directory');

exports.setUp = function (done) {
    process.env.TASK_LOG_DISABLED = true;
    done();
};
exports.tearDown = function (done) {
    process.env.TASK_LOG_DISABLED = false;
    done();
};

exports['Compile jade files.'] = function (test) {
    var workDir = testResource.resolveWorkFile('work_compile_jade_files');
    testResource.prepareCleanWorkDir(workDir, function () {
        compileJadeDirectory({
                srcDir: testResource.resolveMockFile('.'),
                destDir: workDir,
                pattern: '*.jade',
                ignore: [],
                dataFile: testResource.resolveMockFile('mock-data.json')
            },
            function (err) {
                test.ifError(err);
                fs.readdir(workDir, function (err, files) {
                    test.ok(files);
                    test.done();
                });
            }
        );
    });
};

exports['Minify a file.'] = function (test) {
    var workDir = testResource.resolveWorkFile('work_compile_jade_minify');
    testResource.prepareCleanWorkDir(workDir, function () {
        var workHtml = testResource.resolveWorkFile(workDir, 'foo.html');
        compileJadeDirectory._minify(workHtml, function (err) {
            test.ok(err);
            fs.writeFile(workHtml, '<h1>Hey!</h1>', function () {
                compileJadeDirectory._minify(workHtml, function (err) {
                    test.ifError(err);
                    test.done();
                });
            });
        })
    });
};