Skip to content

Commit c91d725

Browse files
deploy: 5bddeab
1 parent fd974ec commit c91d725

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

blog/gleam-test-timeouts/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<!doctype html>
22
<html lang="en"><head><meta charset="UTF-8"><title>Test Timeouts in Gleam | Gears</title><link href="/style.css" rel="stylesheet"><link href="https://rsms.me/" rel="preconnect"><link href="https://rsms.me/inter/inter.css" rel="stylesheet"><link href="/favicon.svg" rel="icon" type="image/svg+xml"><link href="/favicon.ico" rel="alternate icon" sizes="48x48" type="image/png"><link href="/apple-touch-icon.png" rel="apple-touch-icon" sizes="192x192"></head><body class="min-h-screen bg-slate-800 text-white"><header class="bg-purple-700 flex w-full select-none"><nav class="flex h-16 grow items-center justify-between gap-4 px-4 text-white overflow-hidden"><a class="heading" href="/"><figure class="flex flex-shrink-0 items-center space-x-1"><img alt="Gears logo" class="w-16" height="64" src="/images/logo.svg" style="image-rendering:optimizeSpeed;image-rendering:pixelated;" width="64"><figcaption class="text-4xl font-bold font-celandine hidden md:block"><svg xmlns="http://www.w3.org/2000/svg"><path xmlns="http://www.w3.org/2000/svg" class="animate-write" d="m 46.655648,87.273021 c 0.08105,4.602277 0.692125,6.832404 4.69733,4.361206 l 1.696146,2.728148 -14.225762,9.638735 c -2.121146,-1.55607 -3.838276,-4.0442 -4.678364,-7.342384 -3.390161,3.734254 -7.562386,6.271464 -13.082724,5.788494 C 10.581627,101.53029 2.8720353,90.133692 1.4418114,77.915968 0.26959238,64.592176 8.4519982,56.762609 16.647423,50.627146 c 6.709353,-4.814367 12.185664,-6.592535 16.425926,-6.221561 10.400636,0.909937 10.2848,16.055858 17.661218,12.831577 l 1.369105,2.78015 -13.921761,7.085583 C 29.896397,65.974923 28.524127,49.408937 19.629655,55.241389 c -4.548238,3.149245 -6.106269,8.978614 -4.24704,19.057204 1.461159,6.335369 5.770507,14.209799 12.214927,17.030887 2.403158,1.097035 4.205262,0.770993 6.046357,-0.922122 l 0.08399,-0.960053 0.300983,-3.440212 c -4.7513,-0.980005 -7.300468,-2.251058 -10.07761,0.0051 L 22.053124,83.749873 33.3637,74.259168 c 9.7606,0.853945 14.332923,4.801125 19.271184,0.879838 l 1.905129,2.18211 -7.907394,7.450543 c -0.0043,0.967047 0.07203,1.94111 0.02303,2.501151 z m 27.106123,0.967939 c 3.255101,3.879267 7.924879,5.594901 14.610274,2.013462 L 89.84759,92.997687 71.511182,104.62772 C 62.371276,103.58301 53.002118,82.748534 59.5709,73.029912 61.983775,69.728218 72.927415,59.493724 79.332135,60.054064 85.49365,60.593125 92.577447,70.199104 92.109323,75.549881 Z M 70.902742,68.629587 c -3.536763,2.141364 -1.750046,9.73174 1.253752,15.549655 L 79.558343,78.94493 C 78.612783,73.878931 74.248977,66.798328 70.902742,68.629587 Z m 62.806708,23.029124 1.74528,2.221251 -13.08952,10.709588 c -2.6179,0 -5.2358,-4.839141 -5.71178,-8.567661 l -11.7409,8.567661 c -6.505075,-0.0794 -10.709601,-7.61571 -9.916305,-13.24816 1.269292,-8.250355 9.123005,-13.010178 19.832605,-16.104062 -3.49054,-5.553124 -13.08951,-4.997811 -19.0393,-1.348612 l -1.586601,-2.459244 14.993441,-10.78893 c 9.28166,0 19.19795,1.665941 19.43593,14.438129 l 0.0794,12.375534 c -0.0794,4.125169 1.26928,6.901741 4.99782,4.204506 z m -22.60914,3.490534 4.99781,-3.252544 -0.0794,-12.930849 c -10.23362,3.728531 -10.70961,12.930849 -4.91847,16.183393 z m 51.19467,-16.075266 c -2.21157,-3.712255 -5.13397,-8.846224 -8.45131,-5.765843 l -0.47391,0.473911 v 1.184756 l 0.079,12.795432 c -0.079,4.028194 1.18475,6.555693 4.897,3.949214 l 1.81664,2.448509 -13.0324,10.504892 c -3.55428,-2.21157 -6.23973,-6.792636 -6.16074,-13.664255 V 78.679058 c -0.15797,-4.818028 -1.97461,-6.397712 -6.63468,-3.396316 L 132.99186,72.755248 147.13,60.907625 c 3.08039,2.290541 4.89704,4.423114 5.68687,7.740447 l 8.05639,-7.740447 c 6.00279,0 11.68966,9.636068 11.68966,9.636068 z m 19.14678,-9.156439 c 4.4536,7.601839 23.80372,5.375035 23.80372,20.962647 0,10.442913 -10.13577,13.207223 -19.5037,13.207223 -7.14112,0 -13.8983,-2.45716 -16.12512,-6.757188 l 11.36438,-10.596498 1.84287,1.45894 c -2.91787,2.841084 11.134,6.987545 15.05009,6.987545 0.46073,-6.296472 -26.33768,-10.058994 -26.33768,-19.580489 0,-8.369699 13.89831,-14.05188 13.89831,-14.05188 7.83221,0 16.2019,4.4536 21.11622,1.61251 l 1.22858,1.689298 -12.90008,10.289358 c -4.99112,0 -11.44115,-8.292917 -13.43759,-5.221466 z" style="fill:none;stroke:#ffffff;stroke-width:1px;stroke-dasharray:330;stroke-dashoffset:330;"></path></svg></figcaption></figure></a></nav></header><main class="py-2"><div class="mx-auto max-w-3xl"><h1 class="text-3xl font-bold leading-tight text-center">Test Timeouts in Gleam</h1></div><div class="mx-auto max-w-4xl py-8 leading-8"><h2 class="text-xl font-bold text-center m-0">25 November, 2025</h2><p>If you don&#39;t care about the backstory and just want to know the answer, you can
3-
<a class="underline" href="#How-do-I-configure-my-test-timeout" target>skip there</a>.</p><h2 id="How-Gleam-tests-work">How Gleam tests work</h2><p>When you create a new Gleam project, there are two dependencies that are added
3+
<a class="underline" href="#how-do-i-configure-my-test-timeout" target>skip there</a>.</p><h2 id="how-gleam-tests-work">How Gleam tests work</h2><p>When you create a new Gleam project, there are two dependencies that are added
44
automatically by the build tool. These are <a class="underline" href="https://hexdocs.pm/gleam_stdlib" target="_blank"><code>gleam_stdlib</code></a>,
55
the Gleam standard library, and <a class="underline" href="https://hexdocs.pm/gleeunit" target="_blank"><code>gleeunit</code></a>, the
66
default test runner for Gleam. Both of these dependencies are technically optional,
77
but they are added by default to make it easier to start a new project, since
88
most projects use them.</p><p>See, when you run <code>gleam test</code> in the terminal, while it may seem like the Gleam
99
build tool finds all your test functions magically, all it&#39;s really doing is calling
1010
the <code>main</code> function of the module named <code>$PROJECT_test</code>, which by default calls
11-
out to <code>gleeunit</code>, the code that&#39;s really in charge of running your tests.</p><h2 id="What-is-gleeunit">What is gleeunit?</h2><p>On the Erlang target, the <code>gleeunit</code> library is a thin wrapper for
11+
out to <code>gleeunit</code>, the code that&#39;s really in charge of running your tests.</p><h2 id="what-is-gleeunit">What is gleeunit?</h2><p>On the Erlang target, the <code>gleeunit</code> library is a thin wrapper for
1212
<a class="underline" href="https://www.erlang.org/doc/apps/eunit/chapter.html" target="_blank"><code>EUnit</code></a>, which is a test
1313
runner built into OTP. On JavaScript, <code>gleeunit</code> implements a custom test runner
1414
that has similar (but not identical) features to EUnit. Somewhat unfortunately,
@@ -19,7 +19,7 @@
1919
more obscure API, in the form of <strong>test generators</strong>.</p><p>Test generators are another kind of EUnit test. Test generator functions end
2020
in <code>_test_</code> (note the trailing underscore), and they have the ability to configure
2121
various parts of how EUnit runs. It&#39;s detailed in the EUnit documentation,
22-
but here we will just cover the most commonly used one, which is the timeout.</p><h2 id="How-do-I-configure-my-test-timeout">How do I configure my test timeout?</h2><p>EUnit test generators allow returning extra values along with a function to call
22+
but here we will just cover the most commonly used one, which is the timeout.</p><h2 id="how-do-i-configure-my-test-timeout">How do I configure my test timeout?</h2><p>EUnit test generators allow returning extra values along with a function to call
2323
in order to configure it. In Erlang syntax, here is how you would configure the
2424
timeout for your test, to be 60 seconds instead of 5:</p><div class="codeblock"><button class="copy-button" onclick="navigator.clipboard.writeText(`something_test_() -&gt;
2525
{timeout, 60, fun () -&gt;
@@ -79,7 +79,7 @@
7979
... <span class=hl-comment>// The actual body of your test</span>
8080
}
8181
</span></code></pre></div><p>Great! We&#39;ve successfully worked around EUnit&#39;s annoying timeout. Job done! But
82-
wait...</p><h2 id="Multi-target-tests">Multi-target tests</h2><p>Remember when I mentioned earlier about how <code>gleeunit</code> works differently on the
82+
wait...</p><h2 id="multi-target-tests">Multi-target tests</h2><p>Remember when I mentioned earlier about how <code>gleeunit</code> works differently on the
8383
JavaScript target? Well, the good news is that it doesn&#39;t have a timeout like on
8484
the Erlang target, but the bad news is that it doesn&#39;t support test generators.
8585
So if all your tests are called <code>*_test_</code>, none of them are going to run on
@@ -111,7 +111,7 @@
111111
</span></code></pre></div><p>The <code>@target</code> attribute is deprecated, and you shouldn&#39;t use it really, but there
112112
isn&#39;t any alternative for this specific case. Hopefully soon we will have an
113113
alternative, both to <code>@target</code>, and to this problem of different behaviour in the
114-
test runner across targets.</p><h2 id="Conclusion">Conclusion</h2><p>If you want to change the timeout of a test that only runs on Erlang, it&#39;s not
114+
test runner across targets.</p><h2 id="conclusion">Conclusion</h2><p>If you want to change the timeout of a test that only runs on Erlang, it&#39;s not
115115
very hard. If you want to have tests that run on both targets for longer than 5
116116
seconds, it gets messy.
117117
Hopefully there will be a better way to do it in the near future.</p></div></main><footer class="right-5 bottom-4 fixed">Made with <a class="underline" href="https://lustre.build" target="_blank">Lustre</a> and <a class="underline" href="https://gleam.run" target="_blank">Gleam</a><br>Source: <a class="underline" href="https://github.com/GearsDatapacks/GearsDatapacks.github.io" target="_blank">GitHub</a></footer></body></html>

style.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,10 @@ video {
598598
margin-bottom: 0.75rem;
599599
}
600600

601+
.block {
602+
display: block;
603+
}
604+
601605
.inline {
602606
display: inline;
603607
}
@@ -755,6 +759,10 @@ video {
755759
font-weight: 700;
756760
}
757761

762+
.lowercase {
763+
text-transform: lowercase;
764+
}
765+
758766
.leading-8 {
759767
line-height: 2rem;
760768
}
@@ -772,6 +780,10 @@ video {
772780
text-decoration-line: underline;
773781
}
774782

783+
.line-through {
784+
text-decoration-line: line-through;
785+
}
786+
775787
h2 {
776788
font-size: x-large;
777789
font-weight: bold;

0 commit comments

Comments
 (0)