HNHacker News
TopNewBestAskShowJobs

kolodny

1,145 karma · joined March 31, 2013

Github: https://github.com/kolodny

Blog: http://kolodny.github.io/blog/

Linkedin: https://www.linkedin.com/in/moshekolodny

submissionscomments
kolodny··on SafeTest: A novel approach to front end testing
React is pretty performant when context isn't changing. We haven't done any benchmarking but I doubt there's any real world perf hit. For large applications the number of overrides tend to be under 20.

Overrides are opt-in so you can just expose any overridable value as a prop and run a isolated component test on it.

kolodny··on SafeTest: A novel approach to front end testing
Creating an override is basically just providing a placeholder for a value to be injected via React Context. I view this as a form of dependency injection. Contrast this with how this would be done in vanilla Playwright with reading it from a query param or exposing a global to call page.evaluate on which is more along the lines of forcing test code into a component.

Note that if you needed a specific reference in an override there isn't a good way to get that via Playwright, consider this silly example:

    it('can test spies', async () => {
      const spy = browserMock.fn();
      const { page } = await render(
        app =>
          <LogoutButtonAction.Override with={() => spy}>
            {app}
          <LogoutButtonAction.Override>
      );

      await page.getByText('Log out').click();
      expect(await spy).toHaveBeenCalled();
    });
kolodny··on SafeTest: A novel approach to front end testing
The point is that you shouldn't need to rewrite your countdown component to allow testing. Can you provide a snippet of that change and what the test would look like?

Not being toggle parts of the app is the root of the issue when creating e2e tests. For example overriding a feature flag, you could find the API call for the feature but what if it's a grpc call and part of your dev build pulls in any update, you can't easily change the binary response with confidence anymore.

The current solutions are good enough to do smoke tests, but nitty-gritty e2e tests don't scale well.

In the example above it's simple

    export const CountdownTime = createOverride(60);
    export const Countdown = () => {
      const initialTime = CountdownTime.useValue();
      const [time, setTime] = React.useState(initialTime);
      React.useEffect(() => {
        const interval = setInterval(() => {
          setTime(t => t - 1);
          if (t === 1) clearInterval(interval);
        }, 1000);

        return () => clearInterval(interval)
      }, []);

      return time > 0 ? <>Time left {time}</> : <>Done</>
    };

    it('tests faster', async () => {
      const { page } = await render(
        app => <CountdownTime.Override with={() => 5}>{app}</CountdownTime.Override>
      );
      await expect(page.getByText('Done')).not.toBeVisible();
      page.waitForTimeout(5000);
      await expect(page.getByText('Done')).toBeVisible();
    });

If I needed something like this, I'd probably also make setInterval an override as well, so I don't need to wait at all, but you get the idea.
kolodny··on SafeTest: A novel approach to front end testing
Author here. Can you show an example of how Playwright would progress a timer on a page? For example, how would you make this component pass faster than 60 seconds?

    export const Countdown = () => {
      const [time, setTime] = React.useState(60);
      React.useEffect(() => {
        const interval = setInterval(() => {
          setTime(t => t - 1);
          if (t === 1) clearInterval(interval);
        }, 1000);

        return () => clearInterval(interval)
      }, []);

      return time > 0 ? <>Time left {time}</> : <>Done</>
    };
Short of using Playwright Component Tests, this isn't possible.

I also found an issue where the only solution was to inject sinon into the page which I wouldn't consider a great option: https://github.com/microsoft/playwright/issues/10230

kolodny··on SafeTest: A novel approach to front end testing
Sorry about that. I just added an official LICENSE file

https://github.com/kolodny/safetest/blob/main/LICENSE

kolodny··on SafeTest: A novel approach to front end testing
Can you clarify what you mean? Usually, e2e testers don't have a bootstrapping stage for app-level changes, only for things that can be done via the browser automation APIs.
kolodny··on SafeTest: A novel approach to front end testing
Yes, that's correct. You get all the benefits of react-testing-library mounting and the ability to test the entire app as a unit.
kolodny··on Simpler UI Logic With Finite State Machines
Nice, Swift also handles having all the transition changes as well. I wrote a small post about how to do this: https://gist.github.com/kolodny/6fa6aa34a711d36e9de01cec4409...
kolodny··on Skip grep, use awk
Somewhat related nodejs self plug: Use nip https://github.com/kolodny/nip

    $  echo -e 'this\nis\na\nwhatever foo' | nip 'return /whatever/.test(line) && cols[1]' # foo
