Skip to content

Commit

Permalink
test: run e2e adapters in monorepo setup
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Jun 4, 2024
1 parent 4bbd43e commit 520635d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 14 deletions.
20 changes: 19 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ commands:
slices:
type: boolean
default: true # allow disabling it later when setting up partial hydration tests
pre_gatsby_dev_command:
type: string
default: ""
steps:
- checkout
# In case of failure, add these steps again. Cache probably got deleted
Expand Down Expand Up @@ -164,7 +167,7 @@ commands:
command: yarn global add gatsby-dev-cli@next --ignore-engines
- run:
name: Run tests (using defaults)
command: ./scripts/e2e-test.sh "<< parameters.test_path >>" "<< parameters.test_command >>"
command: ./scripts/e2e-test.sh "<< parameters.test_path >>" "<< parameters.test_command >>" "<< parameters.pre_gatsby_dev_command >>"

version: 2.1

Expand Down Expand Up @@ -507,6 +510,19 @@ jobs:
- store_test_results:
path: e2e-tests/adapters/cypress/results

e2e_tests_adapters_monorepo:
<<: *e2e-executor
docker:
- image: cypress/browsers:node-18.16.1-chrome-114.0.5735.133-1-ff-114.0.2-edge-114.0.1823.51-1
steps:
- run: echo 'export CYPRESS_RECORD_KEY="${CY_CLOUD_ADAPTERS}"' >> "$BASH_ENV"
- e2e-test:
test_path: e2e-tests/adapters
test_command: cd workspace; gatsby-dev --force-install --scan-once; cd ..; yarn test
pre_gatsby_dev_command: ./make-monorepo.sh
- store_test_results:
path: e2e-tests/adapters/cypress/results

starters_validate:
executor: node
steps:
Expand Down Expand Up @@ -708,6 +724,8 @@ workflows:
<<: *e2e-test-workflow
- e2e_tests_adapters:
<<: *e2e-test-workflow
- e2e_tests_adapters_monorepo:
<<: *e2e-test-workflow
- e2e_tests_development_runtime_with_react_18:
<<: *e2e-test-workflow
- e2e_tests_production_runtime_with_react_18:
Expand Down
26 changes: 26 additions & 0 deletions e2e-tests/adapters/make-monorepo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# this script will make checked out files move around and make git working directory dirty
# this is primarly for setting up monorepo structure for e2e tests that run in CI to avoid
# having to maintain additional fixture as we want to test all the same things as in single repo
# case

# move all items in the current directory to a new directory called workspace
rm -rf workspace
items=(*)
mkdir workspace
mv ${items[*]} workspace

# create root package.json and mark workspace directory as a npm/yarn workspace
echo '{ "workspaces": ["workspace"], "scripts": { "test": "EXTRA_NTL_CLI_ARGS=\"--filter=workspace\" E2E_MONOREPO=\"true\" npm run test -w workspace" }, "private": true }' > package.json

# update netlify.toml build command and publish dir
sed -i.bak -e 's/npm run build/npm run build -w workspace/g' -e 's/public/workspace\/public/g' workspace/netlify.toml

# update workspace package.json
sed -i.bak -e 's/..\/..\/scripts\/cypress-run-with-conditional-record-flag.js/..\/..\/..\/scripts\/cypress-run-with-conditional-record-flag.js/g' workspace/package.json

git init

# debug
find . -type f
15 changes: 8 additions & 7 deletions e2e-tests/adapters/netlify.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[build]
command = "npm run build"
publish = "public/"
command = "npm run build"
publish = "public/"
base = ""

[build.environment]
NETLIFY_IMAGE_CDN = "true"
NETLIFY_IMAGE_CDN = "true"

