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

Add "engines" flag to package.json #29

Merged
merged 5 commits into from Jun 7, 2022
Merged

Conversation

ballercat
Copy link
Contributor

@ballercat ballercat commented Jun 3, 2022

Hi there, 👋

I really what you folks got going here with Buildkite Test Analytics! Noticed that we are missing support for Cypress and wanted to contribute to this project but ya'll got some issues with the e2e tests and docs. Hopefully this helps others 👍

Expected behavior

Test pass after fresh install and following CONTRIBUTING docs.

Actual behavior

End to end tests timeout if examples/jest directory is missing node_modules.

Note: Looks like this is an issue with using npm versions 6.x, not sure about 7.x vs the CI which is using 8.9.0. This change makes it work on all versions however.

Output

~/work/test-collector-javascript main*
13:07:53 ❯ npm test

> buildkite-test-collector@1.0.1 test /Users/abuldauskas/work/test-collector-javascript
> jest

 PASS  util/ci.test.js
 PASS  jest/reporter.test.js
 FAIL  e2e/jest.test.js (5.699 s)
  ● examples/jest › it posts the correct JSON

    expect(received).toMatch(expected)

    Expected pattern: /Posting to Test Analytics: ({.*})/m
    Received string:  "
    > buildkite-test-collector-jest-example@ test /Users/abuldauskas/work/test-collector-javascript/examples/jest
    > jest·
    "

      17 |     }
      18 |     exec('npm test', execOpts, (error, stdout, stderr) => {
    > 19 |       expect(stdout).toMatch(/Posting to Test Analytics: ({.*})/m);
         |                      ^
      20 |
      21 |       const jsonMatch = stdout.match(/Posting to Test Analytics: ({.*})/m)
      22 |       const json = JSON.parse(jsonMatch[1])

      at toMatch (e2e/jest.test.js:19:22)

  ● examples/jest › it posts the correct JSON

    thrown: "Exceeded timeout of 5000 ms for a test.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

       7 |
       8 | describe('examples/jest', () => {
    >  9 |   test('it posts the correct JSON', (done) => {
         |   ^
      10 |     const execOpts = {
      11 |       cwd: path.join(__dirname, "../examples/jest"),
      12 |       env: {

      at test (e2e/jest.test.js:9:3)
      at Object.describe (e2e/jest.test.js:8:1)

Test Suites: 1 failed, 2 passed, 3 total
Tests:       1 failed, 10 passed, 11 total
Snapshots:   0 total
Time:        6.112 s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

Solution

  • Test timeout after 5s because the done() that's currently in the test can never be reached. The initial expect fails the callback method, because expect throws and the rest of the code in the function can never be reached.
  • Used promisify to make the code a bit easier to read and handle the error in tests without a timeout being hit
  • Added a line to the readme to install example directories. Maybe consider making these not depend on an install in the future.

With this change, the test will still fail w/o node_modules in the example folder but the test suite will not timeout and only take ~2s (on my machine).

@toolmantim
Copy link
Contributor

Thanks for the contribution, and sorry you had trouble getting things set up locally.

This project uses npm workspaces, introduced with npm 7. That would explain why on npm 6 it didn’t install the node_modules correctly.

Looks like we’re missing a {"engines":{"npm":">=7.0.0"} in package.json that codifies these minimum requirements.

Can you try getting started again, but with npm >= 7? Becuase if that works, I’d prefer us not merge this change but just make the above package.json change instead.

@ballercat
Copy link
Contributor Author

Hey @toolmantim, sure no problem I can adjust the package.json in this PR / sounds reasonable to me.

Just wanted to mention that if you guys do have timeouts with these in the future due to other test runner related issues a change to the test body as in this PR would likely be something you might want to revisit!

@ballercat ballercat changed the title Fix e2e tests Add "engines" flag to package.json Jun 7, 2022
@ballercat
Copy link
Contributor Author

Done.

Copy link
Contributor

@toolmantim toolmantim 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! 👍🏼👍🏼

@toolmantim toolmantim merged commit b752f4a into buildkite:main Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants