Skip to content

Commit

Permalink
Fix YARN_ENABLE_OFFLINE_MODE
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessByte committed Jul 29, 2024
1 parent 4bbf2e1 commit e425038
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
35 changes: 20 additions & 15 deletions bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,7 @@ local_configuration_file="${INPUT}.exercism/config.json"
mkdir -p "${OUTPUT}"

if [[ "${INPUT}" -ef "${OUTPUT}" ]]; then
echo "${INPUT} matches ${OUTPUT}. Not copying anything."

# Rename babel.config.js and package.json
if test -f "${OUTPUT}babel.config.js"; then
mv "${OUTPUT}babel.config.js" "${OUTPUT}babel.config.js.__exercism.bak" || true
fi;

if test -f "${OUTPUT}package.json"; then
mv "${OUTPUT}package.json" "${OUTPUT}package.json.__exercism.bak" || true
fi;
echo "${INPUT} matches ${OUTPUT}. Not copying input to output."
else
echo "Copying ${INPUT} to ${OUTPUT}."
cp -r "${INPUT}/." "${OUTPUT}"
Expand All @@ -134,6 +125,22 @@ else
if test -f "${OUTPUT}package.json"; then
mv "${OUTPUT}package.json" "${OUTPUT}package.json.__exercism.bak" || true
fi;
fi

# Rename babel.config.js and package.json
echo "Disabling babel.config.js and package.json from input, if any"
if test -f "${OUTPUT}babel.config.js"; then
mv "${OUTPUT}babel.config.js" "${OUTPUT}babel.config.js.__exercism.bak" || true
fi;

if test -f "${OUTPUT}package.json"; then
mv "${OUTPUT}package.json" "${OUTPUT}package.json.__exercism.bak" || true
fi;

if [[ "${OUTPUT}" =~ "$ROOT" ]]; then
echo "Test runnner root contains output directory. No need to turn output directory into a standalone package."
else
echo "Test runnner root does not contain output directory. Turning output directory into a standalone package."

# Turn into standalone package
cp "${ROOT}/package.json" "${OUTPUT}package.json"
Expand All @@ -155,9 +162,6 @@ fi;

if test -d "${OUTPUT}node_modules"; then
echo "Did not expect node_modules in output directory, but here we are"
# else
# ln -s "${ROOT}/node_modules" "${OUTPUT}node_modules"
# echo "Symlinked ${OUTPUT}node_modules (${ROOT}/node_modules)"
fi;

# Put together the path to the test results file
Expand All @@ -166,6 +170,7 @@ result_file="${OUTPUT}results.json"
# Check yarn
yarn -v
if test -f "${OUTPUT}package.json"; then
echo "Standalone package found, installing packages from cache"
cd "${OUTPUT}" && YARN_ENABLE_OFFLINE_MODE=1 yarn workspaces focus --production
fi;

Expand All @@ -182,7 +187,7 @@ if test -f "${OUTPUT}tsconfig.json"; then
fi;

echo "Running tsc"
tsc_result="$( cd "${OUTPUT}" && "yarn tsc" --noEmit 2>&1 )"
tsc_result="$( cd "${OUTPUT}" && "YARN_ENABLE_OFFLINE_MODE=1 yarn run tsc" --noEmit 2>&1 )"
test_exit=$?

echo "$tsc_result" > $result_file
Expand Down Expand Up @@ -227,7 +232,7 @@ else
fi

# Run tests
cd "${OUTPUT}" && yarn run jest "${OUTPUT}*" \
cd "${OUTPUT}" && YARN_ENABLE_OFFLINE_MODE=1 yarn run jest "${OUTPUT}*" \
--bail 1 \
--ci \
--colors \
Expand Down
4 changes: 3 additions & 1 deletion test/asserts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { join, sep } from 'node:path'
import { tmpdir } from 'node:os'
import { run, root } from './paths.mjs'

const SILENT = true

export function assertPass(slug, fixture, outputDir = '') {
outputDir = outputDir || mkdtempSync(join(tmpdir(), 'foo-'))
outputDir = fixture
Expand All @@ -27,7 +29,7 @@ export function assertPass(slug, fixture, outputDir = '') {
// shelljs.echo(`-> ${command}`)
const { stderr, code } = shelljs.exec(command, {
async: false,
silent: true,
silent: SILENT,
cwd: root,
})

Expand Down

0 comments on commit e425038

Please sign in to comment.