<commit_before>var Config = require('../lib/config.js')
var test = require('./testutils.js')
var EventEmitter = require('events').EventEmitter
var expect = test.expect
var spy = require('sinon').spy
var stub = require('sinon').stub
var browser_launcher = require('../lib/browser_launcher')

describe('Config', function(){
	var config, appMode, progOptions
	beforeEach(function(){
		appMode = 'dev'
		progOptions = {
			file: __dirname + '/testem.yml',
			timeout: null
		}
		config = new Config(appMode, progOptions)
	})
	it('can create', function(){
		expect(config.progOptions).to.equal(progOptions)
	})
	it('gives progOptions properties when got', function(){
		expect(config.get('file')).to.equal(progOptions.file)
	})

	describe('read yaml config file', function(){
		beforeEach(function(done){
			config.read(done)
		})
		it('gets properties from config file', function(){
			expect(config.get('framework')).to.equal('jasmine')
			expect(String(config.get('src_files'))).to.equal('implementation.js,tests.js')
		})
		it('falls back to config file value when progOptions is null', function(){
			expect(config.get('timeout')).to.equal(2)
		})
	})
	
	describe('read json config file', function(){
		var config
		beforeEach(function(done){
			var progOptions = {
				file: __dirname + '/testem.json'
			}
			config = new Config('dev', progOptions)
			config.read(done)
		})
		it('gets properties from config file', function(){
			expect(config.get('framework')).to.equal('mocha')
			expect(String(config.get('src_files'))).to.equal('impl.js,tests.js')
		})
	})

	it('give precendence to json config file', function(done){
		var config = new Config('dev', {})
		config.read(function(){
			expect(config.get('framework')).to.equal('mocha')
			done()
		})
	})

	it('returns whether isCwdMode (read js files from current dir)', function(){
		test.stub(config, 'get', function(key){
			return null
		})
		expect(config.isCwdMode()).to.be.ok
		config.get.restore()
		test.stub(config, 'get', function(key){
			if (key === 'src_files') return ['implementation.js']
			return null
		})
		expect(config.isCwdMode()).to.not.be.ok
		config.get.restore()
		test.stub(config, 'get', function(key){
			if (key === 'test_page') return 'tests.html'
			return null
		})
		expect(config.isCwdMode()).to.not.be.ok
		config.get.restore()
	})

	it('should getLaunchers should call getAvailable browsers', function(){
		stub(config, 'getWantedLaunchers', function(n){return n})
		var getAvailableBrowsers = browser_launcher.getAvailableBrowsers
		var availableBrowsers = [
			{name: 'Chrome', exe: 'chrome.exe'}
			, {name: 'Firefox'}
		]
		browser_launcher.getAvailableBrowsers = function(cb){
			cb(availableBrowsers)
		}
		var cb = spy()
		config.getLaunchers({}, cb)
		expect(cb.called).to.be.ok
		var launchers = cb.args[0][0]
		expect(launchers.chrome.name).to.equal('Chrome')
		expect(launchers.chrome.settings.exe).to.equal('chrome.exe')
		expect(launchers.firefox.name).to.equal('Firefox')
		browser_launcher.getAvailableBrowsers = getAvailableBrowsers
	})

	it('should install custom launchers', function(){
		stub(config, 'getWantedLaunchers', function(n){return n})
		var launchers = {
			Node: {
				command: 'node tests.js'
			}
		}
		config.config = {
			launchers: launchers
		}
		browser_launcher.getAvailableBrowsers = function(cb){
			cb([])
		}
		var cb = spy()
		config.getLaunchers({}, cb)
		var launchers = cb.args[0][0]
		expect(launchers.node.name).to.equal('Node')
		expect(launchers.node.settings.command).to.equal('node tests.js')
	})

	it('getWantedLaunchers uses getWantedLauncherNames', function(){
		stub(config, 'getWantedLauncherNames').returns(['Chrome', 'Firefox'])
		var results = config.getWantedLaunchers({
			chrome: { name: 'Chrome' }
			, firefox: { name: 'Firefox' }
		})
		expect(results).to.deep.equal([{ name: 'Chrome' }, { name: 'Firefox' }])
	})

	describe('getWantedLauncherNames', function(){
		it('adds "launch" param', function(){
			config.progOptions.launch = 'Chrome,Firefox'
			expect(config.getWantedLauncherNames()).to.deep.equal(['Chrome', 'Firefox'])
			config.progOptions.launch = 'IE'
			expect(config.getWantedLauncherNames()).to.deep.equal(['IE'])
		})
		it('adds "launch_in_dev" config', function(){
			config.config = {launch_in_dev: ['Chrome', 'Firefox']}
			expect(config.getWantedLauncherNames()).to.deep.equal(['Chrome', 'Firefox'])
		})
		it('adds "launch_in_ci" config', function(){
			config.appMode = 'ci'
			config.config = {launch_in_ci: ['Chrome', 'Firefox']}
			expect(config.getWantedLauncherNames()).to.deep.equal(['Chrome', 'Firefox'])
		})
		it('removes skip param', function(){
			config.progOptions.launch = 'Chrome,Firefox'
			config.progOptions.skip = 'Chrome'
			expect(config.getWantedLauncherNames()).to.deep.equal(['Firefox'])
		})
	})

	describe('getSrcFiles', function(){
		it('by defaults list all .js files', function(done){
			config.getSrcFiles(function(err, files){
				expect(files.length).be.above(5) // because this dir should have a bunch of .js files
				done()
			})
		})
		it('gets src files', function(done){
			config.set('src_files', ['config_tests.js'])
			config.getSrcFiles(function(err, files){
				expect(files).to.deep.equal(['config_tests.js'])
				done()
			})
		})
		it('excludes usig src_files_ignore', function(done){
			config.set('src_files', ['integration/*'])
			config.set('src_files_ignore', ['**/*.sh'])
			config.getSrcFiles(function(err, files){
				expect(files).to.deep.equal(['integration/browser_tests.bat'])
				done()
			})
		})
		it('can also use space delimited string', function(done){
			config.set('src_files', 'integration/*')
			config.set('src_files_ignore', '**/*.sh')
			config.getSrcFiles(function(err, files){
				expect(files).to.deep.equal(['integration/browser_tests.bat'])
				done()
			})
		})
	})

	describe('getServeFiles', function(){
		it('by default just gets src files', function(done){
			config.set('src_files', 'integration/*')
			config.set('src_files_ignore', '**/*.sh')
			config.getServeFiles(function(err, files){
				expect(files).to.deep.equal(['integration/browser_tests.bat'])
				done()
			})
		})
		it('globs serve_files if specified', function(done){
			config.set('serve_files', 'integration/*')
			config.set('serve_files_ignore', '**/*.sh')
			config.getServeFiles(function(err, files){
				expect(files).to.deep.equal(['integration/browser_tests.bat'])
				done()
			})
		})
	})
})
<commit_msg>Added breaking test for files globbed out of order.<commit_after>var Config = require('../lib/config.js')
var test = require('./testutils.js')
var EventEmitter = require('events').EventEmitter
var expect = test.expect
var spy = require('sinon').spy
var stub = require('sinon').stub
var browser_launcher = require('../lib/browser_launcher')

