From b95960b01f9a9d8cafdb155379d5b29dfd5feeca Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 20 Nov 2024 11:43:46 +0000 Subject: [PATCH 01/12] Enable verbose test output in CI, as well as the github-actions reporter. --- .github/workflows/budibase_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/budibase_ci.yml b/.github/workflows/budibase_ci.yml index 0447b528f0..aa7efc13a8 100644 --- a/.github/workflows/budibase_ci.yml +++ b/.github/workflows/budibase_ci.yml @@ -211,7 +211,7 @@ jobs: fi cd packages/server - yarn test --filter $FILTER --passWithNoTests + yarn test --filter $FILTER --verbose --reporters=default --reporters=github-actions check-pro-submodule: runs-on: ubuntu-latest From f30d56210f029d10445a6398f725c323dadf1ad0 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 20 Nov 2024 11:51:32 +0000 Subject: [PATCH 02/12] Break a test on purpose to check reporter. --- packages/server/src/api/routes/tests/row.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 5bdd341beb..95d44a86ba 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -565,7 +565,7 @@ datasourceDescribe( const row = await config.api.row.save(table._id!, { food: ["orange"], }) - expect(row.food).toEqual(["orange"]) + expect(row.food).toEqual(["orangefdsfsd"]) }) it("resets back to its default value when empty", async () => { From 8d5a67b6b52528031f88776d8eb2d411939a34a2 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 20 Nov 2024 12:07:07 +0000 Subject: [PATCH 03/12] Add reporters to rest of jest tests. --- .github/workflows/budibase_ci.yml | 14 +++++--- .../server/src/api/routes/tests/row.spec.ts | 2 +- scripts/run-affected.js | 34 ------------------- 3 files changed, 10 insertions(+), 40 deletions(-) delete mode 100755 scripts/run-affected.js diff --git a/.github/workflows/budibase_ci.yml b/.github/workflows/budibase_ci.yml index aa7efc13a8..1739070717 100644 --- a/.github/workflows/budibase_ci.yml +++ b/.github/workflows/budibase_ci.yml @@ -114,9 +114,9 @@ jobs: - name: Test run: | if ${{ env.ONLY_AFFECTED_TASKS }}; then - yarn test --ignore=@budibase/worker --ignore=@budibase/server --since=${{ env.NX_BASE_BRANCH }} + yarn test --ignore=@budibase/worker --ignore=@budibase/server --since=${{ env.NX_BASE_BRANCH }} -- --verbose --reporters=default --reporters=github-actions else - yarn test --ignore=@budibase/worker --ignore=@budibase/server + yarn test --ignore=@budibase/worker --ignore=@budibase/server --verbose --reporters=default --reporters=github-actions fi test-worker: @@ -138,11 +138,15 @@ jobs: - name: Test worker run: | if ${{ env.ONLY_AFFECTED_TASKS }}; then - node scripts/run-affected.js --task=test --scope=@budibase/worker --since=${{ env.NX_BASE_BRANCH }} - else - yarn test --scope=@budibase/worker + AFFECTED=$(yarn --silent nx show projects --affected -t test --base=${{ env.NX_BASE_BRANCH }} -p @budibase/worker) + if [ -z "$AFFECTED" ]; then + echo "No affected tests to run" + exit 0 + fi fi + yarn test --scope=@budibase/worker --verbose --reporters=default --reporters=github-actions + test-server: runs-on: ubuntu-latest strategy: diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 95d44a86ba..5bdd341beb 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -565,7 +565,7 @@ datasourceDescribe( const row = await config.api.row.save(table._id!, { food: ["orange"], }) - expect(row.food).toEqual(["orangefdsfsd"]) + expect(row.food).toEqual(["orange"]) }) it("resets back to its default value when empty", async () => { diff --git a/scripts/run-affected.js b/scripts/run-affected.js deleted file mode 100755 index 97f79bb463..0000000000 --- a/scripts/run-affected.js +++ /dev/null @@ -1,34 +0,0 @@ -/*** - * Running lerna with since and scope is not working as expected. - * For example, running the command `yarn test --scope=@budibase/worker --since=master`, with changes only on `@budibase/backend-core` will not work as expected, as it does not analyse the dependencies properly. The actual `@budibase/worker` task will not be triggered. - * - * This script is using `lerna ls` to detect all the affected projects from a given commit, and if the scoped package is affected, the actual command will be executed. - * - * The current version of the script only supports a single project in the scope. - */ - -const { execSync } = require("child_process") - -const argv = require("yargs").demandOption(["task", "since", "scope"]).argv - -const { task, since, scope } = argv - -const affectedPackages = execSync( - `yarn --silent nx show projects --affected -t ${task} --base=${since} --json`, - { - encoding: "utf-8", - } -) - -const packages = JSON.parse(affectedPackages) - -const isAffected = packages.includes(scope) - -if (isAffected) { - console.log(`${scope} is affected. Running task "${task}"`) - execSync(`yarn ${task} --scope=${scope}`, { - stdio: "inherit", - }) -} else { - console.log(`${scope} is not affected. Skipping task "${task}"`) -} From b02e48fa099a4135a12ad7d7ee37c81cb8fe3483 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 20 Nov 2024 12:10:39 +0000 Subject: [PATCH 04/12] Attempt to fix CI. --- .github/workflows/budibase_ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/budibase_ci.yml b/.github/workflows/budibase_ci.yml index 1739070717..5decb660c1 100644 --- a/.github/workflows/budibase_ci.yml +++ b/.github/workflows/budibase_ci.yml @@ -116,7 +116,7 @@ jobs: if ${{ env.ONLY_AFFECTED_TASKS }}; then yarn test --ignore=@budibase/worker --ignore=@budibase/server --since=${{ env.NX_BASE_BRANCH }} -- --verbose --reporters=default --reporters=github-actions else - yarn test --ignore=@budibase/worker --ignore=@budibase/server --verbose --reporters=default --reporters=github-actions + yarn test --ignore=@budibase/worker --ignore=@budibase/server -- --verbose --reporters=default --reporters=github-actions fi test-worker: @@ -145,7 +145,8 @@ jobs: fi fi - yarn test --scope=@budibase/worker --verbose --reporters=default --reporters=github-actions + cd packages/worker + yarn test --verbose --reporters=default --reporters=github-actions test-server: runs-on: ubuntu-latest From d3da6c08a921e64d705c3aec54c7b15c4bd2b104 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 20 Nov 2024 12:12:21 +0000 Subject: [PATCH 05/12] Attempt to fix CI. --- .github/workflows/budibase_ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/budibase_ci.yml b/.github/workflows/budibase_ci.yml index 5decb660c1..cda2c7aa2d 100644 --- a/.github/workflows/budibase_ci.yml +++ b/.github/workflows/budibase_ci.yml @@ -114,9 +114,9 @@ jobs: - name: Test run: | if ${{ env.ONLY_AFFECTED_TASKS }}; then - yarn test --ignore=@budibase/worker --ignore=@budibase/server --since=${{ env.NX_BASE_BRANCH }} -- --verbose --reporters=default --reporters=github-actions + yarn test --ignore=@budibase/worker --ignore=@budibase/server --since=${{ env.NX_BASE_BRANCH }} -- -- --verbose --reporters=default --reporters=github-actions else - yarn test --ignore=@budibase/worker --ignore=@budibase/server -- --verbose --reporters=default --reporters=github-actions + yarn test --ignore=@budibase/worker --ignore=@budibase/server -- -- --verbose --reporters=default --reporters=github-actions fi test-worker: From d3d187e9aec7adb6284a945b3860b0ec2cdeef6b Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 20 Nov 2024 12:25:48 +0000 Subject: [PATCH 06/12] Fix test-libraries yarn invocation. --- .github/workflows/budibase_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/budibase_ci.yml b/.github/workflows/budibase_ci.yml index cda2c7aa2d..c7630e07bd 100644 --- a/.github/workflows/budibase_ci.yml +++ b/.github/workflows/budibase_ci.yml @@ -116,7 +116,7 @@ jobs: if ${{ env.ONLY_AFFECTED_TASKS }}; then yarn test --ignore=@budibase/worker --ignore=@budibase/server --since=${{ env.NX_BASE_BRANCH }} -- -- --verbose --reporters=default --reporters=github-actions else - yarn test --ignore=@budibase/worker --ignore=@budibase/server -- -- --verbose --reporters=default --reporters=github-actions + yarn test -- -- --ignore=@budibase/worker --ignore=@budibase/server --verbose --reporters=default --reporters=github-actions fi test-worker: From 6495a84ff9e582fe4b4cead1aa7ecc879ccd3aea Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 20 Nov 2024 12:34:18 +0000 Subject: [PATCH 07/12] Fix test-libraries yarn invocation. --- .github/workflows/budibase_ci.yml | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/budibase_ci.yml b/.github/workflows/budibase_ci.yml index c7630e07bd..732a295aae 100644 --- a/.github/workflows/budibase_ci.yml +++ b/.github/workflows/budibase_ci.yml @@ -114,9 +114,9 @@ jobs: - name: Test run: | if ${{ env.ONLY_AFFECTED_TASKS }}; then - yarn test --ignore=@budibase/worker --ignore=@budibase/server --since=${{ env.NX_BASE_BRANCH }} -- -- --verbose --reporters=default --reporters=github-actions + yarn test -- --ignore=@budibase/worker --ignore=@budibase/server --since=${{ env.NX_BASE_BRANCH }} -- --verbose --reporters=default --reporters=github-actions else - yarn test -- -- --ignore=@budibase/worker --ignore=@budibase/server --verbose --reporters=default --reporters=github-actions + yarn test -- --ignore=@budibase/worker --ignore=@budibase/server -- --verbose --reporters=default --reporters=github-actions fi test-worker: diff --git a/package.json b/package.json index 07e0010bf2..af39a4048d 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "dev:server": "yarn run kill-server && lerna run --stream dev --scope @budibase/worker --scope @budibase/server", "dev:built": "yarn run kill-all && cd packages/server && yarn dev:stack:up && cd ../../ && lerna run --stream dev:built", "dev:docker": "./scripts/devDocker.sh", - "test": "lerna run --concurrency 1 --stream test --stream", + "test": "lerna run --concurrency 1 --stream test", "test:containers:kill": "./scripts/killTestcontainers.sh", "lint:eslint": "eslint packages --max-warnings=0", "lint:prettier": "prettier --check \"packages/**/*.{js,ts,svelte}\" && prettier --write \"examples/**/*.{js,ts,svelte}\"", From 8944b0908b5e264beacb41178a1a71270a56a68c Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 20 Nov 2024 12:37:36 +0000 Subject: [PATCH 08/12] Create failing test in test-libraries --- .../backend-core/src/users/test/db.spec.ts | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/packages/backend-core/src/users/test/db.spec.ts b/packages/backend-core/src/users/test/db.spec.ts index 3e29d6673c..a279fa3780 100644 --- a/packages/backend-core/src/users/test/db.spec.ts +++ b/packages/backend-core/src/users/test/db.spec.ts @@ -36,26 +36,7 @@ describe("UserDB", () => { describe("save", () => { describe("create", () => { it("creating a new user will persist it", async () => { - const email = generator.email({}) - const user: User = structures.users.user({ - email, - tenantId: config.getTenantId(), - }) - - await config.doInTenant(async () => { - const saveUserResponse = await db.save(user) - - const persistedUser = await db.getUserByEmail(email) - expect(persistedUser).toEqual({ - ...user, - _id: saveUserResponse._id, - _rev: expect.stringMatching(/^1-\w+/), - password: expect.not.stringMatching(user.password!), - status: UserStatus.ACTIVE, - createdAt: Date.now(), - updatedAt: new Date().toISOString(), - }) - }) + throw new Error("oh no") }) it("the same email cannot be used twice in the same tenant", async () => { From cf57c7a0d08d3ee7887a81cf59d4c2c1ffb34861 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 20 Nov 2024 12:37:47 +0000 Subject: [PATCH 09/12] Revert failing test. --- .../backend-core/src/users/test/db.spec.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/backend-core/src/users/test/db.spec.ts b/packages/backend-core/src/users/test/db.spec.ts index a279fa3780..3e29d6673c 100644 --- a/packages/backend-core/src/users/test/db.spec.ts +++ b/packages/backend-core/src/users/test/db.spec.ts @@ -36,7 +36,26 @@ describe("UserDB", () => { describe("save", () => { describe("create", () => { it("creating a new user will persist it", async () => { - throw new Error("oh no") + const email = generator.email({}) + const user: User = structures.users.user({ + email, + tenantId: config.getTenantId(), + }) + + await config.doInTenant(async () => { + const saveUserResponse = await db.save(user) + + const persistedUser = await db.getUserByEmail(email) + expect(persistedUser).toEqual({ + ...user, + _id: saveUserResponse._id, + _rev: expect.stringMatching(/^1-\w+/), + password: expect.not.stringMatching(user.password!), + status: UserStatus.ACTIVE, + createdAt: Date.now(), + updatedAt: new Date().toISOString(), + }) + }) }) it("the same email cannot be used twice in the same tenant", async () => { From 63aa1ec0bf40e767c3f21f0a00270fa384d7b86a Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 20 Nov 2024 12:50:07 +0000 Subject: [PATCH 10/12] Create failing test in test-libraries --- packages/backend-core/src/users/test/db.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/backend-core/src/users/test/db.spec.ts b/packages/backend-core/src/users/test/db.spec.ts index 3e29d6673c..8fce11c7f1 100644 --- a/packages/backend-core/src/users/test/db.spec.ts +++ b/packages/backend-core/src/users/test/db.spec.ts @@ -48,6 +48,7 @@ describe("UserDB", () => { const persistedUser = await db.getUserByEmail(email) expect(persistedUser).toEqual({ ...user, + ohno: "what", _id: saveUserResponse._id, _rev: expect.stringMatching(/^1-\w+/), password: expect.not.stringMatching(user.password!), From 3b439e1228767bdbdb0d11b55e8bcadd28ac632e Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 20 Nov 2024 13:00:26 +0000 Subject: [PATCH 11/12] Don't prefix lerna output to allow github actions annotations through. --- .github/workflows/budibase_ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/budibase_ci.yml b/.github/workflows/budibase_ci.yml index 732a295aae..f1ed6eb87e 100644 --- a/.github/workflows/budibase_ci.yml +++ b/.github/workflows/budibase_ci.yml @@ -114,9 +114,9 @@ jobs: - name: Test run: | if ${{ env.ONLY_AFFECTED_TASKS }}; then - yarn test -- --ignore=@budibase/worker --ignore=@budibase/server --since=${{ env.NX_BASE_BRANCH }} -- --verbose --reporters=default --reporters=github-actions + yarn test -- --ignore=@budibase/worker --ignore=@budibase/server --no-prefix --since=${{ env.NX_BASE_BRANCH }} -- --verbose --reporters=default --reporters=github-actions else - yarn test -- --ignore=@budibase/worker --ignore=@budibase/server -- --verbose --reporters=default --reporters=github-actions + yarn test -- --ignore=@budibase/worker --ignore=@budibase/server --no-prefix -- --verbose --reporters=default --reporters=github-actions fi test-worker: From f25c24dac586da5866f5e768ab6454ead7e1d5fa Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 20 Nov 2024 13:06:56 +0000 Subject: [PATCH 12/12] Fix test. --- packages/backend-core/src/users/test/db.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/backend-core/src/users/test/db.spec.ts b/packages/backend-core/src/users/test/db.spec.ts index 8fce11c7f1..3e29d6673c 100644 --- a/packages/backend-core/src/users/test/db.spec.ts +++ b/packages/backend-core/src/users/test/db.spec.ts @@ -48,7 +48,6 @@ describe("UserDB", () => { const persistedUser = await db.getUserByEmail(email) expect(persistedUser).toEqual({ ...user, - ohno: "what", _id: saveUserResponse._id, _rev: expect.stringMatching(/^1-\w+/), password: expect.not.stringMatching(user.password!),