Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: Run unit tests on more node versions, mac, and windows #16744

Merged
merged 14 commits into from
Dec 15, 2021
Merged

Conversation

IanVS
Copy link
Member

@IanVS IanVS commented Nov 22, 2021

Issue: N/A

What I did

In #16723 (review), it was requested to run tests on Windows. It surprised me a bit that unit tests were not already automatically running on windows for every PR. So, this PR adds windows to the unit tests in the github action. I also took things a step further and added more versions of node.js, as well as MacOS.

According to #16664, we can expect the windows tests to fail. And I'm not sure if there's been discussion previously on adding windows tests or not, but I figured I'd throw this up and see what happens. :)

How to test

  • Is this testable with Jest or Chromatic screenshots?
  • Does this need a new example in the kitchen sink apps?
  • Does this need an update to the documentation?

If your answer is yes to any of these, please make sure to include it in your PR.

@nx-cloud
Copy link

nx-cloud bot commented Nov 22, 2021

Nx Cloud Report

CI ran the following commands for commit dacc755. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch

Status Command
#000000 nx run-many --target=prepare --all --parallel --max-parallel=15

Sent with 💌 from NxCloud.

@nx-cloud
Copy link

nx-cloud bot commented Nov 22, 2021

Nx Cloud Report

We didn't find any information for the current pull request with the commit 2548872.
You might need to set the 'NX_BRANCH' environment variable in your CI pipeline.

Check the Nx Cloud Github Integration documentation for more information.


Sent with 💌 from NxCloud.

@IanVS
Copy link
Member Author

IanVS commented Nov 22, 2021

As expected, Windows tests are failing. I'm not sure how we'd even get them passing, TBH.

