From ee91ddf5a458d83db9a1aa9acdfc40910ec77db8 Mon Sep 17 00:00:00 2001 From: Edgar Ochoa Date: Tue, 31 Mar 2026 17:28:00 +0200 Subject: [PATCH 1/3] test: add test suite for dataform pre-commit hooks --- tests/dummy_project/dataform.json | 6 +++++ tests/dummy_project/definitions/dummy.sqlx | 5 ++++ tests/dummy_project/package.json | 5 ++++ tests/test_hooks.sh | 31 ++++++++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 tests/dummy_project/dataform.json create mode 100644 tests/dummy_project/definitions/dummy.sqlx create mode 100644 tests/dummy_project/package.json create mode 100755 tests/test_hooks.sh diff --git a/tests/dummy_project/dataform.json b/tests/dummy_project/dataform.json new file mode 100644 index 0000000..20c1286 --- /dev/null +++ b/tests/dummy_project/dataform.json @@ -0,0 +1,6 @@ +{ + "defaultProject": "test-project", + "defaultLocation": "US", + "defaultDataset": "dataform", + "assertionSchema": "dataform_assertions" +} diff --git a/tests/dummy_project/definitions/dummy.sqlx b/tests/dummy_project/definitions/dummy.sqlx new file mode 100644 index 0000000..3b372a9 --- /dev/null +++ b/tests/dummy_project/definitions/dummy.sqlx @@ -0,0 +1,5 @@ +config { + type: "view" +} + +SELECT 1 AS test diff --git a/tests/dummy_project/package.json b/tests/dummy_project/package.json new file mode 100644 index 0000000..cb27497 --- /dev/null +++ b/tests/dummy_project/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "@dataform/core": "3.0.0" + } +} diff --git a/tests/test_hooks.sh b/tests/test_hooks.sh new file mode 100755 index 0000000..d0950a1 --- /dev/null +++ b/tests/test_hooks.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Test script for pre-commit-dataform hooks + +set -e + +REPO_ROOT=$(pwd) +TEST_DIR=$(mktemp -d) + +echo "Setting up test Dataform project in $TEST_DIR" +cp -r tests/dummy_project/* "$TEST_DIR/" +cd "$TEST_DIR" + +echo "Running dataform_compile.sh..." +if "$REPO_ROOT/hooks/dataform_compile.sh"; then + echo "dataform_compile.sh passed." +else + echo "dataform_compile.sh failed unexpectedly." + exit 1 +fi + +echo "Running dataform_format.sh..." +if "$REPO_ROOT/hooks/dataform_format.sh"; then + echo "dataform_format.sh passed." +else + echo "dataform_format.sh failed unexpectedly." + exit 1 +fi + +echo "All tests passed!" +rm -rf "$TEST_DIR" From aca01b701d3bf26bca0c6980a9f913d0cf293f02 Mon Sep 17 00:00:00 2001 From: Edgar Ochoa Date: Tue, 31 Mar 2026 17:32:36 +0200 Subject: [PATCH 2/3] fix: compatibility for Node@20 and Dataform Core v3 in dummy test project --- tests/dummy_project/dataform.json | 4 ++-- tests/dummy_project/definitions/dummy.sqlx | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/dummy_project/dataform.json b/tests/dummy_project/dataform.json index 20c1286..534fbfc 100644 --- a/tests/dummy_project/dataform.json +++ b/tests/dummy_project/dataform.json @@ -1,6 +1,6 @@ { - "defaultProject": "test-project", + "defaultDatabase": "test-project", "defaultLocation": "US", - "defaultDataset": "dataform", + "defaultSchema": "dataform", "assertionSchema": "dataform_assertions" } diff --git a/tests/dummy_project/definitions/dummy.sqlx b/tests/dummy_project/definitions/dummy.sqlx index 3b372a9..a32026b 100644 --- a/tests/dummy_project/definitions/dummy.sqlx +++ b/tests/dummy_project/definitions/dummy.sqlx @@ -2,4 +2,5 @@ config { type: "view" } -SELECT 1 AS test +SELECT + 1 AS test From c155fde7cebe6ccef9c718ecdca1502a9ccb0195 Mon Sep 17 00:00:00 2001 From: Edgar Ochoa Date: Tue, 31 Mar 2026 17:33:05 +0200 Subject: [PATCH 3/3] test: make test script more resilient by auto-switching Node version via nvm --- tests/test_hooks.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_hooks.sh b/tests/test_hooks.sh index d0950a1..db82bd7 100755 --- a/tests/test_hooks.sh +++ b/tests/test_hooks.sh @@ -5,6 +5,20 @@ set -e REPO_ROOT=$(pwd) + +# Check Node.js version and try to use nvm if available +if [[ $(node -v) == v2[2-5]* ]]; then + echo "Current Node.js version $(node -v) is known to be incompatible with Dataform CLI." + export NVM_DIR="$HOME/.nvm" + if [ -s "$NVM_DIR/nvm.sh" ]; then + echo "Trying to switch to Node.js v20 using nvm..." + source "$NVM_DIR/nvm.sh" + nvm use 20 || nvm install 20 + else + echo "Warning: No nvm found. Tests might fail." + fi +fi + TEST_DIR=$(mktemp -d) echo "Setting up test Dataform project in $TEST_DIR"