<commit_before>import os
import shutil
import time
from os.path import join, exists, dirname

import bzt
from bzt.modules import javascript
from bzt.modules.aggregator import ConsolidatingAggregator
from bzt.modules.javascript import WebdriverIOExecutor, NewmanExecutor
from bzt.utils import get_full_path, shell_exec, is_windows
from tests import BUILD_DIR, RESOURCES_DIR, BZTestCase
from tests.mocks import EngineEmul
from tests.modules.selenium import SeleniumTestCase


class TestSeleniumMochaRunner(SeleniumTestCase):
    def test_selenium_prepare_mocha(self):
        self.obj.execution.merge({"scenario": {
            "script": RESOURCES_DIR + "selenium/js-mocha/bd_scenarios.js"
        }})
        self.obj.prepare()

    @staticmethod
    def check_mocha_cmd(runner):
        check_mocha = [runner.node_tool.executable, "-e", "require('mocha'); console.log('mocha is installed');"]
        return check_mocha

    @staticmethod
    def install_mocha_cmd(runner):
        package_name = runner.mocha_tool.package_name
        if runner.mocha_tool.version:
            package_name += "@" + runner.mocha_tool.version
        install_mocha = [runner.npm_tool.executable, "install", package_name, "--prefix", runner.mocha_tool.tools_dir]
        return install_mocha

    def test_mocha_not_found(self):
        self.obj.execution.merge({"scenario": {
            "script": RESOURCES_DIR + "selenium/js-mocha/bd_scenarios.js"
        }})
        self.func_results = "not found"
        sync_run_back = bzt.modules.javascript.sync_run
        bzt.modules.javascript.sync_run = self.func_mock
        try:
            self.obj.prepare()
        finally:
            bzt.modules.javascript.sync_run = sync_run_back

        self.assertEqual(5, len(self.func_args))<commit_msg>Fix js tests<commit_after>import os
import shutil
import time
from os.path import join, exists, dirname

import bzt
from bzt.modules import javascript
from bzt.modules.aggregator import ConsolidatingAggregator
from bzt.modules.javascript import WebdriverIOExecutor, NewmanExecutor
from bzt.utils import get_full_path, shell_exec, is_windows
from tests import BUILD_DIR, RESOURCES_DIR, BZTestCase
from tests.mocks import EngineEmul
from tests.modules.selenium import SeleniumTestCase


class TestSeleniumMochaRunner(SeleniumTestCase):
    def test_selenium_prepare_mocha(self):
        self.obj.execution.merge({"scenario": {
            "script": RESOURCES_DIR + "selenium/js-mocha/bd_scenarios.js"
        }})
        self.obj.prepare()

    @staticmethod
    def check_mocha_cmd(runner):
        check_mocha = [runner.node_tool.executable, "-e", "require('mocha'); console.log('mocha is installed');"]
        return check_mocha

    @staticmethod
    def install_mocha_cmd(runner):
        package_name = runner.mocha_tool.package_name
        if runner.mocha_tool.version:
            package_name += "@" + runner.mocha_tool.version
        install_mocha = [runner.npm_tool.executable, "install", package_name, "--prefix", runner.mocha_tool.tools_dir,
                         '--no-save']
        return install_mocha

    def test_mocha_not_found(self):
        self.obj.execution.merge({"scenario": {
            "script": RESOURCES_DIR + "selenium/js-mocha/bd_scenarios.js"
        }})
        self.func_results = "not found"
        sync_run_back = bzt.modules.javascript.sync_run
        bzt.modules.javascript.sync_run = self.func_mock
        try:
            self.obj.prepare()
        finally:
            bzt.modules.javascript.sync_run = sync_run_back

        self.assertEqual(5, len(self.func_args))
{'fraction_non_alphanumeric': 0.09563525159855435, 'fraction_numerical': 0.0005560189046427579, 'mean_word_length': 3.283333333333333, 'pattern_counts': {'":': 8, '<': 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': '2127779', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1094, 'n_words': 212}