Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing rework. Coverage! #273

Merged
merged 21 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:
- name: Run the integration tests.
run: ./scripts/ubik run-tests --type=integration

- name: Run the unit tests, with coverage reporting.
run: ./scripts/ubik run-tests --type=unit-coverage

- name: Ensure the cert creator still works.
run: ./scripts/ubik make-localhost-cert

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Breaking changes:
Other notable changes:
* Development:
* `build` script renamed to `dev`, and merged `run` into it.
* Testing:
* Simplified how the unit tests get set up and run.
* Got coverage reporting to work.
* Linting:
* Added `lint` target to `dev` (see above), and removed the separate `lint`
script.
Expand Down
70 changes: 23 additions & 47 deletions scripts/lib/lactoserv/run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ define-usage --with-help $'
`build` -- Always build, even if there is something already built.
`clean` -- Always do a clean build.
`run` -- Build only if there is nothing yet built. This is the default.
--type=<type> :: `integration` `unit`
Test type to run. By default, runs unit tests.
--type=<type> :: `integration` `unit` `unit-coverage`
Test type to run. By default, runs unit tests (without coverage reporting).
--out=<dir>
Directory where built output goes. Defaults to `out` directly under the
main product directory.
Expand All @@ -30,7 +30,7 @@ define-usage --with-help $'
opt-value --var=action --default=run --enum[]='build clean run' do

# Test type.
opt-value --var=testType --enum[]='integration unit' type
opt-value --var=testType --default=unit --enum[]='integration unit unit-coverage' type

# Built output directory.
opt-value --var=outDir out
Expand Down Expand Up @@ -107,6 +107,8 @@ function run-integration-tests {

# Runs unit tests.
function run-unit-tests {
local jestArgs=("$@")

local configFile
configFile="$(config-file-path)" \
|| exit "$?"
Expand All @@ -115,52 +117,15 @@ function run-unit-tests {
toolPath="$(tester-path)" \
|| exit "$?"

# Find the tests, and generally set up the testing directory.

local testsDir="${outDir}/tests"

rm -rf "${testsDir}"
mkdir -p "${testsDir}"
cd "${testsDir}"
rm -rf node_modules
ln -s ../lactoserv/lib/code/node_modules .
echo >package.json '{ "type": "module" }'

# TODO: Try this to see if Pulsar still messes up syntax highlighting.
#cat >package.json <<< '{ "type": "module" }'

local dirsWithTests
dirsWithTests="$(
lib ls-files --output=array --cd="${srcDir}" --dirs --full-paths \
--include='/tests$')" \
|| exit "$?"

while IFS='' read -r -d $'\0' dir; do
[[ ${dir} =~ /([^/]+)/tests$ ]] || {
error-msg "Weird directory name: ${dir}"
exit 1
}

local moduleName="${BASH_REMATCH[1]}"
cp -r "${dir}" "${testsDir}/${moduleName}"
done < <(jget --output=raw0 "${dirsWithTests}" '.[]')

# Copy the config file into place, where it will be found when the test
# harness is run.
cp "${configFile}" "${testsDir}"
configFile="${testsDir}/$(basename "${configFile}")"

# Run the tool!

"${toolPath}" --config="${configFile}" "${args[@]}" \
"${toolPath}" --config="${configFile}" "${jestArgs[@]}" "${args[@]}" \
|| return "$?"
}

# Builds the tester if necessary, and then prints the path to it main binary.
function tester-path {
local toolModule=tester
local toolDir="${outDir}/${toolModule}"
local toolPath="${toolDir}/bin/tester"
local toolPath="${toolDir}/bin/jest"

# Build the tester, if necessary.
if [[ ! -x ${toolPath} ]]; then
Expand All @@ -185,11 +150,22 @@ outDir="$(lib buildy out-dir --out="${outDir}")" \
build-if-necessary "${action}" \
|| exit "$?"

if [[ ${testType} == integration ]]; then
run-integration-tests
else
run-unit-tests
fi
case "${testType}" in
integration)
run-integration-tests
;;
unit)
run-unit-tests
;;
unit-coverage)
run-unit-tests --coverage
;;
*)
# Shouldn't happen. Bug in this script.
error-msg "Unknown type: ${testType}"
false
;;
esac

status="$?"

Expand Down
2 changes: 1 addition & 1 deletion src/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export default [
'error',
{
...stylisticRules['@stylistic/max-len'][1],
comments: 250
comments: 120
}
]
}
Expand Down
Loading