Bytes: Twitter beefs between framework authors

Bytes banner (Turn on images 😘)

This week, we’ve got a new way to feel something test your code, some bundler fan fiction, and the hardest diss of the 18th Century.

Welcome to #102.


Beeker meme

My first (and last) testing conference

Fact checking your terrible tests

Version 3.0.0 of fast-check, a “property-based testing” library for JavaScript, came out last week. If you’re not familiar, be thankful you’re hearing about it from us and not the obnoxious guy (yes guy) on your team who spends more time arguing about functional programming than getting work done.

What’s Property-Based Testing? Most developers write tests like they do estimates: give the best case scenario and hope it all works out. These lies hardcoded inputs (🥸) are called “example based tests”.

With property-based tests, your test is run hundreds of times with different autogenerated inputs. It’s kind of like having an automated QA person that fact checks your code. fast-check is the most popular library for doing this with JavaScript (and TypeScript).

How does it work? fast-check provides a bunch of utilities for defining the “properties” of your code (things you assume will always be true). It uses them to generate random inputs to test against your code. When a test fails, fast-check helps narrow down the (💩 ton of) failed cases to a single reproducible case that you can “replay” to verify the fix.

Ngl, it’s a lot to take in but they provide a handy set of tips and interactive examples to help you get get familiar.

Property based testing might be for you if you:

  1. Need help detecting race conditions
  2. Need to find edge cases when you can’t conceivably know all the possibilities
  3. Want less tests but with better coverage

Bottom Line: If you want to stop wasting your time with terrible tests, you can A) delete them all (galaxy brain) or B) go all in and use property based testing. We’re big fans of A), but if math is your kink, fast-check might be worth your time.


Elmo making bad decisions meme

Don't be like Elmo. [sponsored]

Sleuth.io can actually make your team more efficient

Tracking “developer productivity” is stupid.

Two reasons:

  1. Developers hate it (spying on me to see if I’m a “productive developer,” actually makes me a way less productive developer)
  2. It doesn’t work (“whoever writes the most lines of code/closes the most tickets is the best developer” is… really dumb?)

That’s why Sleuth is the best. It doesn’t track developer productivity – it only measures team output. And it actually works.

That’s because it captures your team’s DORA metrics – which multiple studies have shown are the only stats that actually matter. No worthless vanity metrics and no individual stats.

Sleuth automatically collects all that data for you (including deploys), unlike most other services that only collect git or issue tracker data. So you can trust that the numbers are legit.

It’s also worth noting that Atlassian uses Sleuth. That’s like being Chef Gordon Ramsey’s favorite restaurant – if it works for them, it’ll probably help you too.

Try it free and help your team reach its goals faster.


Boy wrapped in bubble wrap

Y'all still looking for a bundler?

Let’s get ready to bundle

Back in 2018, Airbnb did what lots of us have done when thinking about upgrading to a new version of Webpack – give up.

Unfortunately for them, this was before The Great Build Tool Renaissance™️ of the last couple years – esbuild and Rollup weren’t around yet, Parcel wasn’t as robust as it is today, and Rome was still just a European city with lots of roads.

So they turned to Metro, Facebook’s open-source JavaScript bundler for React Native.

This was a surprising choice for Airbnb’s web app, and it required them to work directly with the Metro team to create their own custom flavor of Metro (yum) that could handle bundling all of Airbnb’s web properties. The 4-year odyssey finally ended last week with an interesting retro outlining the entire process.

So let’s dive a little deeper into what makes Metro unique, why Airbnb decided to use it, and how it stacks up to some of the newer bundlers we have today.

There are two defining Metro features:

  1. On-demand bundle processing in development – Metro only compiles JS bundles on the pages requested, as opposed to pre-compiling the entire project from the start (like Webpack).
  2. Multi-layered cache – You can set up multiple caches to be used by Metro, and you get the flexibility to define the cache implementation you want.

For most projects, implementing these optimizations would probably feel like extreme hair-splitting (my favorite Winter X-Games event). But for a huge app like Airbnb with 49k+ JS modules, it produced great results, including 80% faster TTI (Time to Interactive) and 55% faster compiling of the slowest prod build. 👏

Should you try this at home? Probably not, tbh. In The Year of Our Build 2022, we have better options for powerful, flexible bundlers that don’t require years of customization (esbuild is probably the gold standard for most projects).

But you could always just wait around for a couple years until we inevitably get something even faster.


Jobs

Backend TypeScript Engineer at Flightcontrol

