Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress e2e tooling - New cy.loadProjectConfig to load project configurations in tests #2578

Merged
merged 14 commits into from
Feb 11, 2025
Merged
2 changes: 1 addition & 1 deletion test/e2e/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
27 changes: 27 additions & 0 deletions test/e2e/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "@testing-library/cypress/add-commands";
import toml from "toml";
import "./selectors";

const connectManagerServer = Cypress.env("CONNECT_MANAGER_URL");
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/tests/deployments.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down