Interestingly, Node 17 is also failing, due to something in webpack 5, it seems:

  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Proxy.createHash (node:crypto:130:10)
    at module.exports (/home/runner/work/storybook/storybook/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/home/runner/work/storybook/storybook/node_modules/webpack/lib/NormalModule.js:417:16)
    at handleParseError (/home/runner/work/storybook/storybook/node_modules/webpack/lib/NormalModule.js:471:10)
    at /home/runner/work/storybook/storybook/node_modules/webpack/lib/NormalModule.js:503:5
    at /home/runner/work/storybook/storybook/node_modules/webpack/lib/NormalModule.js:358:12
    at /home/runner/work/storybook/storybook/node_modules/loader-runner/lib/LoaderRunner.js:373:3
    at iterateNormalLoaders (/home/runner/work/storybook/storybook/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
    at Array.<anonymous> (/home/runner/work/storybook/storybook/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
    at Storage.finished (/home/runner/work/storybook/storybook/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
    at /home/runner/work/storybook/storybook/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
    at /home/runner/work/storybook/storybook/node_modules/graceful-fs/graceful-fs.js:123:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v17.1.0

Ah, yes this Node 17 problem has been raised in an issue: #16555

@IanVS
Copy link
Member Author

IanVS commented Nov 22, 2021

One approach might be to use https://www.npmjs.com/package/jest-os-detection to write linux and windows specific tests that only run on particular operating systems.

But, I'd like to know if the team thinks this is worth exploring, before I put any time into it. Also, if anyone else already has a good windows environment set up, I'd be happy to turn this effort over to them. :)

@ndelangen
Copy link
Member

ndelangen commented Nov 22, 2021

Looks like (at least part of) the reason why tests are failing on windows is because of line-ending issues:

Screenshot 2021-11-22 at 17 12 56

@IanVS
Copy link
Member Author

IanVS commented Nov 22, 2021

@ndelangen exactly. Line endings and path separator differences (/ vs \) account for many of the failures, I believe.

@IanVS IanVS force-pushed the windows-tests branch 5 times, most recently from b63347d to 2412607 Compare November 23, 2021 22:13
@IanVS
Copy link
Member Author

IanVS commented Nov 23, 2021

OK, it'll take a while for the CI to run, but I think I've at least gotten the snapshots passing on both windows and linux. I'll take a look at the unit tests next.

@IanVS
Copy link
Member Author

IanVS commented Nov 24, 2021

@ndelangen is it possible that this is a legit failure on windows?

loadPreset › should prepend framework field to list of presets

    expect(received).toMatchInlineSnapshot(snapshot)

    Snapshot name: `loadPreset should prepend framework field to list of presets 1`

    - Snapshot  - 5
    + Received  + 0

    @@ -8,15 +8,10 @@
          "name": "@storybook/preset-typescript",
          "options": Object {},
          "preset": Object {},
        },
        Object {
    -     "name": "@storybook/addon-docs/preset",
    -     "options": Object {},
    -     "preset": Object {},
    -   },
    -   Object {
          "name": Object {
            "addons": Array [
              "@storybook/addon-docs",
            ],
            "framework": "@storybook/react",

      436 |       {}
      437 |     );
    > 438 |     expect(loaded).toMatchInlineSnapshot(`
          |                    ^
      439 |       Array [
      440 |         Object {
      441 |           "name": "@storybook/react",

      at Object.<anonymous> (lib/core-common/src/presets.test.ts:438:20)

@shilman shilman added maintenance User-facing maintenance tasks and removed other labels Nov 24, 2021
@shilman shilman changed the title Run unit tests on more node versions, mac, and windows Build: Run unit tests on more node versions, mac, and windows Nov 24, 2021
@ndelangen
Copy link
Member

That doesn't look good indeed. @IanVS

@Marklb
Copy link
Member

Marklb commented Dec 3, 2021

I have taken a look at the Angular tests on Windows and usually end up just running the specific tests that I know my change could affect and just let the rest run in CI, or a linux VM if I am fairly sure I will need to rerun the tests multiple times. It would be nice to not have to do that. I am not the most experienced with unit tests, but I can try to help get the Angular ones passing, at least.

One tricky thing I have run into with tests on Windows is the different valid path formats, depending on what will be processing them. I was trying to fix one last night and I think it was a Typescript Webpack plugin had a path in the format E:\Users\Docs\Project then an Angular Webpack plugin had a path in the format E:\\Users\\Docs\\Project then something else had a path in the format E:/Users/Docs/Project.

@Marklb
Copy link
Member

Marklb commented Dec 4, 2021

Well, I took a look at the Angular errors, again and even though I would like it to be more obvious which path formatting should be used, they weren't as far off from fixing as I remembered from last time I looked. I haven't tested them outside of windows yet, but I can do that then submit them or you can just pick them out of my fork if it's useful. It isn't much: Marklb@e432ea0

@IanVS IanVS force-pushed the windows-tests branch 2 times, most recently from 8a5b383 to 1dad0ee Compare December 4, 2021 23:32
@IanVS
Copy link
Member Author

IanVS commented Dec 12, 2021

OK, I've made some updates and verified that the unit test matrix jobs do not run on a PR unless the ci:matrix label is added, and that they start as soon as the label is added. The tests should also run on merges to next. I've just rebased on next, and believe this is ready for review now.

@IanVS
Copy link
Member Author

IanVS commented Dec 12, 2021

OK, with the latest commit I've made sure the tests continue to run when new commits are pushed as long as that label still is present.

// this only applies to this file
jest.setTimeout(10000);

// FIXME: this doesn't work
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments on this FIXME, @IanVS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that the stories.json file was still being created. Also, when I turned on logging, I was seeing messages about this preset being invalid. I think maybe it's not in the correct format for a preset, perhaps?

Copy link
Contributor

@kylegach kylegach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this very thoughtful PR, @IanVS. Future contributors on Windows should have a much nicer experience.

These changes look good to me, but people more familiar with Windows dev and/or @shilman, @ndelangen, @tmeasday should provide final approval.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IanVS This is amazing work. Thanks so much for putting the time in, and also for your patience on the merge. I'm guessing we'll need to tweak a bit once we run this in practice, but I'll coordinate that with you when the time comes. In the meantime, merging! 💯

@shilman shilman merged commit e7b8c49 into next Dec 15, 2021
@shilman shilman deleted the windows-tests branch December 15, 2021 02:54
@IanVS
Copy link
Member Author

IanVS commented Dec 15, 2021

Thanks @shilman. And just to close the loop on one point, it does look like the unit tests are running against the next branch, as intended:

image

@ndelangen
Copy link
Member

I think running the unit tests on multiple platforms is great, but taking different snapshot on different platforms, will make things more difficult.

If someone needs to update the snapshots, they need access to both platforms, which is not something everyone has (me included, I do not have access to any windows platform device)

@IanVS
Copy link
Member Author

IanVS commented Mar 3, 2022

That's a good point. I was using a virtual machine on my mac when I was working on this PR, but that's a pain. I could see a few different possible solutions.

  1. Find a way to accept snapshot changes within CI (maybe this is possible?).
  2. Let them fail until someone with windows can update them.
  3. Remove the snapshots, replace with more explicit tests.
  4. Remove windows tests in CI.

I'd love if we could find an option that's not #4, since I think it's good to have visibility into the windows experience. But, I'll understand if that's the way y'all want to go.

@tmeasday
Copy link
Member

tmeasday commented Mar 4, 2022

Find a way to accept snapshot changes within CI (maybe this is possible?).

I'm not necessarily advocating for this but with Circle it is possible to create downloadable artifacts from a build. What we did in a similar situation in the Chromatic monorepo is do the snapshot tests in CI in two phases:

  1. Run, record exit code.
  2. If 1. failed, run a second time with --updateSnapshot --onlyFailures, place snapshots in artifact location
  3. Return exit code from 1.

It's a bit clunky but it does mean as a dev you can download the snapshots generated in CI in 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance User-facing maintenance tasks windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants