-
Notifications
You must be signed in to change notification settings - Fork 992
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port test-tutorial script to JS (#1896)
* Port test-tutorial script to JS * Remove todos * PR Review comments * Apply suggestions from code review Co-authored-by: Peter Pistorius <peter.pistorius@gmail.com> * Fix comma position * Update based on github workflow file * Additional logging by default | Throw properly in script * Adopt new logic for ☁️ e2e * Dont link when not creatingProject * handle edge case reset for existing projects * fix broken linking logic Co-authored-by: Peter Pistorius <peter.pistorius@gmail.com> Co-authored-by: David S Price <thedavid@thedavidprice.com>
- Loading branch information
1 parent
f39a8bb
commit df8d0c2
Showing
3 changed files
with
127 additions
and
64 deletions.
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 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 |
---|---|---|
@@ -1,60 +1,2 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
realpath() { | ||
path=`eval echo "$1"` | ||
folder=$(dirname "$path") | ||
echo $(cd "$folder"; pwd)/$(basename "$path"); | ||
} | ||
|
||
SCRIPT=`realpath $0` | ||
SCRIPTPATH=`dirname $SCRIPT` | ||
|
||
# Install the dependencies required to run the e2e tests. | ||
cd "$SCRIPTPATH/e2e" | ||
yarn install | ||
|
||
if [ -z "$1" ] | ||
then | ||
echo "You have not supplied a path to a RedwoodJS project." | ||
echo "We will create one for you." | ||
echo "We will copy './packages/create-redwood-app/template' and the packages/*" | ||
TMP_DIR=$(mktemp -d -t redwood) | ||
else | ||
echo "You have supplied a path $1, we will not create a new " | ||
echo "Redwood project, we will use the app you have specified." | ||
TMP_DIR=$1 | ||
fi | ||
|
||
if [[ -z "$1" || "$CREATE_RWJS_PROJECT" == "1" ]] | ||
then | ||
echo "Creating new RedwoodJS Project..." | ||
cd ../../packages/create-redwood-app | ||
yarn babel-node src/create-redwood-app.js $TMP_DIR --no-yarn-install | ||
fi | ||
|
||
if [[ -z "$1" || "$CREATE_RWJS_PROJECT" == "1" ]] | ||
then | ||
cd "$SCRIPTPATH/../" | ||
# build all the packages, but not the TypeScript | ||
# since it is slow and we do not need it. | ||
yarn build:clean && yarn lerna run build:js | ||
fi | ||
|
||
cd $TMP_DIR | ||
|
||
if [[ -z "$1" || "$CREATE_RWJS_PROJECT" == "1" ]]; | ||
then | ||
echo "Linking packages from $SCRIPTPATH" | ||
# make the e2e tests use the packages from this Redwood Framework Repo. | ||
ln -s "$SCRIPTPATH/../packages" | ||
fi | ||
|
||
yarn install | ||
|
||
if [ -z "$CI" ] | ||
then | ||
yarn rw dev --fwd="--open=false" & cd "$SCRIPTPATH/e2e"; yarn cypress open --env RW_PATH=$TMP_DIR | ||
else | ||
echo "CI env-var set skipping Cypress run." | ||
fi | ||
yarn babel-node tasks/test-tutorial.js $1 |
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,122 @@ | ||
/* eslint-env node, es6*/ | ||
|
||
import fs from 'fs' | ||
import os from 'os' | ||
import path from 'path' | ||
|
||
import execa from 'execa' | ||
|
||
const createNewRedwoodProject = async (projectPath, frameworkPath) => { | ||
console.log( | ||
'------------------------ start create redwood app -------------------------' | ||
) | ||
await execa( | ||
'yarn babel-node', | ||
['src/create-redwood-app.js', projectPath, '--no-yarn-install'], | ||
{ | ||
cwd: path.join(frameworkPath, 'packages/create-redwood-app'), | ||
shell: true, | ||
stdio: 'inherit', | ||
} | ||
) | ||
} | ||
|
||
const testTutorial = async () => { | ||
// First two args are "node" and path to script | ||
const [, , pathToProject] = process.argv | ||
|
||
let projectPath = pathToProject | ||
const frameworkPath = path.join(__dirname, '..') | ||
const e2ePath = path.join(frameworkPath, 'tasks/e2e') | ||
const shouldCreateNewProject = process.env.CREATE_RWJS_PROJECT === '1' | ||
|
||
console.log(`📁 ~ projectPath`, projectPath) | ||
console.log(`🌲 ~ frameworkPath`, frameworkPath) | ||
console.log(`🚀 ~ e2ePath`, e2ePath) | ||
|
||
try { | ||
await execa('yarn install', { | ||
cwd: e2ePath, | ||
shell: true, | ||
stdio: 'inherit', | ||
}) | ||
|
||
if (pathToProject) { | ||
console.log('🗂️ You have supplied the path "${projectPath}" \n') | ||
|
||
// For e2e tests in CI | ||
if (shouldCreateNewProject) { | ||
createNewRedwoodProject(projectPath, frameworkPath) | ||
} else { | ||
// Normally when a path is specified, no need to create a new project | ||
console.log( | ||
[ | ||
'Assuming pre-existing Redwood project', | ||
'Not creating a new one', | ||
].join('\n') | ||
) | ||
} | ||
} else { | ||
console.log('\n ℹ️ You have not supplied a path to a Redwood project.') | ||
console.log('We will create one for you. \n \n') | ||
console.log( | ||
"📋 We will copy './packages/create-redwood-app/template' and link packages/* \n" | ||
) | ||
|
||
// Use temporary project path, because no user supplied one | ||
projectPath = fs.mkdtempSync(path.join(os.tmpdir(), 'redwood-e2e-')) | ||
|
||
createNewRedwoodProject(projectPath, frameworkPath) | ||
} | ||
|
||
const packagesPath = path.join(frameworkPath, 'packages') | ||
|
||
// Clean, Build, and Link packages from framework, but only if creating a new one | ||
if (!pathToProject || shouldCreateNewProject) { | ||
await execa('yarn build:clean && yarn lerna run build:js', { | ||
cwd: frameworkPath, | ||
shell: true, | ||
stdio: 'inherit', | ||
}) | ||
|
||
fs.symlinkSync(packagesPath, path.join(projectPath, 'packages')) | ||
} | ||
|
||
await execa('yarn install', { | ||
shell: true, | ||
stdio: 'inherit', | ||
cwd: projectPath, | ||
}) | ||
|
||
// Make sure rw dev can run | ||
fs.chmodSync(path.join(projectPath, 'node_modules/.bin/rw'), '755') | ||
|
||
if (process.env.CI) { | ||
console.log( | ||
'\n ⏩ Skipping cypress and dev server launch, handled by github workflow' | ||
) | ||
} else { | ||
await execa('yarn rw dev --fwd="--open=false" &', { | ||
shell: true, | ||
stdio: 'inherit', | ||
cwd: projectPath, | ||
}) | ||
|
||
// @Note: using env to set RW_PATH does not work correctly | ||
await execa('yarn cypress', ['open', `--env RW_PATH=${projectPath}`], { | ||
shell: true, | ||
stdio: 'inherit', | ||
env: { | ||
...process.env, | ||
}, | ||
cwd: e2ePath, | ||
}) | ||
} | ||
} catch (e) { | ||
console.error('🛑 test-tutorial script failed') | ||
console.error(e) | ||
process.exit(1) | ||
} | ||
} | ||
|
||
testTutorial() |