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

[HERMES-3750] Fix bug where missing .js file results in JSON.parse error #1587

Merged
merged 3 commits into from Sep 13, 2022

Conversation

srajiang
Copy link
Member

@srajiang srajiang commented Sep 12, 2022

Summary

  • resolves a bug where if JSON is defined but .js is undefined, the hook throws an error
  • adds additional tests for getManifestData() util method
  • moves getManifestData() into a standalone file and away from lower utility methods, for easier mocking in tests

Testing

  • Adds some tests to cover this case for when there is
    • A JSON only
    • A .js only
    • A JSON and .js
  • Manual test step:
    • Use this branch npm link & npm link @slack/bolt
    • Run hermes manifest and hermes manifest validate and a manifest should properly generate

Requirements (place an x in each [ ])

@srajiang srajiang changed the base branch from main to next-gen September 12, 2022 21:36
@srajiang srajiang self-assigned this Sep 12, 2022
@srajiang srajiang added the tests M-T: Testing work only label Sep 12, 2022
@codecov
Copy link

codecov bot commented Sep 12, 2022

Codecov Report

❗ No coverage uploaded for pull request base (next-gen@e35ec86). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head 27871a8 differs from pull request most recent head 91fffd1. Consider uploading reports for the commit 91fffd1 to get more accurate results

@@             Coverage Diff             @@
##             next-gen    #1587   +/-   ##
===========================================
  Coverage            ?   80.64%           
===========================================
  Files               ?       20           
  Lines               ?     1767           
  Branches            ?      502           
===========================================
  Hits                ?     1425           
  Misses              ?      221           
  Partials            ?      121           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -78,34 +100,7 @@ function find(currentPath, targetFilename) {
}
}

function getManifestData(searchDir) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to separate file for easier module mocking

@srajiang srajiang added the bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented label Sep 12, 2022
/**
* Union merge of arrays
*/
export function unionMerge(array1, array2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@srajiang it seems like this export keyword here threw an error for me when running hermes manifest while testing. i think since it's getting exported via module.exports it should be good to remove this export keyword!

Copy link
Contributor

Choose a reason for hiding this comment

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

full error I got:

🚫  Unable to get your app manifest details. Please check your manifest file: 
A script hook defined in the Slack Configuration file (`slack.json`) returned an error (sdk_hook_invocation_failed)

Error Details:

1: Command for 'manifest' returned an error: exit status 1
/Users/ashley.huynh/Documents/Forked/bolt-js/src/cli/hook-utils/manifest.js:8
export function unionMerge(array1, array2) {
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1049:15)
    at Module._compile (node:internal/modules/cjs/loader:1084:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
    at Module.load (node:internal/modules/cjs/loader:998:32)
    at Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1022:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/ashley.huynh/Documents/Forked/bolt-js/src/cli/hook-utils/get-manifest-data.js:7:5)
    at Module._compile (node:internal/modules/cjs/loader:1120:14)

Node.js v18.7.0 

Suggestion:

Try to run `slack doctor` to check that your system dependencies are up-to-date.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch @ashleymcm 🙇‍♀️ - I've updated to remove the unnecessary export

@@ -16,12 +21,16 @@ function readManifestJSONFile(searchDir, filename) {
manifestJSON = JSON.parse(fs.readFileSync(jsonFilePath, 'utf8'));
}
} catch (error) {
return;
return null;
Copy link
Member Author

Choose a reason for hiding this comment

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

Now this is properly returning null instead of undefined

@srajiang srajiang changed the title [HERMES-3750] get-manifest hook throws coded error [HERMES-3750] Fix bug where missing .js file results in JSON.parse error Sep 13, 2022
@srajiang srajiang merged commit 414b420 into next-gen Sep 13, 2022
@srajiang srajiang deleted the next-gen-manifest-hook branch September 13, 2022 17:48
srajiang added a commit that referenced this pull request Sep 13, 2022
…ror (#1587)

* Handle missing imported manifest (.js)
* Add tests for getManifestData()
srajiang added a commit that referenced this pull request Sep 28, 2022
…ror (#1587)

* Handle missing imported manifest (.js)
* Add tests for getManifestData()
hello-ashleyintech pushed a commit that referenced this pull request Oct 14, 2022
…ror (#1587)

* Handle missing imported manifest (.js)
* Add tests for getManifestData()
srajiang added a commit that referenced this pull request Nov 11, 2022
…ror (#1587)

* Handle missing imported manifest (.js)
* Add tests for getManifestData()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented tests M-T: Testing work only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants