diff --git a/.eslintignore b/.eslintignore index 91f5433596..54824be5c7 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,4 +6,5 @@ packages/server/coverage packages/server/client packages/builder/.routify packages/builder/cypress/support/queryLevelTransformerFunction.js -packages/builder/cypress/support/queryLevelTransformerFunctionWithData.js \ No newline at end of file +packages/builder/cypress/support/queryLevelTransformerFunctionWithData.js +packages/builder/cypress/reports \ No newline at end of file diff --git a/.github/workflows/smoke_test.yaml b/.github/workflows/smoke_test.yaml index d5a5f0b02a..7002c8335b 100644 --- a/.github/workflows/smoke_test.yaml +++ b/.github/workflows/smoke_test.yaml @@ -33,23 +33,20 @@ jobs: with: record: true install: false + tag: nightly command: yarn test:e2e:ci:record env: CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - # TODO: upload recordings to s3 - # - name: Configure AWS Credentials - # uses: aws-actions/configure-aws-credentials@v1 - # with: - # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - # aws-region: eu-west-1 - - - name: Discord Webhook Action - uses: tsickert/discord-webhook@v4.0.0 + - uses: actions/upload-artifact@v3 with: - webhook-url: ${{ secrets.BUDI_QA_WEBHOOK }} - content: "Smoke test run completed with ${{ steps.cypress.outcome }}. See results at ${{ steps.cypress.outputs.dashboardUrl }}" - embed-title: ${{ steps.cypress.outcome }} - embed-color: ${{ steps.cypress.outcome == 'success' && '3066993' || '15548997' }} + name: Test Reports + path: packages/builder/cypress/reports/testReport.html + - name: Cypress Discord Notify + run: yarn test:e2e:ci:notify + env: + CYPRESS_WEBHOOK_URL: ${{ secrets.BUDI_QA_WEBHOOK }} + CYPRESS_OUTCOME: ${{ steps.cypress.outcome }} + CYPRESS_DASHBOARD_URL: ${{ steps.cypress.outputs.dashboardUrl }} + GITHUB_RUN_URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID diff --git a/.gitignore b/.gitignore index 7d09f0a2ba..03d77c5477 100644 --- a/.gitignore +++ b/.gitignore @@ -97,5 +97,7 @@ hosting/proxy/.generated-nginx.prod.conf bin/ hosting/.generated* -packages/builder/cypress.env.json -stats.html +packages/builder/cypress.env.json +packages/builder/cypress/reports +stats.html + diff --git a/lerna.json b/lerna.json index 69158e38c8..8f68c88cd1 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "1.0.167-alpha.2", + "version": "1.0.167-alpha.8", "npmClient": "yarn", "packages": [ "packages/*" diff --git a/package.json b/package.json index 84f1999ead..bd71dd6bc7 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "test:e2e": "lerna run cy:test --stream", "test:e2e:ci": "lerna run cy:ci --stream", "test:e2e:ci:record": "lerna run cy:ci:record --stream", + "test:e2e:ci:notify": "lerna run cy:ci:notify", "build:specs": "lerna run specs", "build:docker": "lerna run build:docker && npm run build:docker:proxy:compose && cd hosting/scripts/linux/ && ./release-to-docker-hub.sh $BUDIBASE_RELEASE_VERSION && cd -", "build:docker:proxy": "docker build hosting/proxy -t proxy-service", diff --git a/packages/backend-core/package.json b/packages/backend-core/package.json index 25a0509f0c..54c0b4af17 100644 --- a/packages/backend-core/package.json +++ b/packages/backend-core/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/backend-core", - "version": "1.0.167-alpha.2", + "version": "1.0.167-alpha.8", "description": "Budibase backend core libraries used in server and worker", "main": "src/index.js", "author": "Budibase", @@ -13,6 +13,7 @@ "@techpass/passport-openidconnect": "^0.3.0", "aws-sdk": "^2.901.0", "bcryptjs": "^2.4.3", + "dotenv": "^16.0.1", "emitter-listener": "^1.1.2", "ioredis": "^4.27.1", "jsonwebtoken": "^8.5.1", diff --git a/packages/backend-core/src/environment.js b/packages/backend-core/src/environment.js index f628e899ad..e0b70d4007 100644 --- a/packages/backend-core/src/environment.js +++ b/packages/backend-core/src/environment.js @@ -10,7 +10,15 @@ function isDev() { return process.env.NODE_ENV !== "production" } +let LOADED = false +if (!LOADED && isDev() && !isTest()) { + require("dotenv").config() + LOADED = true +} + module.exports = { + isTest, + isDev, JWT_SECRET: process.env.JWT_SECRET, COUCH_DB_URL: process.env.COUCH_DB_URL || "http://localhost:4005", COUCH_DB_USERNAME: process.env.COUCH_DB_USER, @@ -41,8 +49,7 @@ module.exports = { GLOBAL_CLOUD_BUCKET_NAME: process.env.GLOBAL_CLOUD_BUCKET_NAME || "prod-budi-tenant-uploads", USE_COUCH: process.env.USE_COUCH || true, - isTest, - isDev, + DISABLE_DEVELOPER_LICENSE: process.env.DISABLE_DEVELOPER_LICENSE, _set(key, value) { process.env[key] = value module.exports[key] = value diff --git a/packages/backend-core/src/index.js b/packages/backend-core/src/index.js index 3868d9bffa..572b61fbeb 100644 --- a/packages/backend-core/src/index.js +++ b/packages/backend-core/src/index.js @@ -19,5 +19,6 @@ module.exports = { env: require("./environment"), accounts: require("./cloud/accounts"), tenancy: require("./tenancy"), + context: require("../context"), featureFlags: require("./featureFlags"), } diff --git a/packages/backend-core/yarn.lock b/packages/backend-core/yarn.lock index 7dfa64810e..80f292140d 100644 --- a/packages/backend-core/yarn.lock +++ b/packages/backend-core/yarn.lock @@ -1485,6 +1485,11 @@ domexception@^2.0.1: dependencies: webidl-conversions "^5.0.0" +dotenv@^16.0.1: + version "16.0.1" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.1.tgz#8f8f9d94876c35dac989876a5d3a82a267fdce1d" + integrity sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ== + double-ended-queue@2.1.0-0: version "2.1.0-0" resolved "https://registry.yarnpkg.com/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz#103d3527fd31528f40188130c841efdd78264e5c" diff --git a/packages/bbui/package.json b/packages/bbui/package.json index ba51966f3c..e4f527555e 100644 --- a/packages/bbui/package.json +++ b/packages/bbui/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/bbui", "description": "A UI solution used in the different Budibase projects.", - "version": "1.0.167-alpha.2", + "version": "1.0.167-alpha.8", "license": "MPL-2.0", "svelte": "src/index.js", "module": "dist/bbui.es.js", @@ -38,7 +38,7 @@ ], "dependencies": { "@adobe/spectrum-css-workflow-icons": "^1.2.1", - "@budibase/string-templates": "^1.0.167-alpha.2", + "@budibase/string-templates": "^1.0.167-alpha.8", "@spectrum-css/actionbutton": "^1.0.1", "@spectrum-css/actiongroup": "^1.0.1", "@spectrum-css/avatar": "^3.0.2", diff --git a/packages/builder/cypress.json b/packages/builder/cypress.json index 0828c9987b..06bf558946 100644 --- a/packages/builder/cypress.json +++ b/packages/builder/cypress.json @@ -2,6 +2,10 @@ "baseUrl": "http://localhost:4100", "video": true, "projectId": "bmbemn", + "reporter": "cypress-multi-reporters", + "reporterOptions": { + "configFile": "reporterConfig.json" + }, "env": { "PORT": "4100", "WORKER_PORT": "4200", diff --git a/packages/builder/cypress/integration/addRadioButtons.spec.js b/packages/builder/cypress/integration/addRadioButtons.spec.js index 9888b56086..8f5b1a527b 100644 --- a/packages/builder/cypress/integration/addRadioButtons.spec.js +++ b/packages/builder/cypress/integration/addRadioButtons.spec.js @@ -1,4 +1,5 @@ import filterTests from "../support/filterTests" +const interact = require('../support/interact') filterTests(['all'], () => { context("Add Radio Buttons", () => { @@ -12,10 +13,10 @@ filterTests(['all'], () => { cy.addComponent("Form", "Form") cy.addComponent("Form", "Options Picker").then((componentId) => { // Provide field setting - cy.get(`[data-cy="field-prop-control"]`).type("1") + cy.get(interact.DATASOURCE_FIELD_CONTROL).type("1") // Open dropdown and select Radio buttons - cy.get(`[data-cy="optionsType-prop-control"]`).click().then(() => { - cy.get('.spectrum-Popover').contains('Radio buttons') + cy.get(interact.OPTION_TYPE_PROP_CONTROL).click().then(() => { + cy.get(interact.SPECTRUM_POPOVER).contains('Radio buttons') .wait(500) .click() }) @@ -28,8 +29,8 @@ filterTests(['all'], () => { }) const addRadioButtonData = (totalRadioButtons) => { - cy.get(`[data-cy="optionsSource-prop-control"]`).click().then(() => { - cy.get('.spectrum-Popover').contains('Custom') + cy.get(interact.OPTION_SOURCE_PROP_CONROL).click().then(() => { + cy.get(interact.SPECTRUM_POPOVER).contains('Custom') .wait(500) .click() }) diff --git a/packages/builder/cypress/setup.js b/packages/builder/cypress/setup.js index e19c931ed9..d10990573a 100644 --- a/packages/builder/cypress/setup.js +++ b/packages/builder/cypress/setup.js @@ -7,7 +7,6 @@ const tmpdir = path.join(require("os").tmpdir(), ".budibase") const SERVER_PORT = cypressConfig.env.PORT const WORKER_PORT = cypressConfig.env.WORKER_PORT -process.env.BUDIBASE_API_KEY = "6BE826CB-6B30-4AEC-8777-2E90464633DE" process.env.NODE_ENV = "cypress" process.env.ENABLE_ANALYTICS = "false" process.env.JWT_SECRET = cypressConfig.env.JWT_SECRET diff --git a/packages/builder/cypress/support/interact.js b/packages/builder/cypress/support/interact.js index cff16325da..11794d940d 100644 --- a/packages/builder/cypress/support/interact.js +++ b/packages/builder/cypress/support/interact.js @@ -19,3 +19,8 @@ export const DATASOURCE_PROP_CONTROL = '[data-cy="dataSource-prop-control"]' export const DROPDOWN = ".dropdown" export const SPECTRUM_Picker_LABEL = ".spectrum-Picker-label" export const DATASOURCE_FIELD_CONTROL = '[data-cy="field-prop-control"]' +export const OPTION_TYPE_PROP_CONTROL = '[data-cy="optionsType-prop-control' + +//AddRadioButtons +export const SPECTRUM_POPOVER = ".spectrum-Popover" +export const OPTION_SOURCE_PROP_CONROL = '[data-cy="optionsSource-prop-control' diff --git a/packages/builder/package.json b/packages/builder/package.json index 7f3534b093..367d23505a 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/builder", - "version": "1.0.167-alpha.2", + "version": "1.0.167-alpha.8", "license": "GPL-3.0", "private": true, "scripts": { @@ -13,11 +13,13 @@ "cy:setup:ci": "node ./cypress/setup.js", "cy:open": "cypress open", "cy:run": "cypress run", - "cy:run:ci": "xvfb-run cypress run --headed --browser chrome", + "cy:run:ci": "cypress run --headed --browser chrome --spec cypress/integration/createApp.spec.js", "cy:run:ci:record": "xvfb-run cypress run --headed --browser chrome --record", "cy:test": "start-server-and-test cy:setup http://localhost:4100/builder cy:run", "cy:ci": "start-server-and-test cy:setup:ci http://localhost:4100/builder cy:run:ci", - "cy:ci:record": "start-server-and-test cy:setup:ci http://localhost:4100/builder cy:run:ci:record", + "cy:ci:record": "start-server-and-test cy:setup:ci http://localhost:4100/builder cy:run:ci:record && npm run cy:ci:report", + "cy:ci:report": "mochawesome-merge cypress/reports/*.json > cypress/reports/testReport.json && marge cypress/reports/testReport.json --reportDir cypress/reports --inline", + "cy:ci:notify": "node scripts/cypressResultsWebhook", "cy:debug": "start-server-and-test cy:setup http://localhost:4100/builder cy:open", "cy:debug:ci": "start-server-and-test cy:setup:ci http://localhost:4100/builder cy:open" }, @@ -67,10 +69,10 @@ } }, "dependencies": { - "@budibase/bbui": "^1.0.167-alpha.2", - "@budibase/client": "^1.0.167-alpha.2", - "@budibase/frontend-core": "^1.0.167-alpha.2", - "@budibase/string-templates": "^1.0.167-alpha.2", + "@budibase/bbui": "^1.0.167-alpha.8", + "@budibase/client": "^1.0.167-alpha.8", + "@budibase/frontend-core": "^1.0.167-alpha.8", + "@budibase/string-templates": "^1.0.167-alpha.8", "@sentry/browser": "5.19.1", "@spectrum-css/page": "^3.0.1", "@spectrum-css/vars": "^3.0.1", @@ -98,9 +100,13 @@ "@testing-library/svelte": "^3.0.0", "babel-jest": "^26.6.3", "cypress": "^9.3.1", + "cypress-multi-reporters": "^1.6.0", "cypress-terminal-report": "^1.4.1", "identity-obj-proxy": "^3.0.0", "jest": "^26.6.3", + "mochawesome": "^7.1.3", + "mochawesome-merge": "^4.2.1", + "mochawesome-report-generator": "^6.2.0", "ncp": "^2.0.0", "rimraf": "^3.0.2", "rollup": "^2.44.0", diff --git a/packages/builder/reporterConfig.json b/packages/builder/reporterConfig.json new file mode 100644 index 0000000000..2c2ef7c138 --- /dev/null +++ b/packages/builder/reporterConfig.json @@ -0,0 +1,10 @@ +{ + "reporterEnabled": "mochawesome", + "mochawesomeReporterOptions": { + "reportDir": "cypress/reports", + "quiet": true, + "overwrite": false, + "html": false, + "json": true + } +} \ No newline at end of file diff --git a/packages/builder/scripts/cypressResultsWebhook.js b/packages/builder/scripts/cypressResultsWebhook.js new file mode 100644 index 0000000000..457093e013 --- /dev/null +++ b/packages/builder/scripts/cypressResultsWebhook.js @@ -0,0 +1,130 @@ +#!/usr/bin/env node + +const fetch = require("node-fetch") +const path = require("path") +const fs = require("fs") + +const WEBHOOK_URL = process.env.CYPRESS_WEBHOOK_URL +const OUTCOME = process.env.CYPRESS_OUTCOME +const DASHBOARD_URL = process.env.CYPRESS_DASHBOARD_URL +const GIT_SHA = process.env.GITHUB_SHA +const GITHUB_ACTIONS_RUN_URL = process.env.GITHUB_ACTIONS_RUN_URL + +async function generateReport() { + // read the report file + const REPORT_PATH = path.resolve( + __dirname, + "..", + "cypress", + "reports", + "testReport.json" + ) + const report = fs.readFileSync(REPORT_PATH, "utf-8") + return JSON.parse(report) +} + +async function discordCypressResultsNotification(report) { + const { + suites, + tests, + passes, + pending, + failures, + duration, + passPercent, + skipped, + } = report.stats + + const options = { + method: "POST", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + }, + body: JSON.stringify({ + content: `**Nightly Tests Status**: ${OUTCOME}`, + embeds: [ + { + title: "Budi QA Bot", + description: `Nightly Tests`, + url: GITHUB_ACTIONS_RUN_URL, + color: OUTCOME === "success" ? 3066993 : 15548997, + timestamp: new Date(), + footer: { + icon_url: "http://bbui.budibase.com/budibase-logo.png", + text: "Budibase QA Bot", + }, + thumbnail: { + url: "http://bbui.budibase.com/budibase-logo.png", + }, + author: { + name: "Budibase QA Bot", + url: "https://discordapp.com", + icon_url: "http://bbui.budibase.com/budibase-logo.png", + }, + fields: [ + { + name: "Commit", + value: `https://github.com/Budibase/budibase/commit/${GIT_SHA}`, + }, + { + name: "Cypress Dashboard URL", + value: DASHBOARD_URL || "None Supplied", + }, + { + name: "Github Actions Run URL", + value: GITHUB_ACTIONS_RUN_URL || "None Supplied", + }, + { + name: "Test Suites", + value: suites, + }, + { + name: "Tests", + value: tests, + }, + { + name: "Passed", + value: passes, + }, + { + name: "Pending", + value: pending, + }, + { + name: "Skipped", + value: skipped, + }, + { + name: "Failures", + value: failures, + }, + { + name: "Duration", + value: `${duration / 1000} Seconds`, + }, + { + name: "Pass Percentage", + value: Math.floor(passPercent), + }, + ], + }, + ], + }), + } + const response = await fetch(WEBHOOK_URL, options) + + if (response.status >= 400) { + const text = await response.text() + console.error( + `Error sending discord webhook. \nStatus: ${response.status}. \nResponse Body: ${text}. \nRequest Body: ${options.body}` + ) + } +} + +async function run() { + const report = await generateReport() + await discordCypressResultsNotification(report) +} + +run() diff --git a/packages/builder/src/components/usage/Usage.svelte b/packages/builder/src/components/usage/Usage.svelte new file mode 100644 index 0000000000..cd9071785d --- /dev/null +++ b/packages/builder/src/components/usage/Usage.svelte @@ -0,0 +1,56 @@ + + +