'use strict';

const join = require('path').join;
const test = require('tape').test;
const Fly = require('fly');

const dir = join(__dirname, 'fixtures');
const tmp = join(__dirname, 'tmp');

test('fly-uglify', t => {
	t.plan(4);

	const fly = new Fly({
		plugins: [{
			func: require('../')
		}],
		tasks: {
			a: function * () {
				const src = `${dir}/**/*.js`;
				t.ok('uglify' in fly, 'attach `uglify()` plugin to fly');

				yield this.source(src).uglify().target(tmp);
				const str1 = yield this.$.read(`${tmp}/a.js`, 'utf8');
				t.equal(str1, `console.log("this is a");`, 'apply `uglify-js` to content');
				const arr1 = yield this.$.expand(`${tmp}/**/*.js`);
				t.equal(arr1.length, 2, 'keep all files');

				/* eslint camelcase:0 */
				yield this.source(src).uglify({compress: {drop_console: 1}}).target(tmp);
				const str2 = yield this.$.read(`${tmp}/a.js`, 'utf8');
				t.equal(str2, '', 'accept custom config (`compress` options)');

				yield this.clear(tmp);
			}
		}
	});

	fly.start('a');
});

@@ -14,20 +14,22 @@
 %0A%0Aconst 
+%7B
 join
+%7D
  = requi
@@ -42,13 +42,8 @@
 th')
-.join
 ;%0Aco
@@ -72,13 +72,8 @@
 pe')
-.test
 ;%0Aco
@@ -255,19 +255,12 @@
 s: %5B
-%7B
 %0A%09%09%09
-func: 
 requ
@@ -269,20 +269,44 @@
 e('../')
+,%0A%09%09%09require('fly-clear')
 %0A%09%09
-%7D
 %5D,%0A%09%09tas
@@ -318,23 +318,15 @@
 %0A%09%09%09
-a: function * (
+* foo(f
 ) %7B%0A
@@ -383,16 +383,24 @@
 ' in fly
+.plugins
 , 'attac
@@ -432,36 +432,33 @@
 y');%0A%0A%09%09%09%09yield 
-this
+f
 .source(src).ugl
@@ -491,36 +491,33 @@
 st str1 = yield 
-this
+f
 .$.read(%60$%7Btmp%7D/
@@ -635,20 +635,17 @@
 = yield 
-this
+f
 .$.expan
@@ -752,20 +752,17 @@
 %09%09yield 
-this
+f
 .source(
@@ -840,20 +840,17 @@
 = yield 
-this
+f
 .$.read(
@@ -952,20 +952,17 @@
 %09%09yield 
-this
+f
 .clear(t
@@ -993,17 +993,19 @@
 .start('
-a
+foo
 ');%0A%7D);%0A

update tests