{"id":55958,"date":"2026-03-25T11:36:52","date_gmt":"2026-03-25T09:36:52","guid":{"rendered":"https:\/\/www.main-vision.com\/richard\/blog\/?p=55958"},"modified":"2026-03-26T11:38:14","modified_gmt":"2026-03-26T09:38:14","slug":"myai-written-tests-for-eleventy-javascript-files","status":"publish","type":"post","link":"https:\/\/www.main-vision.com\/richard\/blog\/myai-written-tests-for-eleventy-javascript-files\/","title":{"rendered":"MyAI Written Tests for Eleventy JavaScript Files"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\"> 2<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span>\n<p>I followed several JavaScript courses. They taught my about the process, and how to think about functions, but they rarely touched upon writing tests to ensure that the functionality remains when you refactor or make changes. While experimenting with Eleventy and refactoring I tidied up some code whilst in the process removing functionality that I didn&#8217;t want to remove. It took a while to fix.<\/p>\n\n\n\n<p>That&#8217;s why I then grabbed the opportunity to begin dabbling in the realm of tests to ensure that site functionality was not downgraded from one revision to the next.<\/p>\n\n\n\n<p>The process is interesting. You present MyAI with a Javascript file and it will write functions that test to see if the functions are behaving as they are meant to. Each time a new test file is created you can run the tests and it will see if there are errors and if there are it sees whether to change the code, or to change the test logic to match what the function is meant to do.<\/p>\n\n\n\n<p>The danger, in refactoring, and experimenting with JavaScript is that it&#8217;s easy to remove a function that breaks the build which is noticable, or changes a behaviour that you don&#8217;t notice. The key example is posts no longer having an excerpt or the archives page only having two items. With tests both are checked for consistency.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method<\/h2>\n\n\n\n<p>I provided MyAI with the JS file with a list of functions. In some cases it understood the logic and wrote a test for each function. It then got me to run the test, and depending on whether there was an error message or not, it provided feedback on how to adapt the test or the function. This was just a cursory glance into how it dealt with writing tests. I&#8217;m curious to push further.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">And Finally<\/h2>\n\n\n\n<p>When you&#8217;re refactoring it&#8217;s easy to break functionality so it&#8217;s good to check that you don&#8217;t break it. It&#8217;s also interesting to see what tests look like, as an initiation into the realm of Test Driven Design. From now on I experiment with a different design methodology.<\/p>\n\n\n\n<p>I want to explore this in more depth.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\"> 2<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span>I followed several JavaScript courses. They taught my about the process, and how to think about functions, but they rarely touched upon writing tests to ensure that the functionality remains when you refactor or make changes. While experimenting with Eleventy and refactoring I tidied up some code whilst in the process removing functionality that I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":41401,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"local","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[255],"tags":[369,5883,6819],"class_list":["post-55958","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-swiss-walks","tag-blogging","tag-eleventy","tag-myai"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/www.main-vision.com\/richard\/blog\/wp-json\/wp\/v2\/posts\/55958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.main-vision.com\/richard\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.main-vision.com\/richard\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.main-vision.com\/richard\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.main-vision.com\/richard\/blog\/wp-json\/wp\/v2\/comments?post=55958"}],"version-history":[{"count":1,"href":"https:\/\/www.main-vision.com\/richard\/blog\/wp-json\/wp\/v2\/posts\/55958\/revisions"}],"predecessor-version":[{"id":55961,"href":"https:\/\/www.main-vision.com\/richard\/blog\/wp-json\/wp\/v2\/posts\/55958\/revisions\/55961"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.main-vision.com\/richard\/blog\/wp-json\/wp\/v2\/media\/41401"}],"wp:attachment":[{"href":"https:\/\/www.main-vision.com\/richard\/blog\/wp-json\/wp\/v2\/media?parent=55958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.main-vision.com\/richard\/blog\/wp-json\/wp\/v2\/categories?post=55958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.main-vision.com\/richard\/blog\/wp-json\/wp\/v2\/tags?post=55958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}