Skip to content

Commit

Permalink
Merge pull request #226 from andrewnicols/eslint-relative
Browse files Browse the repository at this point in the history
Ensure that eslint is called relative to the moodleroot
  • Loading branch information
stronk7 authored Oct 13, 2020
2 parents 54536c4 + de3541d commit a491175
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mustache_lint/js_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function run_eslint() {
];

$cmd = "$eslint --stdin --no-eslintrc --config {$this->moodleroot}/.eslintrc --format=json";
$proc = proc_open($cmd, $pipesspec, $pipes);
$proc = proc_open($cmd, $pipesspec, $pipes, $this->moodleroot);
// Send the JS to stdin.
fwrite($pipes[0], $this->js);
fclose($pipes[0]);
Expand Down
40 changes: 40 additions & 0 deletions tests/1-mustache_lint.bats
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,43 @@ setup () {
assert_output --partial "lib/templates/js_test.mustache - WARNING: ESLint warning [camelcase]: Identifier 'my_message' is not in camel case"
assert_output --partial "lib/templates/js_test.mustache - WARNING: ESLint warning [no-alert]: Unexpected alert. ( alert(my_message); )"
}

@test "mustache_lint: Test eslint runs ok when invoked from any directory" {

# We need to use recent version here, the default 3.1.3 used for tests (that already had eslint)
# did not expose the problem (and it ran ok from any CWD directory).
# TODO: Some day, kill all old-version tests by moving them to 39_STABLE or later.
create_git_branch MOODLE_39_STABLE v3.9.2

# Calculate moodleroot and localciroot.
localciroot=$PWD
moodleroot=${LOCAL_CI_TESTS_GITDIR}

# Install npm depends so we have eslint (sourced).
source ${localciroot}/prepare_npm_stuff/prepare_npm_stuff.sh

# Run normally (from moodleroot).
cd ${moodleroot}
ci_run_php mustache_lint/mustache_lint.php --filename="${moodleroot}/lib/templates/inplace_editable.mustache" \
--basename="${moodleroot}" --validator="${localciroot}/node_modules/vnu-jar/build/dist/vnu.jar"
assert_success
refute_output --partial "INFO: ESLint did not run"
refute_output --partial "was not found when loaded as a Node module"

# Run also from another dir within moodleroot.
cd ${moodleroot}/mod/forum
ci_run_php mustache_lint/mustache_lint.php --filename="${moodleroot}/lib/templates/inplace_editable.mustache" \
--basename="${moodleroot}" --validator="${localciroot}/node_modules/vnu-jar/build/dist/vnu.jar"
assert_success
refute_output --partial "INFO: ESLint did not run"
refute_output --partial "was not found when loaded as a Node module"

# Let's switch to any other directory (out from moodleroot).
cd ${moodleroot}/..
ci_run_php mustache_lint/mustache_lint.php --filename="${moodleroot}/lib/templates/inplace_editable.mustache" \
--basename="${moodleroot}" --validator="${localciroot}/node_modules/vnu-jar/build/dist/vnu.jar"
assert_success
refute_output --partial "INFO: ESLint did not run"
refute_output --partial "was not found when loaded as a Node module"
refute_output --partial "${LOCAL_CI_TESTS_CACHEDIR}"
}

0 comments on commit a491175

Please sign in to comment.