Flightcontrol recently completed YCombinator and raised $3.3m. They’re a fully remote team that’s focused on solving the huge gap between Heroku and AWS, and they’re led by Brandon Bayer, the creator of Blitz.js.

Senior or Staff Front-end Engineer - React (100% Remote)

Close.com is looking for 3 experienced individuals that have a solid understanding of React and want to help design, implement and launch major user-facing features. Close is a 100% globally distributed team of ~55 high-performing, happy people that are dedicated to building a product our customers love.

Yeti Labs is looking for Frontend (React + Typescript) developers

Yeti Labs is a human-centered frontend studio designing and building web apps for DeFi protocols. We love UI animations, innovative UXs, best practices, reusing our code, improving our workflow and learning new things. Come join our crew as we solve interesting challenges while having fun.


🔬 Spot the Bug – Sponsored by CarbonQA

CarbonQA provides QA services geared for dev teams. Let us lift your dev team’s morale by breaking their code. We work in your tools, talk with your team in Slack, and let devs be devs. Leave the testing to us.

import db from "./db";
import admin from "firebase-admin";
import { getUserClaimsFromCookie } from "./claims";

const { arrayUnion, arrayRemove } = admin.firestore.FieldValue

export default async function updateLessonComplete(req, res) {
  try {
    const { lessonId, completed } = req.body

    if (!lessonId) {
      throw new Error("lessonId is a required parameter");
    }

    if (!completed) {
      throw new Error("completed is a required parameter");
    }

    const claims = await getUserClaimsFromCookie(req, res);

    if (!claims) {
      throw new Error('user must be logged in')
    }

    await db.collection('lessons').doc(lessonId)
      .update({
        completed: completed === true
          ? arrayUnion(claims.uid)
          : arrayRemove(claims.uid)
      })

    res.send({ status: "success" });
  } catch (e) {
    res.status(400);
    res.send({ error: { message: e.message } });
  }
}


Cool Bits

  1. Curious about what’s happening in Java-land? New Relic’s got you covered with their 2022 State of the Java Ecosystem Report. [sponsored]

  2. The new React docs got some performance upgrades after Evan You and Dan Abramov went head to head in a battle of the subtweets. I’m sad that neither of them found a way to use the hardest diss of the 18th Century, but there’s always next time.

  3. Speaking of Twitter beefs between framework authors, Next.js just shared their new Layouts RFC – which is basically just Remix (Taylor’s Guillermo’s Version). Here’s a quick TLDR we made to catch you up to speed.

  4. Austin Gil wrote an in-depth article about Why Edge Compute is kind of like knitting dog hats. Personally, I think it’s a lot more like crocheting, but that’s just one person’s opinion.

  5. Tailwind 1.6 was just released with a new Tailwind language mode for VS Code and some other cool features to help you feel good at design.

  6. Danny Hermes wrote a great article about What npm Can Learn from Go and that has us thinking, why is “Can” capitalized but not “From”?

  7. Digital Ocean just announced DO Functions and officially entered the serverless computing battle royale.

  8. Ken Kantzer wrote up his learnings from 5 years of doing tech startup code audits. Specializing in “code audits for startups” sounds about as much fun as specializing in “behavior management for middle schoolers”, but I’m glad there are good people out there doing both.


🔬 Spot the Bug Solution – Sponsored by CarbonQA

import db from "./db";
import admin from "firebase-admin";
import { getUserClaimsFromCookie } from "./claims";

const { arrayUnion, arrayRemove } = admin.firestore.FieldValue

export default async function updateLessonComplete(req, res) {
  try {
    const { lessonId, completed } = req.body

    if (!lessonId) {
      throw new Error("lessonId is a required parameter");
    }

    if (!completed) {
      throw new Error("completed is a required parameter");
    }

    const claims = await getUserClaimsFromCookie(req, res);

    if (!claims) {
      throw new Error('user must be logged in')
    }

    await db.collection('lessons').doc(lessonId)
      .update({
        completed: completed === true
          ? arrayUnion(claims.uid)
          : arrayRemove(claims.uid)
      })

    res.send({ status: "success" });
  } catch (e) {
    res.status(400);
    res.send({ error: { message: e.message } });
  }
}

There’s a lot of misdirection here. The bug happens with our if (!completed) check. completed is a boolean, meaning when completed is false (making it falsy), our code will throw an error. Instead, we can check if completed is of type boolean, not if it’s falsy.

if (typeof completed !== 'boolean') {
  throw new Error("completed is a required parameter");
}

