Skip to content

Commit 8a56587

Browse files
authored
Improve devcontainer for running tests (mastodon#22277)
* Improve devcontainer for running tests - Pull devcontainer post-create out into its own script - Add asset precompilation - Add test-mode asset precompilation (needed to run tests without error) * Document Gemfile.lock re-checkout in devcontainer
1 parent 726c7de commit 8a56587

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

.devcontainer/devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"forwardPorts": [3000, 4000],
2121

2222
// Use 'postCreateCommand' to run commands after the container is created.
23-
"postCreateCommand": "bundle install --path vendor/bundle && yarn install && git checkout -- Gemfile.lock && ./bin/rails db:setup",
23+
"postCreateCommand": ".devcontainer/post-create.sh",
2424

2525
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
2626
"remoteUser": "vscode"

.devcontainer/post-create.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -e # Fail the whole script on first error
4+
5+
# Fetch Ruby gem dependencies
6+
bundle install --path vendor/bundle --with='development test'
7+
8+
# Fetch Javascript dependencies
9+
yarn install
10+
11+
# Make Gemfile.lock pristine again
12+
git checkout -- Gemfile.lock
13+
14+
# [re]create, migrate, and seed the test database
15+
RAILS_ENV=test ./bin/rails db:setup
16+
17+
# Precompile assets for development
18+
RAILS_ENV=development ./bin/rails assets:precompile
19+
20+
# Precompile assets for test
21+
RAILS_ENV=test NODE_ENV=tests ./bin/rails assets:precompile

0 commit comments

Comments
 (0)