kolodny··on Raymond Smullyan has died
One of my favorite books is the "The Chess Mysteries of Sherlock Holmes" which describes a technique called retrograde analysis

https://www.amazon.com/Chess-Mysteries-Sherlock-Holmes-Recre...

kolodny··on [dead]
There should be a link for you to delete it

http://i.imgur.com/pwHijrG.png

kolodny··on jQuery 3.0 Released
https://gist.github.com/paulirish/12fb951a8b893a454b32
kolodny··on Ask HN: How do prolific programmers go about their daily lives?
I wouldn't know about that. It sounds like the OP is specifically asking about people who contribute to OSS as "just a hobby"
kolodny··on Ask HN: How do prolific programmers go about their daily lives?
As others have been saying, the "prolific programmers" have a passion to program that doesn't get satisfied by coding from just 9 to 5. Personally I tend to have waves of intense programming around the clock followed by a cooling down period with either part of the cycle lasting days to weeks. Sorry for the shameless self plug but you should start small and try making a "One Hour Side Project" http://kolodny.github.io/blog/blog/2015/03/03/the-one-hour-s...
kolodny··on Show HN: Janeway – A more mouse-driven, curses-based Node.js console
That would be awesome considering you need to run _mocha with --debug-brk and it never really works that well
kolodny··on blip.strongloop.com is dead – what is this?
https://api.npmjs.org/downloads/point/last-day/express
kolodny··on Savable Sharable Rich Text Editor Fit in a Tweet
The address bar will update automatically
kolodny··on ReactCSS – Bringing Classes to Inline Styles
I've never seen any builder that outputs js to that[1]. Does anyone know what he's using?

[1][ https://raw.githubusercontent.com/casesandberg/reactcss/gh-p... ]

kolodny··on Show HN: A Repo of JavaScript Coding Challenges
https://github.com/kolodny/jsan ;)
kolodny··on Show HN: A Repo of JavaScript Coding Challenges
Yup, fixed. Thanks
kolodny··on Show HN: A Repo of JavaScript Coding Challenges
You should be creating the index file, it's the solution to the problem. If you were going to edit the test.js it would make it really simple ;)
kolodny··on Hello, World
Another way to look at it is either they can both get the same result or they can get different results, if it's the same then Bob will be correct, if it's different then Alice will be correct
kolodny··on Endless Horse
In case anyone is wondering:

       ,
    _,,)\.~,,._
    (()`  ``)\))),,_
     |     \ ''((\)))),,_          ____
     |6`   |   ''((\())) "-.____.-"    `-.-,
     |    .'\    ''))))'                  \)))
     |   |   `.     ''                     ((((
     \, _)     \/                          |))))
      `'        |                          (((((
                \                  |       ))))))
                 `|    |           ,\     /((((((
                  |   / `-.______.<  \   |  )))))
                  |   |  /         `. \  \  ((((
                  |  / \ |           `.\  | (((
                  \  | | |             )| |  ))
                   | | | |             || |  '
                   | | | |             || |  
                   | | | |             || |  
                   | | | |             || |  
                   | | | |             || |  
                   | | | |             || |  
                   | | | |             || |  
                   | | | |             || |  
                   | | | |            / | |  
                   | | /_(           /_(/ /
              hjw  /_(/__]           \_/_(
                  /__]                /__]
kolodny··on Render HTML via WebGL
fiddle: http://jsfiddle.net/409gxzm6/
kolodny··on Signing in to websites with SSH
I may be missing something but this seems highly susceptible to man in the middle attacks
kolodny··on Wikipedia on HHVM
I think that techempower is a neutral third party yet they show php having a huge advantage over hhvm[1]

[1] : https://www.techempower.com/benchmarks/

kolodny··on Language choices for long-term projects
In case anyone is curious about any of those languages:

http://learnxinyminutes.com/

kolodny··on Sherlock Holmes Debugging
For debugging javascript there's tracegl [1] and you can always restart frame in devtools [2]

1: https://github.com/traceglMPL/tracegl

2: https://twitter.com/ebryn/status/443080437485682689

kolodny··on IntelliJ IDEA 14 Released
I'm really impressed with the javascript debugger showing relevant vars on a line by line basis as the code is executed, although that's more a matter of a Webstorm feature trickling down into Intellij.
kolodny··on Stackoverflow is down
I guess it wasn't down for very long
Page 1 of 3Next →