Skip to content

Commit

Permalink
Ensure no tmpfs for tests if running in docker without exec
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessByte committed Aug 12, 2024
1 parent d652f26 commit c907f7b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ RUN set -ex; \
ENV COREPACK_ENABLE_NETWORK=0
ENV COREPACK_ENABLE_STRICT=0

# Mark this as a docker run so we don't try to execute things in /tmp
ENV TMP_MAY_BE_NON_EXEC=1

# Execute everything as the appuser
USER appuser
ENTRYPOINT [ "/opt/test-runner/bin/run.sh" ]
4 changes: 2 additions & 2 deletions bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ if test -f "${OUTPUT}package.json"; then
fi
fi;

bin_jest="$(corepack pnpm bin)/jest"
bin_jest="$(cd "${COREPACK_ROOT_DIR}" && corepack pnpm bin)/jest"
if [[ -f "${bin_jest}" ]]; then
echo "✔️ jest executable found using ${bin_jest}"

Expand Down Expand Up @@ -352,7 +352,7 @@ echo " ➤ Execution (tests: does the solution work?) "
echo "╚═════════════════════════════════════════════════════════════╝"
echo ""

jest_tests=$(corepack pnpm jest "${OUTPUT}*" --listTests --passWithNoTests) || false
jest_tests=$(cd "${COREPACK_ROOT_DIR}" && corepack pnpm jest "${OUTPUT}*" --listTests --passWithNoTests) || false

if [ -z "${jest_tests}" ]; then
echo "❌ no jest tests (*.spec.js) discovered."
Expand Down
18 changes: 15 additions & 3 deletions test/asserts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { run, root } from './paths.mjs'
const SILENT = process.env.SILENT !== '0' && process.env.RUNNER_DEBUG !== '1'

export function assertPass(slug, fixture, outputDir = null) {
outputDir = outputDir || mkdtempSync(join(tmpdir(), 'foo-'))
outputDir =
outputDir ||
(process.env.process.env.TMP_MAY_BE_NON_EXEC
? fixture
: mkdtempSync(join(tmpdir(), 'assert-pass-')))
const resultPath = join(outputDir, 'results.json')

if (fixture[fixture.length - 1] !== sep) {
Expand Down Expand Up @@ -64,7 +68,11 @@ export function assertPass(slug, fixture, outputDir = null) {
}

export function rejectPass(slug, fixture, outputDir = null) {
outputDir = outputDir || mkdtempSync(join(tmpdir(), 'foo-'))
outputDir =
outputDir ||
(process.env.process.env.TMP_MAY_BE_NON_EXEC
? fixture
: mkdtempSync(join(tmpdir(), 'reject-pass-')))
const resultPath = join(outputDir, 'results.json')

if (fixture[fixture.length - 1] !== sep) {
Expand Down Expand Up @@ -127,7 +135,11 @@ export function rejectPass(slug, fixture, outputDir = null) {
}

export function assertError(slug, fixture, outputDir = null) {
outputDir = outputDir || mkdtempSync(join(tmpdir(), 'foo-'))
outputDir =
outputDir ||
(process.env.process.env.TMP_MAY_BE_NON_EXEC
? fixture
: mkdtempSync(join(tmpdir(), 'assert-error-')))
const resultPath = join(outputDir, 'results.json')

if (fixture[fixture.length - 1] !== sep) {
Expand Down
6 changes: 5 additions & 1 deletion test/log.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { fixtures, root, run } from './paths.mjs'
const SILENT = process.env.SILENT !== '0' && process.env.RUNNER_DEBUG !== '1'

export function assertLog(slug, fixture, outputDir = null) {
outputDir = outputDir || mkdtempSync(join(tmpdir(), 'foo-'))
outputDir =
outputDir ||
(process.env.process.env.TMP_MAY_BE_NON_EXEC
? fixture
: mkdtempSync(join(tmpdir(), 'assert-log-')))
const resultPath = join(outputDir, 'results.json')

if (fixture[fixture.length - 1] !== sep) {
Expand Down
8 changes: 5 additions & 3 deletions test/taskid.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ shelljs.echo(
'javascript-test-runner > passing solution with task ids > with output directory'
)

const outputDir = mkdtempSync(join(tmpdir(), 'foo-'))
const resultPath = join(outputDir, 'results.json')
const slug = 'lasagna'
const fixture = join(fixtures, 'lasagna', 'exemplar')
const fixture = join(fixtures, slug, 'exemplar')
const outputDir = process.env.process.env.TMP_MAY_BE_NON_EXEC
? fixture
: mkdtempSync(join(tmpdir(), 'assert-pass-'))
const resultPath = join(outputDir, 'results.json')

assertPass(slug, fixture, outputDir)

Expand Down

0 comments on commit c907f7b

Please sign in to comment.