<commit_before>package io.silksmith.js.closure.task

import com.sun.nio.file.SensitivityWatchEventModifier
import io.silksmith.SourceLookupService
import io.silksmith.development.server.WorkspaceServer
import io.silksmith.source.WebSourceSet
import org.eclipse.jetty.server.Handler
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.artifacts.Configuration
import org.gradle.api.tasks.TaskAction
import org.gradle.logging.StyledTextOutput
import org.gradle.logging.StyledTextOutputFactory
import org.openqa.selenium.JavascriptExecutor
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeDriverService
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.remote.DesiredCapabilities
import org.openqa.selenium.remote.RemoteWebDriver
import org.openqa.selenium.support.ui.ExpectedCondition
import org.openqa.selenium.support.ui.WebDriverWait

import java.nio.file.*

class TestJSTask extends DefaultTask {

    def jsExecution = "return window.silksmith.results;"

    def symbols = [
        "ok": '✓',
        "err": '✖',
        "dot": '․'
    ];

    SourceLookupService sourceLookupService
    WebSourceSet testSourceSet

    @Lazy
    WorkspaceServer server = {
        Configuration configuration = project.configurations[testSourceSet.configurationName]
        [
                project            : project,
                sourceSet          : testSourceSet,
                configuration      : configuration,

                sourceLookupService: sourceLookupService
        ]
    }()

    def handler(Handler handler) {
        def s = server
        server.handler(handler)
    }

    @TaskAction
    def test() {

        def drivers = []
        def ok = false

        try {
            boolean watch = project.hasProperty('watch')
            boolean firefox = project.hasProperty('firefox')
            boolean chrome = project.hasProperty('chrome')
            boolean sauce = project.hasProperty('sauce')


            server.start()

            if (!firefox && !chrome && !sauce) {
                firefox = true;
            }

            if (sauce) {
                String sauseUsername = project.hasProperty('sauceUsername') ? project.property("sauceUsername") : System.getenv('SAUCE_USERNAME')
                String sauseAccessKey = project.hasProperty('sauceAccessKey') ? project.property("sauceAccessKey") : System.getenv('SAUCE_ACCESS_KEY')

                def capabilities = DesiredCapabilities.chrome();
                capabilities.setCapability("platform", "OS X 10.10");
                capabilities.setCapability("version", "40.0");
                drivers << new RemoteWebDriver(new URL("http://$sauseUsername:$sauseAccessKey@ondemand.saucelabs.com:80/wd/hub"), capabilities)
            }
            if (firefox) {
                drivers << new FirefoxDriver()
            }
            if (chrome) {
                WebDriver chromeDriver
                String chromeDriverUrl = project.hasProperty('chromeDriverUrl') ? project.property("chromeDriverUrl") : null
                String chromeDriverExe = project.hasProperty('chromeDriverExe') ? project.property("chromeDriverExe") : null
                String chromeBin = project.hasProperty('chromeBin') ? project.property("chromeBin") : null

                ChromeOptions options = new ChromeOptions()
                if (chromeBin != null) {
                    def chromeBinFile = new File(chromeBin)
                    if (chromeBinFile.exists()) {
                        options.setBinary(chromeBinFile)
                    } else {
                        logger.warn("Chrome binary not found at $chromeBinFile. Using default location")
                    }
                }

                if (chromeDriverUrl) {
                    // use existing chrome driver server
                    def capabilities = DesiredCapabilities.chrome()<commit_msg>Add SauceLabs tunnel identifier within travis build<commit_after>package io.silksmith.js.closure.task

import com.sun.nio.file.SensitivityWatchEventModifier
import io.silksmith.SourceLookupService
import io.silksmith.development.server.WorkspaceServer
import io.silksmith.source.WebSourceSet
import org.eclipse.jetty.server.Handler
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.artifacts.Configuration
import org.gradle.api.tasks.TaskAction
import org.gradle.logging.StyledTextOutput
import org.gradle.logging.StyledTextOutputFactory
import org.openqa.selenium.JavascriptExecutor
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeDriverService
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.remote.DesiredCapabilities
import org.openqa.selenium.remote.RemoteWebDriver
import org.openqa.selenium.support.ui.ExpectedCondition
import org.openqa.selenium.support.ui.WebDriverWait

import java.nio.file.*

class TestJSTask extends DefaultTask {

    def jsExecution = "return window.silksmith.results;"

    def symbols = [
        "ok": '✓',
        "err": '✖',
        "dot": '․'
    ];

    SourceLookupService sourceLookupService
    WebSourceSet testSourceSet

    @Lazy
    WorkspaceServer server = {
        Configuration configuration = project.configurations[testSourceSet.configurationName]
        [
                project            : project,
                sourceSet          : testSourceSet,
                configuration      : configuration,

                sourceLookupService: sourceLookupService
        ]
    }()

    def handler(Handler handler) {
        def s = server
        server.handler(handler)
    }

    @TaskAction
    def test() {

        def drivers = []
        def ok = false

        try {
            boolean watch = project.hasProperty('watch')
            boolean firefox = project.hasProperty('firefox')
            boolean chrome = project.hasProperty('chrome')
            boolean sauce = project.hasProperty('sauce')


            server.start()

            if (!firefox && !chrome && !sauce) {
                firefox = true;
            }

            if (sauce) {
                String sauceUsername = project.hasProperty('sauceUsername') ? project.property("sauceUsername") : System.getenv('SAUCE_USERNAME')
                String sauceAccessKey = project.hasProperty('sauceAccessKey') ? project.property("sauceAccessKey") : System.getenv('SAUCE_ACCESS_KEY')
                String sauceTunnelIdentifier = System.getenv('TRAVIS_JOB_NUMBER')

                def capabilities = DesiredCapabilities.chrome();
                capabilities.setCapability("platform", "OS X 10.10");
                capabilities.setCapability("version", "40.0");
                if (sauceTunnelIdentifier) {
                    capabilities.setCapability("tunnel-identifier", sauceTunnelIdentifier);
                }
                drivers << new RemoteWebDriver(new URL("http://$sauceUsername:$sauceAccessKey@localhost:4445/wd/hub"), capabilities)
            }
            if (firefox) {
                drivers << new FirefoxDriver()
            }
            if (chrome) {
                WebDriver chromeDriver
                String chromeDriverUrl = project.hasProperty('chromeDriverUrl') ? project.property("chromeDriverUrl") : null
                String chromeDriverExe = project.hasProperty('chromeDriverExe') ? project.property("chromeDriverExe") : null
                String chromeBin = project.hasProperty('chromeBin') ? project.property("chromeBin") : null

                ChromeOptions options = new ChromeOptions()
                if (chromeBin != null) {
                    def chromeBinFile = new File(chromeBin)
                    if (chromeBinFile.exists()) {
                        options.setBinary(chromeBinFile)
                    } else {
                        logger.warn("Chrome binary not found at $chromeBinFile. Using default location")
                    }
                }

                if (chromeDriverUrl) {
                    // use existing chrome driver server
                    def capabilities = DesiredCapabilities.chrome()
{'fraction_non_alphanumeric': 0.09099616858237548, 'fraction_numerical': 0.0023946360153256703, 'mean_word_length': 2.3600160901045855, 'pattern_counts': {'":': 6, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '6742676', 'n_tokens_mistral': 2267, 'n_tokens_neox': 2105, 'n_words': 410}