From 3a31e02cf3459ef7446f44b36d048b4a489cbbbd Mon Sep 17 00:00:00 2001 From: Marcos Date: Tue, 11 Feb 2025 13:32:23 -0600 Subject: [PATCH] Cypress e2e tooling - New `cy.loadProjectConfig` to load project configurations in tests (#2578) Co-authored-by: marcosnavarro --- test/e2e/docker-compose.yml | 2 +- test/e2e/package-lock.json | 8 ++++++++ test/e2e/package.json | 1 + test/e2e/support/commands.js | 27 +++++++++++++++++++++++++++ test/e2e/tests/deployments.cy.js | 13 +++++++++++++ 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/test/e2e/docker-compose.yml b/test/e2e/docker-compose.yml index 587b67b2a..91d4df889 100644 --- a/test/e2e/docker-compose.yml +++ b/test/e2e/docker-compose.yml @@ -1,7 +1,7 @@ services: # Starts a container that mounts Connect and other dependencies connect-publisher-e2e: - container_name: publishe-e2e.connect + container_name: publisher-e2e.connect build: context: ../.. dockerfile: test/e2e/Dockerfile.connect diff --git a/test/e2e/package-lock.json b/test/e2e/package-lock.json index 79d496acf..c5d747ecc 100644 --- a/test/e2e/package-lock.json +++ b/test/e2e/package-lock.json @@ -18,6 +18,7 @@ "eslint-plugin-mocha": "^10.5.0", "lint-staged": "^15.4.3", "prettier": "^3.4.2", + "toml": "^3.0.0", "wait-on": "^8.0.2" } }, @@ -3580,6 +3581,13 @@ "node": ">=8.0" } }, + "node_modules/toml": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz", + "integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==", + "dev": true, + "license": "MIT" + }, "node_modules/tough-cookie": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-5.1.0.tgz", diff --git a/test/e2e/package.json b/test/e2e/package.json index 9775d751e..6d9b39cf0 100644 --- a/test/e2e/package.json +++ b/test/e2e/package.json @@ -20,6 +20,7 @@ "eslint-plugin-mocha": "^10.5.0", "lint-staged": "^15.4.3", "prettier": "^3.4.2", + "toml": "^3.0.0", "wait-on": "^8.0.2" } } diff --git a/test/e2e/support/commands.js b/test/e2e/support/commands.js index 26751423b..afccc8293 100644 --- a/test/e2e/support/commands.js +++ b/test/e2e/support/commands.js @@ -1,4 +1,5 @@ import "@testing-library/cypress/add-commands"; +import toml from "toml"; import "./selectors"; const connectManagerServer = Cypress.env("CONNECT_MANAGER_URL"); @@ -133,6 +134,32 @@ Cypress.Commands.add("clearupDeployments", () => { cy.exec(`rm -rf content-workspace/static/.posit`); }); +Cypress.Commands.add("loadProjectConfigFile", (projectName) => { + const projectConfigPath = `content-workspace/${projectName}/.posit/publish/static-*.toml`; + // Do not fail on non-zero exit this time, we can provide a better error + return cy + .exec(`cat ${projectConfigPath}`, { failOnNonZeroExit: false }) + .then((result) => { + if (result.code === 0 && result.stdout) { + return toml.parse(result.stdout); + } + throw new Error(`Could not load project configuration. ${result.stderr}`); + }); +}); + +Cypress.Commands.add("loadProjectDeploymentFile", (projectName) => { + const projectDeploymentPath = `content-workspace/${projectName}/.posit/publish/deployments/deployment-*.toml`; + // Do not fail on non-zero exit this time, we can provide a better error + return cy + .exec(`cat ${projectDeploymentPath}`, { failOnNonZeroExit: false }) + .then((result) => { + if (result.code === 0 && result.stdout) { + return toml.parse(result.stdout); + } + throw new Error(`Could not load project deployment. ${result.stderr}`); + }); +}); + // Performs the full set of reset commands we typically use before executing our tests Cypress.Commands.add("resetConnect", () => { cy.clearupDeployments(); diff --git a/test/e2e/tests/deployments.cy.js b/test/e2e/tests/deployments.cy.js index 9b8c2a339..e0ccf7843 100644 --- a/test/e2e/tests/deployments.cy.js +++ b/test/e2e/tests/deployments.cy.js @@ -56,6 +56,19 @@ describe("Deployments Section", () => { .should("be.visible") .click(); + cy.loadProjectConfigFile("static").then((config) => { + expect(config.title).to.equal("static"); + expect(config.type).to.equal("html"); + expect(config.entrypoint).to.equal("index.html"); + expect(config.files[0]).to.equal("/index.html"); + expect(config.files[1]).to.match( + /\/.posit\/publish\/static-[A-Z0-9]{4}\.toml/, + ); + expect(config.files[2]).to.match( + /\/.posit\/publish\/deployments\/deployment-[A-Z0-9]{4}\.toml/, + ); + }); + cy.publisherWebview() .findByTestId("deploy-button") .should("be.visible")