and before you say it, yes, I know TypeScript prevents this 🙂.


Share Bytes

ui.dev banner
 

We work hard to make Bytes something you'd want to share with your developer friends. And to make it a little easier, we'll give you free stuff when you do.

30

Your bits

Your Referral Page

Your shareable link

https://bytes.dev?x=1697807915
 

Have a product you think our developers will love?
Advertise in Bytes

youtube icon youtube icon twitter icon instagram icon

50 W Broadway Ste 333 PMB 51647 Salt Lake City, Utah 84101

Unsubscribe from Bytes

Older messages

Bytes: Two words: React fatigue

Monday, May 23, 2022

This week, we've got blessings from the platform, math being a very cool thing, and yet another existential crisis. Welcome to #101. The Chrome team presenting new platform features Google I/O

Bytes: 10 things we learned turning 100

Monday, May 16, 2022

🎉 Welcome to issue 100 🎉 We were planning on doing an awesome giveaway, but after looking at $NET this morning, it'll have to wait until issue #200. Let's rage 10 things we learned turning 100

Bytes: Why Web Components Lost

Monday, May 9, 2022

This week, we've got React hook turtles all the way down, Jörmungandr trying to take down JavaScript, and a surefire way to get on Linus Torvalds' good side. Welcome to #99. React hooks are

Bytes: making FTP cool again

Tuesday, May 3, 2022

“WTF is this?” First off, watch your language. The RWD Weekly newsletter (of which you were subscribed) has merged with Bytes (this newsletter) to bring you our educational, yet delightful dose of

Bytes: The Edge is just a spicy CDN

Tuesday, May 3, 2022

This week, we're experimenting with our runtime features, learning about The Edge™️, and (hopefully) avoiding accidental tax fraud. Welcome to #97. Some experiments pay off Node gets experimental

You Might Also Like

LockBit Ransomware Developer Charged for Billions in Global Damages

Saturday, December 21, 2024

THN Daily Updates Newsletter cover The Data Science Handbook, 2nd Edition ($60.00 Value) FREE for a Limited Time Practical, accessible guide to becoming a data scientist, updated to include the latest

Re: My VPN recommendation

Saturday, December 21, 2024

Do you know when to use a VPN and what it does to protect your data? Any time you are connected to the internet, your information is at risk of being tracked or hacked. A VPN helps keep your surfing

📧 Scheduling Background Jobs With Quartz in .NET (advanced concepts)

Saturday, December 21, 2024

​ Scheduling Background Jobs With Quartz in .NET (advanced concepts) Read on: m​y website / Read time: 6 minutes The .NET Weekly is brought to you by: It's been a big year for API collaborations!

The Thrill Was Never There 🎸

Saturday, December 21, 2024

Takeaways from a punk-rock creator who says he doesn't like punk. Here's a version for your browser. Hunting for the end of the long tail • December 20, 2024 The Thrill Was Never There A famous

🎮 Smartphones Will Never Kill Dedicated Handhelds — 11 Stocking Stuffers for iPhone Owners

Friday, December 20, 2024

Also: How to Add a Smart Speaker to Your Home Assistant Setup How-To Geek Logo December 20, 2024 Did You Know The nursery rhyme "Mary Had a Little Lamb" is based on a true story. The girl in

Daily Coding Problem: Problem #1643 [Easy]

Friday, December 20, 2024

Daily Coding Problem Good morning! Here's your coding interview problem for today. This problem was asked by Facebook. Given a 32-bit integer, return the number with its bits reversed. For example,

JSK Daily for Dec 20, 2024

Friday, December 20, 2024

JSK Daily for Dec 20, 2024 View this email in your browser A community curated daily e-mail of JavaScript news Empower Your Data Insights: Integrating JavaScript Gantt Chart into Power BI Syncfusion

Charted | America’s Top 20 Billionaires, by Wealth 💰

Friday, December 20, 2024

America's top 20 billionaires have a combined wealth of $2.7 trillion, as of December 2024. See how it all breaks down in this infographic. View Online | Subscribe | Download Our App Presented by:

My holiday AI reading list 🎄

Friday, December 20, 2024

plus, what's coming in 2025 ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏

Spyglass Dispatch: On to '25

Friday, December 20, 2024

Google's 'AI Mode' • Billionaires at Dinner • Nintendo's Switch 2 • Amazon's Bond Problem The Spyglass Dispatch is a newsletter sent on weekdays featuring links and commentary on