var files,
	async = require( "async" ),
	expect = require( "chai" ).expect,
	fs = require( "fs" ),
	amdBuilder = require( "../index.js" );

files = {
	"foo.js": fs.readFileSync( __dirname + "/fixtures/basic/foo.js" ),
	"bar.js": fs.readFileSync( __dirname + "/fixtures/basic/bar.js" )
};

describe( "The JS file of the include property", function() {
	var js;

	before(function( done ) {
		amdBuilder( files, { include: [ "bar" ] }, function( error, _js ) {
			js = _js;
			done( error );
		});
	});

	it( "must be included", function() {
		expect( js ).to.equal( "define(\"bar\",[],function(){}),define(\"output\",function(){});" );
	});

});

describe( "The JS dependencies", function() {
	var js;

	before(function( done ) {
		amdBuilder( files, { include: [ "foo" ] }, function( error, _js ) {
			js = _js;
			done( error );
		});
	});

	it( "must be included", function() {
		expect( js ).to.equal( "define(\"bar\",[],function(){}),define([\"./bar\"]),define(\"output\",function(){});" );
	});

});

describe( "Using appDir", function() {
	var js, files;

	files = {
		"fixtures/foo.js": fs.readFileSync( __dirname + "/fixtures/basic/foo.js" ),
		"fixtures/bar.js": fs.readFileSync( __dirname + "/fixtures/basic/bar.js" )
	};

	before(function( done ) {
		amdBuilder( files, { appDir: "fixtures", include: [ "foo" ] }, function( error, _js ) {
			js = _js;
			done( error );
		});
	});

	it( "should work just fine", function() {
		expect( js ).to.equal( "define(\"bar\",[],function(){}),define([\"./bar\"]),define(\"output\",function(){});" );
	});

});

describe( "Serial runs", function() {
	var barJs, fooJs;

	before(function( done ) {
		async.series([
			function( callback ) {
				amdBuilder( files, { include: [ "bar" ] }, callback );
			},
			function( callback ) {
				amdBuilder( files, { include: [ "foo" ] }, callback );
			}
		], function( error, result ) {
			if ( error ) {
				return done( error );
			}
			barJs = result[ 0 ][ 0 ];
			fooJs = result[ 1 ][ 0 ];
			done();
		});
	});

	it( "should work just fine", function() {
		expect( barJs ).to.equal( "define(\"bar\",[],function(){}),define(\"output\",function(){});" );
		expect( fooJs ).to.equal( "define(\"bar\",[],function(){}),define([\"./bar\"]),define(\"output\",function(){});" );
	});

});

describe( "Concurrent runs", function() {
	var barJs, fooJs;

	before(function( done ) {
		async.parallel([
			function( callback ) {
				amdBuilder( files, { include: [ "bar" ] }, callback );
			},
			function( callback ) {
				amdBuilder( files, { include: [ "foo" ] }, callback );
			}
		], function( error, result ) {
			if ( error ) {
				return done( error );
			}
			barJs = result[ 0 ][ 0 ];
			fooJs = result[ 1 ][ 0 ];
			done();
		});
	});

	it( "should work just fine", function() {
		expect( barJs ).to.equal( "define(\"bar\",[],function(){}),define(\"output\",function(){});" );
		expect( fooJs ).to.equal( "define(\"bar\",[],function(){}),define([\"./bar\"]),define(\"output\",function(){});" );
	});

});


@@ -2972,28 +2972,637 @@
 nction()%7B%7D);%22 );%0A%09%7D);%0A%0A%7D);%0A%0A
+describe( %22onBuildWrite property%22, function() %7B%0A%09var js;%0A%0A%09before(function( done ) %7B%0A%09%09amdBuilder( files, %7B%0A%09%09%09include: %5B %22foo%22 %5D,%0A%09%09%09optimize: %22none%22,%0A%09%09%09onBuildWrite: function( id, path, contents ) %7B%0A%09%09%09%09return %22/* banner for %22 + id + %22 */%5Cn%22 + contents;%0A%09%09%09%7D%0A%09%09%7D, function( error, result ) %7B%0A%09%09%09if ( error ) %7B%0A%09%09%09%09return done( error );%0A%09%09%09%7D%0A%09%09%09js = result;%0A%09%09%09done();%0A%09%09%7D);%0A%09%7D);%0A%0A%09it( %22should work just fine%22, function() %7B%0A%09%09expect( js ).to.equal( %22/* banner for bar */%5Cndefine('bar',%5B%5D,function() %7B%7D);%5Cn%5Cn/* banner for foo */%5Cndefine(%5B %5C%22./bar%5C%22 %5D);%5Cn%5Cn%5Cndefine(%5C%22output%5C%22, function()%7B%7D);%5Cn%22 );%0A%09%7D);%0A%7D);%0A%0A

Add onBuildWrite property test