Skip to content

Setup Prettier for test/cy code #1198

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

Merged
merged 9 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ jobs:
- run: just web install
- run: just web lint
- run: just web check-format

- run: just test/cy install
- run: just test/cy lint
- run: just test/cy check-format
12 changes: 6 additions & 6 deletions test/cy/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
extends: ['plugin:cypress/recommended'],
plugins: ['cypress'],
env: {
'cypress/globals': true,
}
};
extends: ["plugin:cypress/recommended", "prettier"],
plugins: ["cypress"],
env: {
"cypress/globals": true,
},
};
1 change: 1 addition & 0 deletions test/cy/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion test/cy/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ module.exports = defineConfig({
},
viewportHeight: 1080,
viewportWidth: 1920,
video: true
video: true,
},
});
65 changes: 35 additions & 30 deletions test/cy/cypress/e2e/contract/deploy.cy.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,55 @@
describe('Publish', () => {
it('publish content and check app type', () => {
describe("Publish", () => {
it("publish content and check app type", () => {
cy.visit({
url: '/',
qs: { token: Cypress.env('token') }
url: "/",
qs: { token: Cypress.env("token") },
});

// Add a New Deployment button
cy.get('div[data-automation="add-new-deployment"]')
.click();
cy.get('div[data-automation="add-new-deployment"]').click();

// Continue to Deploy
// ensure accounts are loaded to stall before clicking
cy.get('label[data-automation="account"]')
.should('exist');
cy.get('button[data-automation="continue-deployment"]')
.click();
cy.get('label[data-automation="account"]').should("exist");
cy.get('button[data-automation="continue-deployment"]').click();

// Deploy
cy.get('button[data-automation="deploy"]')
.click();
cy.get('button[data-automation="deploy"]').click();

// Wait for Deployment Success message
cy.get('div[data-automation="deploy-message"]', { timeout: 30000 })
.contains("Deploy was successful!");
cy.get('div[data-automation="deploy-message"]', {
timeout: 30000,
}).contains("Deploy was successful!");

// Get the link from the deployment logs
cy.get('a[href="#/progress')
.click();
cy.get('a[href="#/progress').click();
cy.get('div[class="space-between-sm"]')
.find('p').last().invoke('text').then((guid) => {
Cypress.env('DEPLOYED_APP_URL', '/__api__/v1/content/' + guid);
cy.log("MY GUID " + Cypress.env('DEPLOYED_APP_URL'));
cy.log("MY URL " + Cypress.env('CYPRESS_CONNECT_ADDRESS') + Cypress.env('DEPLOYED_APP_URL'))
.find("p")
.last()
.invoke("text")
.then((guid) => {
Cypress.env("DEPLOYED_APP_URL", "/__api__/v1/content/" + guid);
cy.log("MY GUID " + Cypress.env("DEPLOYED_APP_URL"));
cy.log(
"MY URL " +
Cypress.env("CYPRESS_CONNECT_ADDRESS") +
Cypress.env("DEPLOYED_APP_URL"),
);

// Use API to check the content on Connect
cy.request({
method: 'GET',
url: Cypress.env('CYPRESS_CONNECT_ADDRESS') + Cypress.env('DEPLOYED_APP_URL'),
'auth': {
'bearer': Cypress.env('CONNECT_API_KEY')
},
}).then((response) => {
expect(response.status).to.equal(200);
// app mode should be correct
expect(response.body).to.have.property('app_mode', 'python-fastapi')
method: "GET",
url:
Cypress.env("CYPRESS_CONNECT_ADDRESS") +
Cypress.env("DEPLOYED_APP_URL"),
auth: {
bearer: Cypress.env("CONNECT_API_KEY"),
},
}).then((response) => {
expect(response.status).to.equal(200);
// app mode should be correct
expect(response.body).to.have.property("app_mode", "python-fastapi");
});
});
});
});
});
55 changes: 26 additions & 29 deletions test/cy/cypress/e2e/ui/home.cy.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,51 @@
describe('Landing', () => {
describe("Landing", () => {
beforeEach(() => {
cy.visit({
url: '/',
url: "/",
});
});
it('.should() - assert that <title> is correct', () => {
cy.title().should('include', 'Posit Publisher');
it(".should() - assert that <title> is correct", () => {
cy.title().should("include", "Posit Publisher");
});
it('dark mode works', () => {

it("dark mode works", () => {
// expand dark mode menu
cy.expandDarkMenu();
cy.get('body').should('have.css', 'background-color', 'rgb(250, 250, 250)');
cy.get("body").should("have.css", "background-color", "rgb(250, 250, 250)");

// set dark mode on
cy.get('div[data-automation="dark-on"]')
.click();
cy.get('body').should('have.css', 'background-color', 'rgb(18, 18, 18)');
cy.get('div[data-automation="dark-on"]').click();
cy.get("body").should("have.css", "background-color", "rgb(18, 18, 18)");

cy.expandDarkMenu();
// set dark mode off
cy.get('div[data-automation="dark-off"]')
.click();
cy.get('body').should('have.css', 'background-color', 'rgb(250, 250, 250)');
cy.get('div[data-automation="dark-off"]').click();
cy.get("body").should("have.css", "background-color", "rgb(250, 250, 250)");

cy.expandDarkMenu();
// set dark mode auto
cy.get('div[data-automation="dark-auto"]')
.click();
cy.get('body').should('have.css', 'background-color', 'rgb(250, 250, 250)');
cy.get('div[data-automation="dark-auto"]').click();
cy.get("body").should("have.css", "background-color", "rgb(250, 250, 250)");
});

// disabling configuration file test temporarily
// it('configuration file is displayed', () => {
// cy.get('div[data-automation="config-card"]')
// .find('h3[class="card-title truncate"]')
// .contains("default");
// });
// disabling configuration file test temporarily
// it('configuration file is displayed', () => {
// cy.get('div[data-automation="config-card"]')
// .find('h3[class="card-title truncate"]')
// .contains("default");
// });

// cy.get('div[data-automation="config-card"]')
// .find('p')
// .should('contain', '.posit')
// .and('contain', 'publish')
// .and('contain', 'default.toml');
// });

it('files are displayed', () => {
cy.get('div[data-automation="file-tree"]')
.should('contain', 'fastapi-simple')
.and('contain', 'requirements.txt')
.and('contain', 'simple.py');
it("files are displayed", () => {
cy.get('div[data-automation="file-tree"]')
.should("contain", "fastapi-simple")
.and("contain", "requirements.txt")
.and("contain", "simple.py");
});
});
});
13 changes: 5 additions & 8 deletions test/cy/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

Cypress.Commands.add('expandDarkMenu', () => {
cy.get('button[data-automation="menu-button"]')
.click();
cy.get('div[data-automation="dark-mode-submenu"]')
.click();
cy.get('div[data-automation="dark-on"]')
.should('be.visible');
});
Cypress.Commands.add("expandDarkMenu", () => {
cy.get('button[data-automation="menu-button"]').click();
cy.get('div[data-automation="dark-mode-submenu"]').click();
cy.get('div[data-automation="dark-on"]').should("be.visible");
});
4 changes: 2 additions & 2 deletions test/cy/cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
import "./commands";

// Alternatively you can use CommonJS syntax:
// require('./commands')
// require('./commands')
14 changes: 14 additions & 0 deletions test/cy/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ lint:

npm run lint

format:
#!/usr/bin/env bash
set -eou pipefail
{{ _with_debug }}

npm run format

check-format:
#!/usr/bin/env bash
set -eou pipefail
{{ _with_debug }}

npm run check-format

# Install dependencies
install:
#!/usr/bin/env bash
Expand Down
29 changes: 29 additions & 0 deletions test/cy/package-lock.json

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

4 changes: 4 additions & 0 deletions test/cy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"scripts": {
"lint": "eslint --ext .js,.ts,.cjs .",
"fix": "eslint --ext .js,.ts,.cjs . --fix",
"format": "prettier . --write",
"check-format": "prettier . --check",
"init": "just ../../run init ./test/sample-content/fastapi-simple",
"start": "just ../../run ui --listen 127.0.0.1:9000 ./test/sample-content/fastapi-simple",
"test": "start-server-and-test --expect 200 start http-get://127.0.0.1:9000 run",
Expand All @@ -18,7 +20,9 @@
"devDependencies": {
"cypress": "^13.3.0",
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-cypress": "^2.15.1",
"prettier": "3.2.5",
"start-server-and-test": "^2.0.3"
}
}