社内用の啓発記事ですが、閉じる理由がないのでここに投げます。 ブラウザにべったりなコードを書いてると、ブラウザや node.js 固有の環境をインラインで記述してしまうことが多々あると思います。 あえてダメダメなブラウザ向けのエントリポイントの例を書きます。 // main.ts let id = localStorage.get('id'); if (!id) { id = `${navigator.userAgent}-${Math.random()}`; localStorage.set('id', id); fetch('/auth', { method: 'POST', credentials: 'include', body: JSON.stringify({ id, at: Date.now(), }), headers: {'Content-Type': 'applicat
![実行環境依存のコードに対してテストを書く考え方](https://cdn-ak-scissors.b.st-hatena.com/image/square/677d527f56ae01f9036949ea3257c667874d10e1/height=288;version=1;width=512/https%3A%2F%2Fres.cloudinary.com%2Fzenn%2Fimage%2Fupload%2Fs--uv0dInPr--%2Fc_fit%252Cg_north_west%252Cl_text%3Anotosansjp-medium.otf_55%3A%2525E5%2525AE%25259F%2525E8%2525A1%25258C%2525E7%252592%2525B0%2525E5%2525A2%252583%2525E4%2525BE%25259D%2525E5%2525AD%252598%2525E3%252581%2525AE%2525E3%252582%2525B3%2525E3%252583%2525BC%2525E3%252583%252589%2525E3%252581%2525AB%2525E5%2525AF%2525BE%2525E3%252581%252597%2525E3%252581%2525A6%2525E3%252583%252586%2525E3%252582%2525B9%2525E3%252583%252588%2525E3%252582%252592%2525E6%25259B%2525B8%2525E3%252581%25258F%2525E8%252580%252583%2525E3%252581%252588%2525E6%252596%2525B9%252Cw_1010%252Cx_90%252Cy_100%2Fg_south_west%252Cl_text%3Anotosansjp-medium.otf_37%3Amizchi%252Cx_203%252Cy_121%2Fg_south_west%252Ch_90%252Cl_fetch%3AaHR0cHM6Ly9saDMuZ29vZ2xldXNlcmNvbnRlbnQuY29tL2EtL0FPaDE0R2liclRHT052Z3d3ay1fNGxlcVk4TGNGSlNuX0FoWnpEWVlKaXJNcWc9czI1MC1j%252Cr_max%252Cw_90%252Cx_87%252Cy_95%2Fv1627283836%2Fdefault%2Fog-base-w1200-v2.png)