Skip to content

Commit

Permalink
OPHYK-212 Split different test suites to separate CodePipeline action…
Browse files Browse the repository at this point in the history
…s to make it easier to see which is failing and why
  • Loading branch information
rce committed Dec 10, 2024
1 parent 73074f0 commit 0dd0f01
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 53 deletions.
29 changes: 15 additions & 14 deletions infra/src/cdk-app-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,22 @@ class ContinuousDeploymentPipelineStack extends cdk.Stack {

const runTests = env === "hahtuva";
if (runTests) {
const tests = [
{ name: "TestOrganisaatioService", commands: ["scripts/ci/run-java-tests.sh"] },
{ name: "TestOrganisaatioUi", commands: ["scripts/ci/run-frontend-tests.sh"] },
{ name: "TestOrganisaatioCypress", commands: ["scripts/ci/run-cypress-tests.sh"] },
]

const testStage = pipeline.addStage({ stageName: "Test" });
testStage.addAction(
new codepipeline_actions.CodeBuildAction({
actionName: "TestOrganisaatio",
input: sourceOutput,
project: makeTestProject(
this,
env,
tag,
"TestOrganisaatio",
["scripts/ci/run-tests.sh"],
"corretto21"
),
})
);
for (const test of tests) {
testStage.addAction(
new codepipeline_actions.CodeBuildAction({
actionName: test.name,
input: sourceOutput,
project: makeTestProject(this, env, tag, test.name, test.commands, "corretto21"),
})
);
}
}

const deployProject = new codebuild.PipelineProject(
Expand Down
69 changes: 30 additions & 39 deletions scripts/ci/run-tests.sh → scripts/ci/run-cypress-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,28 @@ trap stop_database EXIT
function main {
init_nodejs
install_npm_dependencies
start_database
build_and_test_frontend
build_and_test_jar
run_cypress_tests
}

function install_npm_dependencies {
for bom_dir in "${repo}/playwright" \
"${repo}/organisaatio-ui" \
"${repo}/mock-api"; do
cd ${bom_dir}
npm_ci_if_needed
done
}
start_database
start_mock_api
start_ui

function start_database {
cd $repo
docker compose up --detach
}
start_server

function stop_database {
cd $repo
docker compose down
cd "${repo}/organisaatio-ui"
npm run cypress:ci
}

function build_and_test_frontend {
cd $repo/organisaatio-ui
npm run lint
npm run prettier
CI=true npm run test
npm run build
function start_mock_api {
cd "${repo}/mock-api" && npm run mock-api &
}

function build_and_test_jar {
cd $repo
./gradlew clean build
function start_ui {
cd "${repo}/organisaatio-ui" && npm run start &
}

function run_cypress_tests {
cd "${repo}/mock-api" && npm run mock-api &
mock_api_pid=$!
cd "${repo}/organisaatio-ui" && npm run start &
ui_pid=$!
function start_server {
cd "${repo}"
./gradlew clean build -x test
java -jar -Xms2g -Xmx2g \
-Dspring.config.location=classpath:application.properties,classpath:application-test-envs.properties \
-Dspring.profiles.active=dev \
Expand All @@ -63,12 +41,25 @@ function run_cypress_tests {
-Durl-oidservice=http://localhost:9000/oidservice \
-Dcas.service.organisaatio-service=http://localhost:8080/organisaatio-service-not-available \
organisaatio-service/build/libs/organisaatio-service.jar &
}

cd "${repo}/organisaatio-ui"
npm run cypress:ci
function install_npm_dependencies {
for bom_dir in "${repo}/playwright" \
"${repo}/organisaatio-ui" \
"${repo}/mock-api"; do
cd ${bom_dir}
npm_ci_if_needed
done
}

kill $mock_api_pid
kill $ui_pid
function start_database {
cd $repo
docker compose up --detach
}

function stop_database {
cd $repo
docker compose down
}

main "$@"
main "$@"
27 changes: 27 additions & 0 deletions scripts/ci/run-frontend-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail

repo="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd ../.. && pwd )"
source "${repo}/scripts/lib/common-functions.sh"

function main {
init_nodejs
install_npm_dependencies

cd "${repo}/organisaatio-ui"
npm run lint
npm run prettier
CI=true npm run test
npm run build
}

function install_npm_dependencies {
for bom_dir in "${repo}/playwright" \
"${repo}/organisaatio-ui" \
"${repo}/mock-api"; do
cd ${bom_dir}
npm_ci_if_needed
done
}

main "$@"
26 changes: 26 additions & 0 deletions scripts/ci/run-java-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail

repo="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd ../.. && pwd )"
source "${repo}/scripts/lib/common-functions.sh"

trap stop_database EXIT

function main {
start_database

cd "${repo}"
./gradlew clean build
}

function start_database {
cd $repo
docker compose up --detach
}

function stop_database {
cd $repo
docker compose down
}

main "$@"

0 comments on commit 0dd0f01

Please sign in to comment.