Skip to content

Unit test rework #122

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
package.json
package-lock.json
tsconfig.json
t/db/sample_data/*.json
34 changes: 6 additions & 28 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,40 @@
---
###########################
## Linter GitHub Actions ##
###########################
name: Lint Code Base

defaults:
run:
shell: bash

# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions

#############################
# Start the job on all push #
#############################
on:
push:
branches-ignore: [main]
# Remove the line above to run when pushing to main
pull_request:
branches: [main]

###############
# Set the Job #
###############
jobs:
lint:
# Name the Job
name: Lint Code Base
# Set the agent to run on
runs-on: ubuntu-latest

##################
# Load all steps #
##################
steps:
##########################
# Checkout the code base #
##########################
# Checkout the code base
- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0

# Install node (for npm) and use it to install eslint and stylelint dependencies.
- name: Use Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install Dependencies
run: npm ci

################################
# Run Linter against code base #
################################
# Run Linter against code base
- name: Super-Linter
uses: github/super-linter@v4.8.1
uses: github/super-linter@v4.9.5

env:
VALIDATE_ALL_CODEBASE: false
Expand All @@ -77,7 +55,7 @@ jobs:
container:
image: perl:5.32
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: perl -V
run: perl -V
- name: Install dependencies
Expand Down
100 changes: 81 additions & 19 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,105 @@
---
name: Unit Tests and Coverage

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
branches: [main]

jobs:
unit-tests:
runs-on: ubuntu-latest
# If we are going to use a prebuilt image like this we need a webwork repository on docker hub
container: drgrice1/webwork3
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Run perl unit tests
- name: Checkout webwork3 source code
uses: actions/checkout@v3

# Disabling these things speeds up the setup considerably, and they are not needed for the throw away machine.
- name: Disable man-db and initramfs updates
run: |
sudo sed -i 's/yes/no/g' /etc/initramfs-tools/update-initramfs.conf
sudo rm -f /var/lib/man-db/auto-update

- name: Install dependencies
env:
HARNESS_PERL_SWITCHES: -MDevel::Cover
DEBIAN_FRONTEND: noninteractive
DEBCONF_NONINTERACTIVE_SEEN: true
DEBCONF_NOWARNINGS: yes
run: |
perl t/db/build_db.pl
prove -r t
sudo apt-get update
sudo apt-get install -qy --no-install-recommends --no-install-suggests \
cpanminus \
libarray-utils-perl \
libcanary-stability-perl \
libcapture-tiny-perl \
libclass-accessor-lite-perl \
libclone-perl \
libcpanel-json-xs-perl \
libcrypt-ssleay-perl \
libdata-dump-perl \
libdatetime-format-strptime-perl \
libdbd-sqlite3-perl \
libdbd-mysql-perl \
libdbix-class-inflatecolumn-serializer-perl \
libdbix-class-perl \
libdbix-dbschema-perl \
libdevel-cover-perl \
libexception-class-perl \
libextutils-config-perl \
libextutils-helpers-perl \
libextutils-installpaths-perl \
libfurl-perl \
libhttp-parser-xs-perl \
libimporter-perl \
libio-socket-ssl-perl \
liblist-moreutils-perl \
libmodule-build-tiny-perl \
libmojolicious-perl \
libmojolicious-plugin-authentication-perl \
libnet-ssleay-perl \
libsql-translator-perl \
libsub-info-perl \
libterm-table-perl \
libtest-harness-perl \
libtest2-suite-perl \
libtest-postgresql-perl \
libtext-csv-perl \
libtry-tiny-perl \
libyaml-libyaml-perl \
mariadb-client \
mariadb-server \
postgresql
cpanm --sudo --notest \
DBIx::Class::DynamicSubclass \
Mojolicious::Plugin::DBIC \
Mojolicious::Plugin::NotYAMLConfig \
Test2::MojoX \
Devel::Cover::Report::Codecov

# we probably don'te need to upload the codecov data
# - uses: actions/upload-artifact@v2
# with:
# name: coverage-report
# path: cover_db/
- name: Run perl unit tests
env:
HARNESS_PERL_SWITCHES: -MDevel::Cover
WW3_TEST_ALL_DBS: 1
run: prove -r t

- name: Push coverage analysis
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: cover -report codecov

# Install node (for npm) and use it to install eslint and stylelint dependencies.
- name: Use Node.js
uses: actions/setup-node@v2
# Install node (for npm).
- name: Set up node
uses: actions/setup-node@v3
with:
node-version: '16'

- name: Install Dependencies
run: npm ci
- name: Run typescript (client-side) tests

- name: Run jest client-side tests
run: npm run test

- name: Run jest pinia stores tests.
env:
WW3_TEST_ALL_DBS: 1
run: bin/dev_scripts/test_pinia_stores.pl
2 changes: 1 addition & 1 deletion .jscpd.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"threshold": 5,
"ignore": ["node_modules", "dist", "**/*.pm", "**/*.ts"]
"ignore": ["node_modules", "dist", "**/*.pm", "**/*.ts", "**/t/db/sample_data/*.json"]
}
7 changes: 7 additions & 0 deletions .perlcriticrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ severity = 4
# Allow no warnings usage with a category restriction (for signatures)
[TestingAndDebugging::ProhibitNoWarnings]
allow_with_category_restriction = 1

# Allow $a and $b in sort functions. If sort functions are added to the code not in a "sort" call, they must be added
# to this list. Annoyingly both of these policies that do the same thing have to each get the list.
[Community::DollarAB]
extra_pair_functions = user_prob_sort_fcn
[Freenode::DollarAB]
extra_pair_functions = user_prob_sort_fcn
64 changes: 64 additions & 0 deletions bin/dev_scripts/build_sample_db.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env perl

# This file fills a database with sample data from JSON files.

use warnings;
use strict;
use feature 'say';

use Mojo::File qw/curfile/;
use YAML::XS qw/LoadFile/;

use lib curfile->dirname->dirname->sibling('lib')->to_string;
use lib curfile->dirname->dirname->sibling('t/lib')->to_string;

use DB::Schema;
use BuildDB qw/loadPermissions addCourses addUsers addSets addProblems addUserSets addProblemPools addUserProblems/;

my $ww3_dir = curfile->dirname->dirname->dirname;

# Load the configuration for the database settings.
my $config_file = $ww3_dir->child('conf', 'webwork3-dev.yml');
$config_file = $ww3_dir->child('conf/webwork3.yml') unless -e $config_file;
$config_file = $ww3_dir->child('conf/webwork3.dist.yml') unless -e $config_file;
my $config = LoadFile($config_file);

# Connect to the database.
my $schema = DB::Schema->connect(
$config->{database_dsn},
$config->{database_user},
$config->{database_password},
{ quote_names => 1 }
);

say "restoring the database with dbi: $config->{database_dsn}";

# Create the database based on the schema.
$schema->deploy({ add_drop_table => 1 });

# The permissions need to be loaded into the database first.
say 'loading permissions';
loadPermissions($schema, $ww3_dir);

say 'adding courses';
addCourses($schema, $ww3_dir);

say 'adding users';
addUsers($schema, $ww3_dir);

say 'adding problem sets';
addSets($schema, $ww3_dir);

say 'adding problems';
addProblems($schema, $ww3_dir);

say 'adding user sets';
addUserSets($schema, $ww3_dir);

say 'adding problem pools';
addProblemPools($schema, $ww3_dir);

say 'adding user problems';
addUserProblems($schema, $ww3_dir);

1;
33 changes: 0 additions & 33 deletions bin/dev_scripts/test_pinia_stores

This file was deleted.

Loading