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 unit tests and refactor nextjs build adaptor to make testing easier #131

Merged
merged 8 commits into from
Jan 3, 2024

Conversation

Yuangwang
Copy link
Collaborator

  • adds unit tests for nextjs adaptor
  • refactors out functions to util directory
  • formatted a couple other files nearby


// move the standalone directory, the static directory and the public directory to apphosting output directory
// as well as generating bundle.yaml
export async function generateOutputBundle(
Copy link
Collaborator

@sjjj986 sjjj986 Dec 18, 2023

Choose a reason for hiding this comment

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

I think this naming is too similar to "generateBundleYaml" and could get confusing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed it to "generateOutputDirectory"

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the major logic for the build adaptor should be mainly in the build file and have some helper functions in utils, rn it seems like all the logic are in utils.ts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I needed to extract the functions out into utils.ts for the code to be testable.
The way that imports work right now is that when you import a file ( for example const importUtils = import("@apphosting/adapter-nextjs/dist/utils.js")) the imported file will be run in its entirety. In our case we don't actually want the whole of build.ts to be run since it will not work properly as it expected to be run in a nextjs app and not this repo.
We don't want build.ts to be run but we still want to be able to import the functions that need to be unit tested so I needed to extract those functions out to a separate file that is okay to be run in its entirety. In this case that is utils.ts

@Yuangwang Yuangwang merged commit d085e8a into main Jan 3, 2024
10 checks passed
@Yuangwang Yuangwang deleted the nextjsadaptor-refactor-tests branch January 25, 2024 20:49
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.

2 participants