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 pnpm command to update snapshot #1647

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ pnpm test:template greeter
rm -fr ../tmp-greeter
```

Snapshots in `templates` can be updated with the following command but note that manual clean up is necessary afterwards

```shell
# greeter being name of template
pnpm test:template:updateSnapshot greeter

# clean up temporary sibling directory
rm -fr ../tmp-greeter
```

### Running locally

If you want to try out the **skuba** CLI on itself,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"test:ci": "pnpm --silent skuba test --runInBand",
"test:int": "pnpm --silent skuba test --selectProjects integration --runInBand",
"test:template": "scripts/test-template.sh",
"test:template:updateSnapshot": "scripts/test-template.sh -u",
"test:watch": "pnpm --silent skuba test --runInBand --watch"
},
"remarkConfig": {
Expand Down
21 changes: 19 additions & 2 deletions scripts/test-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@

set -e

update_snapshot=false

# Process optional flag
if [ "$1" == "-u" ]; then
update_snapshot=true
shift
fi

template="${1}"

echo "--- testing template ${update_snapshot}, ${template}"
if [ -z "$template" ]; then
echo "Usage: pnpm test:template <template_name>"
exit 1
Expand Down Expand Up @@ -81,5 +91,12 @@ pnpm lint
echo "--- pnpm format ${template}"
pnpm format

echo "--- pnpm test ${template}"
pnpm test
if [ "$update_snapshot" = true ]; then
echo "--- pnpm test --updateSnapshot ${template}"
pnpm test -- --updateSnapshot
cd ../../skuba || exit 1
bash ./scripts/update-template-snapshot.sh ${skuba_temp_directory} ${template}
else
echo "--- pnpm test ${template}"
pnpm test
fi
16 changes: 16 additions & 0 deletions scripts/update-template-snapshot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# To be used in conjunction with `test-template.sh`.
# This script copies all snapshot directories from the tmp directory to the template directory.

set -e

tmp_dir="$1"
template="$2"

# Loops through tmp directory created in test-template.sh, ignoring node_modules and only looks at __snapshots__ directories.
find ../${tmp_dir}/tmp-${template} -path '*/node_modules' -prune -o -type d -name '__snapshots__' -print | while read -r src_dir; do
dest_dir=$(echo "$src_dir" | sed "s|../${tmp_dir}/tmp-${template}|template/${template}|")
cp -r $src_dir/ $dest_dir/
done

echo "All snapshot directories have been copied successfully."