<commit_before>'use strict';
/* global jasmine, spyOn, describe, it, expect */

var proxyquire = require( 'proxyquire' );
var mkdirp = require( 'mkdirp' );
var Emitter = require( 'events' ).EventEmitter;
var Stream = require( 'stream' );

class Needle extends Emitter {
	get( urlPath, options, callback ) {
		if ( urlPath.indexOf( 'https://api' ) !== -1 ) {
			return callback( null, {
				statusCode: 200,
				body: [
					{
						tag_name: '1.0.0',
						assets: [
							{
								name: 'windows',
								browser_download_url: 'https://github.com/deepstream.io-cache-redis-test.zip'
							},
							{
								name: 'linux',
								browser_download_url: 'https://github.com/deepstream.io-cache-redis-test.zip'}
								,
							{
								name: 'mac',
								browser_download_url: 'https://github.com/deepstream.io-cache-redis-test.zip'
							}
						]
					}
				]
			} );
		} else {
			// simulates the archive file
			var stream = new Stream.Readable();
			stream.push( 'chunk' );
			stream.push( null );
			return stream;
		}
	}
}
const needleMock = new Needle();

const noop = function() {};

function createZipMock( cb1, cb2 ) {
	if ( cb1 == null ) { cb1 = noop; }
	if ( cb2 == null ) { cb2 = noop; }
	class ZipMock {
		constructor( filePath ) {
			cb1( filePath );
		}
		extractAllTo( directory, overwrite ) {
			cb2( directory, overwrite );
		}
	}
	return ZipMock;
}

const fsMock = {
	readFileSync: function() {
		return 'config:\n  host: localhost\n  port: 1234';
	},
	createWriteStream: function() {
		var stream = new Stream.Writable();
		stream._write = function( chunk, enc, next ) {
			next();
		};
		return stream;
	}
};

describe( 'CLI installer', function() {

	it( 'downloads a connector and extract it', function( done ) {

		const zipConstructor = jasmine.createSpy( 'callback' );
		const zipExtractor = jasmine.createSpy( 'callback' );
		const zipMock = createZipMock( zipConstructor, zipExtractor );
		const child_processMock = {
			execSync: function() {}
		};
		spyOn( needleMock, 'get' ).and.callThrough();
		spyOn( mkdirp, 'sync' );
		spyOn( fsMock, 'readFileSync' ).and.callThrough();
		spyOn( fsMock, 'createWriteStream' ).and.callThrough();
		spyOn( child_processMock, 'execSync' );
		var installer = proxyquire( '../../bin/installer', {
			needle: {
				get: needleMock.get,
			},
			'adm-zip': zipMock,
			fs: fsMock,
			'child_process': child_processMock
		} );


		var installOptions = {
			type: 'cache',
			name: 'redis',
			version: null,
			dir: null
		};
		process.env.QUITE = 1;
		installer( installOptions, function( error ) {
			expect( error ).toBeUndefined();
			// fetch all releases
			expect( needleMock.get.calls.argsFor( 0 )[0] )
				.toEqual( 'https://api.github.com/repos/deepstreamIO/deepstream.io-cache-redis/releases' );
			// fetch archive
			expect( needleMock.get.calls.argsFor( 1 )[0] )
				.toEqual( 'https://github.com/deepstream.io-cache-redis-test.zip' );
			// save archive
			expect( mkdirp.sync.calls.argsFor( 0 )[0] ).toEqual( 'lib' );
			expect( fsMock.createWriteStream.calls.argsFor( 0 )[0] ).toEqual( 'lib/cache-redis-test-1.0.0.zip' );
			// prepare extract archive
			if ( child_processMock.execSync.calls.count() ) {
				expect( child_processMock.execSync.calls.argsFor( 0 )[0] )
					.toEqual( 'mkdir -p lib/deepstream.io-cache-redis && ' +
					'tar -xzf lib/cache-redis-test-1.0.0.zip -C lib/deepstream.io-cache-redis' );
			} else {
				expect( zipConstructor.calls.argsFor( 0 )[0] ).toEqual( 'lib/cache-redis-test-1.0.0.zip' );
				expect( zipExtractor.calls.argsFor( 0 ) ).toEqual( [ 'lib/deepstream.io-cache-redis', true ] );
			}
			// show example config
			expect( fsMock.readFileSync.calls.argsFor( 0 )[0] ).toEqual( 'lib/deepstream.io-cache-redis/README.md' );
			done();
		} );

	} );

} );<commit_msg>fix tests on windows<commit_after>'use strict';
/* global jasmine, spyOn, describe, it, expect */

