Skip to content

Commit 1de2e5f

Browse files
authored
run test-stores now spawns morbo. (#91)
This changes the way that npm run test-stores runs. Instead of requiring morbo to be started, this will spawn it before running the jest script. Additionally, morbo is started in 'test' mode which loads conf/ww3-dev.yaml instead of conf/webwork3.yaml. Other thoughts about this. I set the port this runs as 3333. Perhaps have an environment variable to set this. Also, I haven't put this in the GitHub action. It might run now that morbo is running.
1 parent 62fae8f commit 1de2e5f

4 files changed

Lines changed: 48 additions & 4 deletions

File tree

bin/dev_scripts/test_pinia_stores

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#! /usr/bin/env bash
2+
3+
# Runs the tests in the tests/store directory by first spawning morbo (needed to test the stores)
4+
# The port can be changed either with the environmental variable WEBWORK3_TEST_PORT
5+
# or the command line option -p (which overrides WEBWORK3_TEST_PORT)
6+
7+
port=3333
8+
if [[ -n ${WEBWORK3_TEST_PORT+x} ]]; then
9+
port=$WEBWORK3_TEST_PORT
10+
fi
11+
12+
while getopts ':p:' OPTION; do
13+
case "$OPTION" in
14+
p)
15+
port="$OPTARG"
16+
echo "The port has been set to $port via a command line argument"
17+
;;
18+
*)
19+
echo "the option $OPTARG is not defined"
20+
exit 1
21+
;;
22+
esac
23+
done
24+
25+
echo "Running the test scripts using port $port"
26+
27+
morbo -v -m test -l "http://[::]:$port" bin/webwork3 &
28+
# Grab the process number.
29+
P1=$!
30+
31+
npx jest --verbose --runInBand --testURL "http://localhost:$port/webwork3/api" 'tests/stores'
32+
33+
kill $P1

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { compilerOptions } = requireJSON5('./node_modules/@quasar/app/tsconfig-pr
77
module.exports = {
88
preset: 'ts-jest',
99
testEnvironment: 'node',
10-
testURL: 'http://localhost:3000/webwork3/api',
10+
testURL: 'http://localhost:3333/webwork3/api',
1111
globals: {
1212
'ts-jest': {
1313
'tsconfig': 'tsconfig.json',

lib/WeBWorK3.pm

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,19 @@ sub startup ($self) {
2222
$self->log->path($path);
2323
}
2424

25-
# Load configuration from config file
26-
my $config = $self->plugin('NotYAMLConfig');
25+
my $config;
26+
27+
if ($ENV{MOJO_MODE} && $ENV{MOJO_MODE} eq 'test') {
28+
my $path = path("$ENV{WW3_ROOT}/logs")->make_path->child('webwork3_test.log');
29+
$self->log->path($path);
30+
$self->log->level('trace');
31+
my $test_config_file = "$ENV{WW3_ROOT}/conf/ww3-dev.yml";
32+
$test_config_file = "$ENV{WW3_ROOT}/conf/ww3-dev.dist.yml" unless (-e $test_config_file);
33+
$config = $self->plugin(NotYAMLConfig => { file => $test_config_file });
34+
} else {
35+
# Load configuration from config file
36+
$config = $self->plugin('NotYAMLConfig');
37+
}
2738

2839
# Configure the application
2940
$self->secrets($config->{secrets});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"scripts": {
99
"lint": "eslint --ext .js,.ts,.vue . --fix && stylelint \"./src/**/*.vue\" \"./src/**/*.scss\" --fix",
1010
"test": "jest --testPathPattern='tests/unit-tests'",
11-
"test-stores": "jest --runInBand --testPathPattern='tests/stores'",
11+
"test-stores": "./bin/dev_scripts/test_pinia_stores",
1212
"serve": "morbo bin/webwork3 & quasar dev",
1313
"build": "quasar build",
1414
"perltidy": "bash perltidy --pro=./.perltidyrc -b -bext='/' ./**/*.{t,pl,pm}"

0 commit comments

Comments
 (0)