[images]
remote_images = [
"https://images.unsplash.com/.*",
"https://www.gatsbyjs.com/.*",
]
remote_images = [
"https://images.unsplash.com/.*",
"https://www.gatsbyjs.com/.*",
]
6 changes: 3 additions & 3 deletions e2e-tests/adapters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"cy:open": "cypress open --browser chrome --e2e",
"develop:debug": "start-server-and-test develop http://localhost:8000 'npm run cy:open -- --config baseUrl=http://localhost:8000'",
"ssat:debug": "start-server-and-test serve http://localhost:9000 cy:open",
"test:template": "cross-env-shell CYPRESS_GROUP_NAME=\"adapter:$ADAPTER / trailingSlash:${TRAILING_SLASH:-always} / pathPrefix:${PATH_PREFIX:--}\" TRAILING_SLASH=$TRAILING_SLASH PATH_PREFIX=$PATH_PREFIX node ../../scripts/cypress-run-with-conditional-record-flag.js --browser chrome --e2e --config-file \"cypress/configs/$ADAPTER.ts\" --env TRAILING_SLASH=$TRAILING_SLASH,PATH_PREFIX=$PATH_PREFIX",
"test:template:debug": "cross-env-shell CYPRESS_GROUP_NAME=\"adapter:$ADAPTER / trailingSlash:${TRAILING_SLASH:-always} / pathPrefix:${PATH_PREFIX:--} / excludeDatastoreFromBundle:${GATSBY_EXCLUDE_DATASTORE_FROM_BUNDLE:-false}\" TRAILING_SLASH=$TRAILING_SLASH PATH_PREFIX=$PATH_PREFIX npm run cy:open -- --config-file \"cypress/configs/$ADAPTER.ts\" --env TRAILING_SLASH=$TRAILING_SLASH,PATH_PREFIX=$PATH_PREFIX",
"test:template": "cross-env-shell CYPRESS_GROUP_NAME=\"adapter:$ADAPTER / trailingSlash:${TRAILING_SLASH:-always} / pathPrefix:${PATH_PREFIX:--} / excludeDatastoreFromBundle:${GATSBY_EXCLUDE_DATASTORE_FROM_BUNDLE:-false} / monorepo:${E2E_MONOREPO:-false}\" TRAILING_SLASH=$TRAILING_SLASH PATH_PREFIX=$PATH_PREFIX node ../../scripts/cypress-run-with-conditional-record-flag.js --browser chrome --e2e --config-file \"cypress/configs/$ADAPTER.ts\" --env TRAILING_SLASH=$TRAILING_SLASH,PATH_PREFIX=$PATH_PREFIX",
"test:template:debug": "cross-env-shell CYPRESS_GROUP_NAME=\"adapter:$ADAPTER / trailingSlash:${TRAILING_SLASH:-always} / pathPrefix:${PATH_PREFIX:--} / excludeDatastoreFromBundle:${GATSBY_EXCLUDE_DATASTORE_FROM_BUNDLE:-false} / monorepo:${E2E_MONOREPO:-false}\" TRAILING_SLASH=$TRAILING_SLASH PATH_PREFIX=$PATH_PREFIX npm run cy:open -- --config-file \"cypress/configs/$ADAPTER.ts\" --env TRAILING_SLASH=$TRAILING_SLASH,PATH_PREFIX=$PATH_PREFIX",
"test:debug": "npm-run-all -s build:debug ssat:debug",
"test:netlify": "cross-env TRAILING_SLASH=always node scripts/deploy-and-run/netlify.mjs test:template",
"test:smoke": "node smoke-test.mjs",
Expand All @@ -38,7 +38,7 @@
"dotenv": "^8.6.0",
"execa": "^6.1.0",
"gatsby-cypress": "^3.13.0",
"netlify-cli": "^17.9.0",
"netlify-cli": "^17.25.0",
"npm-run-all": "^4.1.5",
"start-server-and-test": "^2.0.3",
"typescript": "^5.3.3"
Expand Down
15 changes: 12 additions & 3 deletions e2e-tests/adapters/scripts/deploy-and-run/netlify.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ const npmScriptToRun = process.argv[2] || "test:netlify"
await execa(`npm`, [`run`, `clean`], { stdio: `inherit` })

const deployResults = await execa(
"ntl",
["deploy", "--build", "--json", "--cwd=.", "--message", deployTitle],
"npx",
[
"ntl",
"deploy",
"--build",
"--json",
"--message",
deployTitle,
process.env.EXTRA_NTL_CLI_ARGS ?? "--cwd=.",
],
{
reject: false,
}
Expand Down Expand Up @@ -49,7 +57,8 @@ try {
} finally {
if (!process.env.GATSBY_TEST_SKIP_CLEANUP) {
console.log(`Deleting project with deploy_id ${deployInfo.deploy_id}`)
const deleteResponse = await execa("ntl", [
const deleteResponse = await execa("npx", [
"ntl",
"api",
"deleteDeploy",
"--data",
Expand Down
6 changes: 6 additions & 0 deletions scripts/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set -e # bail on errors

SRC_PATH=$1
CUSTOM_COMMAND="${2:-yarn test}"
PRE_GATSBY_DEV_COMMAND="${3:-}"
eval GATSBY_PATH=${CIRCLE_WORKING_DIRECTORY:-../..}
TMP_LOCATION=$(mktemp -d);

Expand All @@ -22,6 +23,11 @@ cp -Rv $GATSBY_PATH/scripts/. $TMP_LOCATION/scripts/
# setting up child integration test link to gatsby packages
cd "$TMP_TEST_LOCATION"

if [[ $PRE_GATSBY_DEV_COMMAND != "" ]]; then
echo "Running pre-gatsby-dev command: $PRE_GATSBY_DEV_COMMAND"
sh -c "$PRE_GATSBY_DEV_COMMAND"
fi

gatsby-dev --set-path-to-repo "$GATSBY_PATH"
gatsby-dev --force-install --scan-once # Do not copy files, only install through npm, like our users would
if test -f "./node_modules/.bin/gatsby"; then
Expand Down

0 comments on commit 520635d

Please sign in to comment.