Skip to content

Commit

Permalink
📝 Update coverage script to update github tracking issue (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliencrn authored Jan 16, 2024
1 parent dda658b commit d3bb3a8
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 34 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,6 @@ Big thanks goes to these wonderful people ❤️

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification ([emoji key](https://allcontributors.org/docs/en/emoji-key)). Contributions of any kind welcome!

## 🚗 Roadmap

- Unit-test all hooks
- Add more hooks

## 📝 License

This project is [MIT](https://github.com/juliencrn/usehooks-ts/blob/master/LICENSE) licensed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"format": "prettier --write \"**/*.{json,md,mdx,css,scss,yaml,yml}\"",
"lint": "turbo run lint",
"types-check": "turbo run types-check",
"test:coverage": "zx ./scripts/coverage.mjs",
"update-testing-issue": "zx ./scripts/updateTestingIssue.mjs",
"update-readme": "zx ./scripts/updateReadme.mjs",
"copy-hooks": "rimraf -rf ./apps/www/generated && zx ./scripts/copyHooks.mjs",
"gen-hook": "turbo gen hook && pnpm format",
Expand Down
28 changes: 0 additions & 28 deletions scripts/coverage.mjs

This file was deleted.

80 changes: 80 additions & 0 deletions scripts/updateTestingIssue.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env zx

import { path, fs, $ } from 'zx'

import { isHookFile } from './utils.mjs'

const GITHUB_REPO = `juliencrn/usehooks-ts`
const GITHUB_ISSUE_PATH = `${GITHUB_REPO}/issues/423`
const hookDir = path.resolve('./packages/usehooks-ts/src')

function generateHookListBody() {
const initialState = {
body: '',
total: 0,
hasTestCount: 0,
}
const testFileRegex = new RegExp(`\.test\.ts$`)
return fs
.readdirSync(hookDir)
.filter(isHookFile)
.reduce((acc, filename) => {
const subFiles = fs.readdirSync(path.resolve(hookDir, filename))
const hasTest = !!subFiles.find(name => testFileRegex.test(name))
const url = `https://github.com/${GITHUB_REPO}/tree/master/packages/usehooks-ts/src/${filename}`
const newLine = `- [${hasTest ? 'x' : ' '}] [\`${filename}\`](${url})\n`
return {
body: `${acc.body}${newLine}`,
total: acc.total + 1,
testedCount: hasTest ? acc.testedCount + 1 : acc.testedCount,
}
}, initialState)
}

function issueTemplate(body) {
return `## Overview
This GitHub issue serves as a central hub for the unit-testing journey of our React hook library. Our goal is to ensure robust and reliable testing for each individual hook in the library.
## Objectives
1. **Comprehensive Testing**: Write unit tests for each hook to ensure thorough coverage of functionality.
2. **Consistent Test Structure**: Maintain a consistent structure/format for unit tests across all hooks.
3. **Documentation**: Document the purpose and usage of each test to enhance overall project understanding.
## Getting Started
1. Fork the repository to your account.
2. Create a new branch for your tests: git checkout -b feature/hook-name-tests.
3. Write tests for the specific hook in \`packages/usehooks-ts/src/useExample/useExample.test.ts\`.
4. Ensure all tests pass before submitting a pull request.
## Hooks to Test
${body}
Let's ensure our hooks are well-tested and reliable!`
}

async function main() {
try {
const { body, total, testedCount } = generateHookListBody()
const url = `https://github.com/${GITHUB_ISSUE_PATH}`
const state = total === testedCount ? 'closed' : 'open'

await $`gh api \
--method PATCH \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${GITHUB_ISSUE_PATH} \
-f body=${issueTemplate(body)} \
-f state=${state}
`

console.log(`\n\n✅ Issue successfully updated! -> ${url}`)
} catch (error) {
console.error('\n❌ Something failed', error)
}
}

await main()

0 comments on commit d3bb3a8

Please sign in to comment.