"use babel";

const env = jasmine.getEnv();

let includeSpecsWithoutTags = true;
env.includeSpecsWithoutTags = function (permit) {
	includeSpecsWithoutTags = permit;
};

let includedTags = [];
env.setIncludedTags = function (tags) {
	if (!Array.isArray(tags)) {
		tags = [tags];
	}
	includedTags = tags;
};

function findTags(spec) {
	const words = spec.getFullName().split(" ");
	let tags = words.filter(word => word.startsWith("#")).map(word => word.substring(1));
	if (!tags) { tags = []; }

	return tags;
};

const originalFilter = (env.specFilter ? env.specFilter : _ => true);
env.specFilter = function (spec) {
	if (!originalFilter(spec)) { return false; }

	const tags = findTags(spec);
	if (includeSpecsWithoutTags && (tags.length === 0)) { return true; }

	return tags.some(tag => includedTags.includes(tag));
};

@@ -230,16 +230,50 @@
 ) %7B%0A%09if 
+(!tags) %7B%0A%09%09tags = %5B%5D;%0A%09%7D else if 
 (!Array.
@@ -307,14 +307,26 @@
 tags
+.toString()
 %5D;%0A%09%7D%0A
+%0A
 %09inc

set included tags to none on falsy input