<commit_before>/* jshint node: true */
/* jshint expr:true */
/* global describe, it, afterEach, beforeEach */

'use strict';

var expect  = require('chai').expect,
    rimraf  = require('rimraf'),
    gutil   = require('gulp-util'),
    symlink = require('./'),
    path    = require('path'),
    fs      = require('fs');

symlink._setDebug(true);

/**
 * Expect that we created a symlink which contains the desired link text;
 * i.e. whether it is relative or absolute
 * @param  {String}   fpath      Path to the symlink
 * @param  {Function}   pathMethod A method passed in to compare the cwd to the linked path
 * @param  {Function} callback   Call the callback when we're done
 */
var assertion = function(fpath, pathMethod, callback) {
    fs.lstat(fpath, function(err, stats) {
        expect(stats.isSymbolicLink()).to.be.true;
        fs.readlink(fpath, function(err, link) {
            expect(link).to.equal(pathMethod(process.cwd(), link));
            callback && callback();
        });
    });
};

describe('gulp-symlink', function() {
    function test(testDir, method, pathMethod) {
        var testFile = 'index.js';
        var testPath = path.join(testDir, testFile);

        beforeEach(function() {
            this.gutilFile = new gutil.File({
                path: path.join(process.cwd(), testFile)
            });
        });

        it('should throw if no directory was specified', function(cb) {
            var stream = method();
            try {
                stream.write(this.gutilFile);
            } catch (e) {
                expect(e.toString()).to.contain.string('An output destination is required.');
                cb();
            }
        });
        it('should create symlinks', function(cb) {
            var stream = method(testDir);

            stream.on('data', function() {
                assertion(testPath, pathMethod, cb);
            });<commit_msg>Remove try/catch test, replace with emit check.<commit_after>/* jshint node: true */
/* jshint expr:true */
/* global describe, it, afterEach, beforeEach */

'use strict';

var expect  = require('chai').expect,
    rimraf  = require('rimraf'),
    gutil   = require('gulp-util'),
    symlink = require('./'),
    path    = require('path'),
    fs      = require('fs');

symlink._setDebug(true);

/**
 * Expect that we created a symlink which contains the desired link text;
 * i.e. whether it is relative or absolute
 * @param  {String}   fpath      Path to the symlink
 * @param  {Function}   pathMethod A method passed in to compare the cwd to the linked path
 * @param  {Function} callback   Call the callback when we're done
 */
var assertion = function(fpath, pathMethod, callback) {
    fs.lstat(fpath, function(err, stats) {
        expect(stats.isSymbolicLink()).to.be.true;
        fs.readlink(fpath, function(err, link) {
            expect(link).to.equal(pathMethod(process.cwd(), link));
            callback && callback();
        });
    });
};

describe('gulp-symlink', function() {
    function test(testDir, method, pathMethod) {
        var testFile = 'index.js';
        var testPath = path.join(testDir, testFile);

        beforeEach(function() {
            this.gutilFile = new gutil.File({
                path: path.join(process.cwd(), testFile)
            });
        });

        it('should emit an error if no directory was specified', function() {
            var stream = method();

            stream.on('error', function(err) {
                expect(err instanceof gutil.PluginError).to.be.true;
                expect(err.toString()).to.contain.string('An output destination is required.');
            });

            stream.write(this.gutilFile);
        });
        it('should create symlinks', function(cb) {
            var stream = method(testDir);

            stream.on('data', function() {
                assertion(testPath, pathMethod, cb);
            });
{'fraction_non_alphanumeric': 0.13643331630045988, 'fraction_numerical': 0.0, 'mean_word_length': 2.298230834035383, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6654882', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1106, 'n_words': 301}