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

fix: multiple breakages due to jest version upgrade #7667

Merged
merged 8 commits into from Apr 29, 2020

Conversation

iliapolo
Copy link
Contributor

@iliapolo iliapolo commented Apr 29, 2020

Not ideal, but seems like the most pragmatic thing to do.

The PR also comes with an upgrade to jest so that we won't still use 25.4.0 which doesn't have these problems.

This essentially replaces this Dependabot PR for jest, which is naturally broken due to the issues described here.

Commit Message

fix: multiple breakages due to jest version upgrade (#7667)

Couple of things here:

require.cache

In version v25.5.0, jest introduced an implementation of their own to the require.cache object. It seems that it doesn't handle caching json modules properly, which causes our code to fail because mod.paths is undefined when we are querying for json files that were required (for example package.json or cloud-assembly.schema.json).

const paths = mod.paths.map(stripNodeModules);

TypeError: Cannot read property 'map' of undefined

The "fix" was to add a null check to prevent failure when looking up modules who don't have the paths property defined.

Note that this was only observed in test environments using jest > v25.5.0, not during actual runtime of cdk synth. This is because jest manipulates the built-in require module of nodejs.

graceful-fs

In version v25.5.0, jest added a dependency on the graceful-fs package. The version they depend on (4.2.4) differs from the version that we bring (4.2.3). This caused the graceful-fs dependency that comes from jest no to be deduped by node at installation. In turn, this caused multiple copies of the library to be installed on disk.

The graceful-fs package monkey patches the process.chdir and process.cwd functions with a cached version for better performance.

For reasons not completely clear to us, the existence of multiple copies of the module, caused process.cwd() to return incorrect cached results, essentially always returning the directory that the process was started from, without consideration to calls to process.chdir. This broke decdk (and possibly many more) tests which rely on process.chdir.

Fixes #7657

End Commit Message


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@iliapolo iliapolo added pr-linter/exempt-test The PR linter will not require test changes pr/do-not-merge This PR should not be merged at this time. labels Apr 29, 2020
@iliapolo iliapolo requested a review from a team April 29, 2020 09:44
rix0rrr
rix0rrr previously approved these changes Apr 29, 2020
@iliapolo iliapolo dismissed rix0rrr’s stale review April 29, 2020 09:54

Many more files were added after the approval

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 2fd39f6
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 0f4d5b7
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: f1a766f
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: f479074
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Apr 29, 2020
(This makes sure all the graceful-fs'es dedupe to the right
version so there's only one copy of the cached cwd while
jest executes)
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 39b9f9b
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@iliapolo iliapolo changed the title fix(core): runtime-info collection breaks in jest environment fix: multiple breakages due to jest version upgrade Apr 29, 2020
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 3327089
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: bbff37a
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: eb89c91
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@iliapolo iliapolo merged commit e18312c into master Apr 29, 2020
@iliapolo iliapolo deleted the epolon/runtime-info-empty-module-paths branch April 29, 2020 17:48
iliapolo added a commit that referenced this pull request Apr 29, 2020
Couple of things here:

**require.cache**

In version `v25.5.0`, jest introduced an [implementation](jestjs/jest#9841) of their own to the `require.cache` object. It seems that it doesn't handle caching `json` modules properly, which causes our code to fail because `mod.paths` is `undefined` when we are querying for `json` files that were required (for example `package.json` or `cloud-assembly.schema.json`).

https://github.com/aws/aws-cdk/blob/07fe642e38118e24837b492fa182737fc41bb429/packages/%40aws-cdk/core/lib/private/runtime-info.ts#L66

```console
TypeError: Cannot read property 'map' of undefined
```

The "fix" was to add a null check to prevent failure when looking up modules who don't have the `paths` property defined.

Note that this was only observed in test environments using `jest > v25.5.0`, not during actual runtime of `cdk synth`. This is because `jest` manipulates the built-in `require` module of `nodejs`.

**graceful-fs**

In version `v25.5.0`, jest [added](jestjs/jest#9443) a dependency on the `graceful-fs` package. The version they depend on (`4.2.4`) differs from the version that we bring (`4.2.3`). This caused the `graceful-fs` dependency that comes from `jest` no to be deduped by node at installation. In turn, this caused multiple copies of the library to be installed on disk.

The `graceful-fs` package monkey patches the `process.chdir` and `process.cwd` functions with a cached version for better performance.

For reasons not completely clear to us, the existence of multiple copies of the module, caused `process.cwd()` to return incorrect cached results, essentially always returning the directory that the process was started from, without consideration to calls to `process.chdir`. This broke `decdk` (and possibly many more) tests which rely on `process.chdir`.

Fixes #7657
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. pr/do-not-merge This PR should not be merged at this time. pr-linter/exempt-test The PR linter will not require test changes
Projects
None yet
3 participants