describe('Config', function(){
	var config, appMode, progOptions
	beforeEach(function(){
		appMode = 'dev'
		progOptions = {
			file: __dirname + '/testem.yml',
			timeout: null
		}
		config = new Config(appMode, progOptions)
	})
	it('can create', function(){
		expect(config.progOptions).to.equal(progOptions)
	})
	it('gives progOptions properties when got', function(){
		expect(config.get('file')).to.equal(progOptions.file)
	})

	describe('read yaml config file', function(){
		beforeEach(function(done){
			config.read(done)
		})
		it('gets properties from config file', function(){
			expect(config.get('framework')).to.equal('jasmine')
			expect(String(config.get('src_files'))).to.equal('implementation.js,tests.js')
		})
		it('falls back to config file value when progOptions is null', function(){
			expect(config.get('timeout')).to.equal(2)
		})
	})
	
	describe('read json config file', function(){
		var config
		beforeEach(function(done){
			var progOptions = {
				file: __dirname + '/testem.json'
			}
			config = new Config('dev', progOptions)
			config.read(done)
		})
		it('gets properties from config file', function(){
			expect(config.get('framework')).to.equal('mocha')
			expect(String(config.get('src_files'))).to.equal('impl.js,tests.js')
		})
	})

	it('give precendence to json config file', function(done){
		var config = new Config('dev', {})
		config.read(function(){
			expect(config.get('framework')).to.equal('mocha')
			done()
		})
	})

	it('returns whether isCwdMode (read js files from current dir)', function(){
		test.stub(config, 'get', function(key){
			return null
		})
		expect(config.isCwdMode()).to.be.ok
		config.get.restore()
		test.stub(config, 'get', function(key){
			if (key === 'src_files') return ['implementation.js']
			return null
		})
		expect(config.isCwdMode()).to.not.be.ok
		config.get.restore()
		test.stub(config, 'get', function(key){
			if (key === 'test_page') return 'tests.html'
			return null
		})
		expect(config.isCwdMode()).to.not.be.ok
		config.get.restore()
	})

	it('should getLaunchers should call getAvailable browsers', function(){
		stub(config, 'getWantedLaunchers', function(n){return n})
		var getAvailableBrowsers = browser_launcher.getAvailableBrowsers
		var availableBrowsers = [
			{name: 'Chrome', exe: 'chrome.exe'}
			, {name: 'Firefox'}
		]
		browser_launcher.getAvailableBrowsers = function(cb){
			cb(availableBrowsers)
		}
		var cb = spy()
		config.getLaunchers({}, cb)
		expect(cb.called).to.be.ok
		var launchers = cb.args[0][0]
		expect(launchers.chrome.name).to.equal('Chrome')
		expect(launchers.chrome.settings.exe).to.equal('chrome.exe')
		expect(launchers.firefox.name).to.equal('Firefox')
		browser_launcher.getAvailableBrowsers = getAvailableBrowsers
	})

	it('should install custom launchers', function(){
		stub(config, 'getWantedLaunchers', function(n){return n})
		var launchers = {
			Node: {
				command: 'node tests.js'
			}
		}
		config.config = {
			launchers: launchers
		}
		browser_launcher.getAvailableBrowsers = function(cb){
			cb([])
		}
		var cb = spy()
		config.getLaunchers({}, cb)
		var launchers = cb.args[0][0]
		expect(launchers.node.name).to.equal('Node')
		expect(launchers.node.settings.command).to.equal('node tests.js')
	})

	it('getWantedLaunchers uses getWantedLauncherNames', function(){
		stub(config, 'getWantedLauncherNames').returns(['Chrome', 'Firefox'])
		var results = config.getWantedLaunchers({
			chrome: { name: 'Chrome' }
			, firefox: { name: 'Firefox' }
		})
		expect(results).to.deep.equal([{ name: 'Chrome' }, { name: 'Firefox' }])
	})

	describe('getWantedLauncherNames', function(){
		it('adds "launch" param', function(){
			config.progOptions.launch = 'Chrome,Firefox'
			expect(config.getWantedLauncherNames()).to.deep.equal(['Chrome', 'Firefox'])
			config.progOptions.launch = 'IE'
			expect(config.getWantedLauncherNames()).to.deep.equal(['IE'])
		})
		it('adds "launch_in_dev" config', function(){
			config.config = {launch_in_dev: ['Chrome', 'Firefox']}
			expect(config.getWantedLauncherNames()).to.deep.equal(['Chrome', 'Firefox'])
		})
		it('adds "launch_in_ci" config', function(){
			config.appMode = 'ci'
			config.config = {launch_in_ci: ['Chrome', 'Firefox']}
			expect(config.getWantedLauncherNames()).to.deep.equal(['Chrome', 'Firefox'])
		})
		it('removes skip param', function(){
			config.progOptions.launch = 'Chrome,Firefox'
			config.progOptions.skip = 'Chrome'
			expect(config.getWantedLauncherNames()).to.deep.equal(['Firefox'])
		})
	})

	describe('getSrcFiles', function(){
		it('by defaults list all .js files', function(done){
			config.getSrcFiles(function(err, files){
				expect(files.length).be.above(5) // because this dir should have a bunch of .js files
				done()
			})
		})
		it('gets src files', function(done){
			config.set('src_files', ['config_tests.js'])
			config.getSrcFiles(function(err, files){
				expect(files).to.deep.equal(['config_tests.js'])
				done()
			})
		})
		it('excludes usig src_files_ignore', function(done){
			config.set('src_files', ['integration/*'])
			config.set('src_files_ignore', ['**/*.sh'])
			config.getSrcFiles(function(err, files){
				expect(files).to.deep.equal(['integration/browser_tests.bat'])
				done()
			})
		})
		it('can also use space delimited string', function(done){
			config.set('src_files', 'integration/browser_tests.bat integration/browser_tests.sh')
			config.getSrcFiles(function(err, files){
				expect(files).to.deep.equal(['integration/browser_tests.bat', 'integration/browser_tests.sh'])
				done()
			})
		})
		it('respects order', function(done){
			config.set('src_files', [
				'integration/browser_tests.bat',
				'filewatcher_tests.js'
			])
			config.getSrcFiles(function(err, files){
				expect(files).to.deep.equal([
					'integration/browser_tests.bat',
					'filewatcher_tests.js'
				])
				done()
			})
		})
	})

	describe('getServeFiles', function(){
		it('by default just gets src files', function(done){
			config.set('src_files', 'integration/*')
			config.set('src_files_ignore', '**/*.sh')
			config.getServeFiles(function(err, files){
				expect(files).to.deep.equal(['integration/browser_tests.bat'])
				done()
			})
		})
		it('globs serve_files if specified', function(done){
			config.set('serve_files', 'integration/*')
			config.set('serve_files_ignore', '**/*.sh')
			config.getServeFiles(function(err, files){
				expect(files).to.deep.equal(['integration/browser_tests.bat'])
				done()
			})
		})
	})
})

{'fraction_non_alphanumeric': 0.17777275807544612, 'fraction_numerical': 0.0009035464196973119, 'mean_word_length': 4.625582380347311, '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': '7111560', 'n_tokens_mistral': 5088, 'n_tokens_neox': 4477, 'n_words': 790}