/** @overview nodeunit test case. */

var testResource = require('../../../test_resource'),
    fs = require('fs'),
    generateDataJson = require('../../../../task/worker/generate_data_json.js');

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

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

exports['Name a dot-data-json file.'] = function (test) {
    var name = generateDataJson._nameDotDataJson('/foo/bar/baz.js');
    test.equal(name, '/foo/bar/.baz-data.json');
    test.done();
};

exports['Generate data json.'] = function (test) {
    var workDir = testResource.resolveWorkFile('work_generate_dot_data');
    testResource.prepareCleanWorkDir(workDir, function () {
        var filename = testResource.resolveWorkFile(workDir, 'foo.js');
        fs.writeFile(filename, 'exports.a="123";', function () {
            generateDataJson({
                src: filename
            }, function (err) {
                test.ifError(err);
                test.done();
            });
        });
    });
};