const path = require( 'path' );
const pj = path.join;
const proxyquire = require( 'proxyquire' );
const mkdirp = require( 'mkdirp' );
const Emitter = require( 'events' ).EventEmitter;
const Stream = require( 'stream' );

class Needle extends Emitter {
	get( urlPath, options, callback ) {
		if ( urlPath.indexOf( 'https://api' ) !== -1 ) {
			return callback( null, {
				statusCode: 200,
				body: [
					{
						tag_name: '1.0.0',
						assets: [
							{
								name: 'windows',
								browser_download_url: 'https://github.com/deepstream.io-cache-redis-test.zip'
							},
							{
								name: 'linux',
								browser_download_url: 'https://github.com/deepstream.io-cache-redis-test.zip'}
								,
							{
								name: 'mac',
								browser_download_url: 'https://github.com/deepstream.io-cache-redis-test.zip'
							}
						]
					}
				]
			} );
		} else {
			// simulates the archive file
			var stream = new Stream.Readable();
			stream.push( 'chunk' );
			stream.push( null );
			return stream;
		}
	}
}
const needleMock = new Needle();

const noop = function() {};

function createZipMock( cb1, cb2 ) {
	if ( cb1 == null ) { cb1 = noop; }
	if ( cb2 == null ) { cb2 = noop; }
	class ZipMock {
		constructor( filePath ) {
			cb1( filePath );
		}
		extractAllTo( directory, overwrite ) {
			cb2( directory, overwrite );
		}
	}
	return ZipMock;
}

const fsMock = {
	readFileSync: function() {
		return 'config:\n	host: localhost\n	port: 1234';
	},
	createWriteStream: function() {
		var stream = new Stream.Writable();
		stream._write = function( chunk, enc, next ) {
			next();
		};
		return stream;
	}
};

describe( 'CLI installer', function() {

	it( 'downloads a connector and extract it', function( done ) {

		const zipConstructor = jasmine.createSpy( 'callback' );
		const zipExtractor = jasmine.createSpy( 'callback' );
		const zipMock = createZipMock( zipConstructor, zipExtractor );
		const child_processMock = {
			execSync: function() {}
		};
		spyOn( needleMock, 'get' ).and.callThrough();
		spyOn( mkdirp, 'sync' );
		spyOn( fsMock, 'readFileSync' ).and.callThrough();
		spyOn( fsMock, 'createWriteStream' ).and.callThrough();
		spyOn( child_processMock, 'execSync' );
		var installer = proxyquire( '../../bin/installer', {
			needle: {
				get: needleMock.get,
			},
			'adm-zip': zipMock,
			fs: fsMock,
			'child_process': child_processMock
		} );


		var installOptions = {
			type: 'cache',
			name: 'redis',
			version: null,
			dir: null
		};
		process.env.QUITE = 1;

		installer( installOptions, function( error ) {
			expect( error ).toBeUndefined();
			// fetch all releases
			expect( needleMock.get.calls.argsFor( 0 )[0] )
				.toEqual( 'https://api.github.com/repos/deepstreamIO/deepstream.io-cache-redis/releases' );
			// fetch archive
			expect( needleMock.get.calls.argsFor( 1 )[0] )
				.toEqual( 'https://github.com/deepstream.io-cache-redis-test.zip' );
			// save archive
			expect( mkdirp.sync.calls.argsFor( 0 )[0] ).toEqual( 'lib' );
			expect( fsMock.createWriteStream.calls.argsFor( 0 )[0] )
				.toEqual( pj( 'lib', 'cache-redis-test-1.0.0.zip' ) );
			// prepare extract archive
			if ( child_processMock.execSync.calls.count() ) {
				expect( child_processMock.execSync.calls.argsFor( 0 )[0] )
					.toEqual( 'mkdir -p lib/deepstream.io-cache-redis && ' +
					'tar -xzf lib/cache-redis-test-1.0.0.zip -C lib/deepstream.io-cache-redis' );
			} else {
				expect( zipConstructor.calls.argsFor( 0 )[0] ).toEqual( pj( 'lib', 'cache-redis-test-1.0.0.zip' ) );
				expect( zipExtractor.calls.argsFor( 0 ) ).toEqual( [ pj( 'lib', 'deepstream.io-cache-redis' ), true ] );
			}
			// show example config
			expect( fsMock.readFileSync.calls.argsFor( 0 )[0] ).toEqual( 'lib/deepstream.io-cache-redis/README.md' );
			done();
		} );

	} );

} );
{'fraction_non_alphanumeric': 0.16480228928199792, 'fraction_numerical': 0.011446409989594173, 'mean_word_length': 2.994285714285714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5364137', 'n_tokens_mistral': 3275, 'n_tokens_neox': 2746, 'n_words': 584}