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

feat: add code testing #585

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

heyAyushh
Copy link
Contributor

Problem

This PR introduces testing for snippets imported in markdown using code-import.

Summary of Changes

  • Seperated code files for cookbook wallet section
  • setup pnpm workspace
  • turborepo monorepo (in case code folder grows with multiple projects (react testing, mobile testing etc))
  • added tests with node:test
  • added GitHub Actions for testing only changed scripts on PR and all tests on schedule

Fixes #

  • Bug in code-import where It failed when line ranges weren't mentioned

@heyAyushh heyAyushh requested a review from nickfrosty as a code owner October 25, 2024 00:44
@@ -11,7 +11,7 @@ are [connecting to a wallet](/content/cookbook/wallets/connect-wallet-react),
you do not need to worry about the keypair. Otherwise a keypair must be
generated for signing transactions.

```javascript
```javascript file=/code/content/cookbook/wallets/create-keypair.ts#L1-L3
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you double check the content displays correctly on solana-com. It looks like if you don't include a filename for a snippet, the provided file path gets used.

CleanShot 2024-10-25 at 10 28 20@2x

Also, why is there a file path, but the code block still contains the snippet?

```javascript file=/code/content/cookbook/wallets/create-keypair.ts#L1-L3
import { Keypair } from "@solana/web3.js";

const keypair = Keypair.generate();
```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code block has content for crowdin support i guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be a PR on solana-com?

@ZYJLiu
Copy link
Collaborator

ZYJLiu commented Oct 25, 2024

Can you provide more context on the changes and instructions for how I can test your changes locally? Please include the commands to run.
Is turbo supposed to be included as a dev dependency?

When I ran turbo test I got the following error:

turbo 2.2.3

• Packages in scope: solana-developer-content-api, solana-developer-content-code
• Running test in 2 packages
• Remote caching disabled
solana-developer-content-api:build: cache miss, executing 1cb178dcc001b143
solana-developer-content-code:test: cache miss, executing f6823e566d70ef4f
solana-developer-content-api:build: 
solana-developer-content-code:test: 
solana-developer-content-api:build: 
solana-developer-content-api:build: > [email protected] build /developer-content
solana-developer-content-api:build: > pnpm code-import && pnpm prettier:i18n && pnpm contentlayer:build && next build
solana-developer-content-api:build: 
solana-developer-content-code:test: 
solana-developer-content-code:test: > [email protected] test /developer-content/code
solana-developer-content-code:test: > node --import tsx --test '**/*.test.ts' --trace-deprecation
solana-developer-content-code:test: 
solana-developer-content-code:test: Could not find '/developer-content/code/**/*.test.ts'
solana-developer-content-code:test:  ELIFECYCLE  Test failed. See above for more details.
solana-developer-content-code:test: ERROR: command finished with error: command (/developer-content/code) /usr/local/bin/pnpm run test exited (1)
solana-developer-content-code#test: command (/developer-content/code) /usr/local/bin/pnpm run test exited (1)

 Tasks:    0 successful, 2 total
Cached:    0 cached, 2 total
  Time:    383ms 
Failed:    solana-developer-content-code#test

 ERROR  run failed: command  exited (1)

Also the following error if I run pnpm run test in the new /code folder.

> [email protected] test /developer-content/code
> node --import tsx --test '**/*.test.ts' --trace-deprecation

Could not find '/developer-content/code/**/*.test.ts'
 ELIFECYCLE  Test failed. See above for more details.
 ```

@heyAyushh
Copy link
Contributor Author

Can you provide more context on the changes and instructions for how I can test your changes locally? Please include the commands to run. Is turbo supposed to be included as a dev dependency?

When I ran turbo test I got the following error:

turbo 2.2.3

• Packages in scope: solana-developer-content-api, solana-developer-content-code
• Running test in 2 packages
• Remote caching disabled
solana-developer-content-api:build: cache miss, executing 1cb178dcc001b143
solana-developer-content-code:test: cache miss, executing f6823e566d70ef4f
solana-developer-content-api:build: 
solana-developer-content-code:test: 
solana-developer-content-api:build: 
solana-developer-content-api:build: > [email protected] build /developer-content
solana-developer-content-api:build: > pnpm code-import && pnpm prettier:i18n && pnpm contentlayer:build && next build
solana-developer-content-api:build: 
solana-developer-content-code:test: 
solana-developer-content-code:test: > [email protected] test /developer-content/code
solana-developer-content-code:test: > node --import tsx --test '**/*.test.ts' --trace-deprecation
solana-developer-content-code:test: 
solana-developer-content-code:test: Could not find '/developer-content/code/**/*.test.ts'
solana-developer-content-code:test:  ELIFECYCLE  Test failed. See above for more details.
solana-developer-content-code:test: ERROR: command finished with error: command (/developer-content/code) /usr/local/bin/pnpm run test exited (1)
solana-developer-content-code#test: command (/developer-content/code) /usr/local/bin/pnpm run test exited (1)

 Tasks:    0 successful, 2 total
Cached:    0 cached, 2 total
  Time:    383ms 
Failed:    solana-developer-content-code#test

 ERROR  run failed: command  exited (1)

Also the following error if I run pnpm run test in the new /code folder.

> [email protected] test /developer-content/code
> node --import tsx --test '**/*.test.ts' --trace-deprecation

Could not find '/developer-content/code/**/*.test.ts'
 ELIFECYCLE  Test failed. See above for more details.
 ```

I added a testing section in Contibuting.md

   pnpm install
   cd code
   pnpm turbo test

let me know if this command doesn't work.

@heyAyushh
Copy link
Contributor Author

This PR resolves the issue where code path was shown on the block as name.

solana-foundation/solana-com#96

Copy link

github-actions bot commented Dec 9, 2024

This pull request has been automatically marked as stale because it has not had recent activity. Remove stale label or comment or this will be closed in 7 days.

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