-
Notifications
You must be signed in to change notification settings - Fork 1
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 jest recipe #4
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
92ded7b
feat: add jest recipe
km1chno 9ff23d6
chore: use p-map for processing chain of promises
km1chno 2055460
Merge branch 'main' into feat-add-jest-recipe
km1chno 3e352eb
chore: remove duplicate esModuleInterop param from tsconfig
km1chno 1e39c1e
revert tsconfig changes
km1chno a6f34f5
chore: changes from comments
km1chno 7ddc6c5
chore: extract sequential promise map to utilities
km1chno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { GluegunToolbox } from 'gluegun' | ||
|
||
module.exports = (toolbox: GluegunToolbox) => { | ||
const { filesystem, packageManager, print } = toolbox | ||
|
||
const exists = (name: string, dev: boolean) => { | ||
km1chno marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const packageJSON = filesystem.read('package.json', 'json') | ||
return ( | ||
(!dev && packageJSON?.dependencies[name]) || | ||
(dev && packageJSON?.devDependencies[name]) | ||
maciekstosio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
} | ||
|
||
const add = async (name: string, dev: boolean) => { | ||
km1chno marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (exists(name, dev)) { | ||
print.info(`${name} already installed, skipping adding dependency.`) | ||
return | ||
} | ||
|
||
const spinner = print.spin( | ||
`📦 Installing ${name} as ${dev ? 'devDependency' : 'dependency'}...` | ||
) | ||
|
||
await packageManager.add(name, { dev }) | ||
|
||
spinner.stop() | ||
|
||
print.info(`✔ Installed ${name}.`) | ||
} | ||
|
||
toolbox.dependencies = { | ||
exists, | ||
add, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { GluegunToolbox } from 'gluegun' | ||
|
||
module.exports = (toolbox: GluegunToolbox) => { | ||
const { patching, print } = toolbox | ||
|
||
const add = async (name: string, command: string) => { | ||
await patching.update('package.json', (config) => { | ||
if (config.scripts[name]) { | ||
return config | ||
} | ||
|
||
config.scripts[name] = command | ||
|
||
print.info(`✔ Added script "${name}": "${command}" to package.json.`) | ||
}) | ||
} | ||
|
||
toolbox.scripts = { add } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { confirm } from '@clack/prompts' | ||
import { Toolbox } from 'gluegun/build/types/domain/toolbox' | ||
|
||
const COMMAND = 'jest' | ||
|
||
const execute = () => async (toolbox: Toolbox) => { | ||
await toolbox.dependencies.add('jest', '', true) | ||
km1chno marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
await toolbox.scripts.add('test', 'jest') | ||
|
||
await toolbox.template.generate({ | ||
template: 'jest.ejf', | ||
target: `.github/workflows/jest.yml`, | ||
}) | ||
|
||
toolbox.print.info('✔ Created Jest workflow.') | ||
|
||
return `--${COMMAND}` | ||
} | ||
|
||
const run = async ( | ||
toolbox: Toolbox | ||
): Promise<(toolbox: Toolbox) => Promise<string> | null> => { | ||
if (toolbox.skipInteractiveForCommand(COMMAND)) { | ||
return execute() | ||
} | ||
|
||
const proceed = await confirm({ | ||
message: 'Do you want to run Jest on your project on every PR?', | ||
}) | ||
|
||
if (!proceed) { | ||
return | ||
} | ||
|
||
return execute() | ||
} | ||
|
||
export default run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Run Jest tests | ||
on: [pull_request] | ||
|
||
jobs: | ||
test: | ||
name: Jest | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: 📦 Install dependencies | ||
run: yarn | ||
|
||
- name: 🎭 Run Jest | ||
run: yarn test |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last think, let's put it in some utils (not necessarly extension as I think it's not strictly related tool for CLI)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extracted to
/src/utils/sequentialPromiseMap.ts
in 7ddc6c5