<commit_before>(ns clj-chrome-devtools.automation-test
  (:require [clj-chrome-devtools.automation :as a]
            [clj-chrome-devtools.automation.fixture :refer [create-chrome-fixture]]
            [clojure.spec.test.alpha :as stest]
            [clojure.test :as t :refer [deftest is testing]]))

(stest/instrument)

(defonce chrome-fixture (create-chrome-fixture))
(t/use-fixtures :each chrome-fixture)

(deftest evaluate
  (testing "a call that takes longer than the default timeout should throw an exception"
    (let [[prior-default-timeout _] (reset-vals! a/default-timeout-ms 100)]
      (is (thrown-with-msg?
           RuntimeException
           #"^Timeout!.+"
           (a/evaluate "Array(1024 ** 3).fill().map(Math.random).length")))
      (reset! a/default-timeout-ms prior-default-timeout)))
  (testing "a call that takes longer than the supplied timeout should throw an exception"
    (is (thrown-with-msg?
         RuntimeException
         #"^Timeout!.+"
         (a/evaluate @a/current-automation
                    "Array(1024 ** 3).fill().map(Math.random).length"
                    100)))))
<commit_msg>Add test that prints example.com site to PDF<commit_after>(ns clj-chrome-devtools.automation-test
  (:require [clj-chrome-devtools.automation :as a]
            [clj-chrome-devtools.automation.fixture :refer [create-chrome-fixture]]
            [clojure.spec.test.alpha :as stest]
            [clojure.test :as t :refer [deftest is testing]]
            [clojure.string :as str]))

(stest/instrument)

(defonce chrome-fixture (create-chrome-fixture))
(t/use-fixtures :each chrome-fixture)

(deftest evaluate
  (testing "a call that takes longer than the default timeout should throw an exception"
    (let [[prior-default-timeout _] (reset-vals! a/default-timeout-ms 100)]
      (is (thrown-with-msg?
           RuntimeException
           #"^Timeout!.+"
           (a/evaluate "Array(1024 ** 3).fill().map(Math.random).length")))
      (reset! a/default-timeout-ms prior-default-timeout)))
  (testing "a call that takes longer than the supplied timeout should throw an exception"
    (is (thrown-with-msg?
         RuntimeException
         #"^Timeout!.+"
         (a/evaluate @a/current-automation
                    "Array(1024 ** 3).fill().map(Math.random).length"
                    100)))))


(deftest pdf-print-test
  (a/to "http://example.com")
  (a/print-pdf @a/current-automation "example.pdf")
  (let [pdf (slurp "example.pdf")]
    (is (str/starts-with? pdf "%PDF-1.4")) ; file exists and starts with proper PDF header
    (is (> (count pdf) 50000)))) ; file should be little over 50k

{'fraction_non_alphanumeric': 0.14068441064638784, 'fraction_numerical': 0.0155893536121673, 'mean_word_length': 2.785611510791367, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '4323148', 'n_tokens_mistral': 871, 'n_tokens_neox': 820, 'n_words': 203}