<commit_before>from clickerft.jsplayer import JsPlayer


class JSuite(JsPlayer):

    def test_run_javascript(self):
        js = """
document.getElementById("r1").click()
"""
        self.run_javascript(js)
        assert int(self.tr1.text) > 0

if __name__ == '__main__':
    JSuite()<commit_msg>test running javascript using `document` to store state<commit_after>from clickerft.jsplayer import JsPlayer
from time import sleep


class JSuite(JsPlayer):

    def test_run_javascript(self):
        js = """
document.getElementById("r1").click()
"""
        self.run_javascript(js)
        assert int(self.tr1.text) > 0

    def test_js_with_state(self):
        js = """
cheats = document.cheats || {};
document.cheats = cheats;
if (! cheats.runR1 ) {
  cheats.runR1 = 0;
}

if (cheats.runR1 < 5) {
  document.getElementById("r1").click();
  cheats.runR1 +=  1;
  return;
} else {
  console.log('skipping r1');
}
"""
        self.run_javascript(js)

        # allow time for the cheat codes to run
        sleep(3)
        assert int(self.tr1.text) == 5

if __name__ == '__main__':
    JSuite()
{'fraction_non_alphanumeric': 0.13777372262773724, 'fraction_numerical': 0.016423357664233577, 'mean_word_length': 3.1553030303030303, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, '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': '2104597', 'n_tokens_mistral': 385, 'n_tokens_neox': 370, 'n_words': 80}