mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
add cypress scaffolding
This commit is contained in:
parent
3fb6f0413e
commit
9bffa6e52c
9 changed files with 100 additions and 1 deletions
3
cypress.json
Normal file
3
cypress.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"baseUrl": "http://localhost:3000/"
|
||||||
|
}
|
6
cypress/.eslintrc.js
Normal file
6
cypress/.eslintrc.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
module.exports = {
|
||||||
|
globals: {
|
||||||
|
Cypress: "readonly",
|
||||||
|
cy: "readonly"
|
||||||
|
}
|
||||||
|
};
|
5
cypress/fixtures/example.json
Normal file
5
cypress/fixtures/example.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"name": "Using fixtures to represent data",
|
||||||
|
"email": "hello@cypress.io",
|
||||||
|
"body": "Fixtures are a great way to mock data for responses to routes"
|
||||||
|
}
|
10
cypress/integration/basic.spec.js
Normal file
10
cypress/integration/basic.spec.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import { tools } from "../support/constants.js";
|
||||||
|
|
||||||
|
describe("Drawing elements", () => {
|
||||||
|
it("should draw rectangle", () => {
|
||||||
|
cy.visit("/");
|
||||||
|
cy.viewport(600, 600);
|
||||||
|
cy.pickTool(tools.rectangle);
|
||||||
|
cy.get("#canvas").canvasDrag({ x: 50, y: 50 }, { x: 100, y: 100 });
|
||||||
|
});
|
||||||
|
});
|
7
cypress/plugins/index.js
Normal file
7
cypress/plugins/index.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
module.exports = (on, config) => {
|
||||||
|
on(`before:browser:launch`, (browser = {}, args) => {
|
||||||
|
if (browser.name === `chrome`) {
|
||||||
|
return args.concat(`--auto-open-devtools-for-tabs`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
39
cypress/support/commands.js
Normal file
39
cypress/support/commands.js
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
function normalizeCoords(coords) {
|
||||||
|
// Note: Cypress seems to check against falsiness (thus 0 values are
|
||||||
|
// considered as not supplied, and position defualts to "center").
|
||||||
|
// Until fixed, default to `1`
|
||||||
|
// See https://github.com/cypress-io/cypress/issues/2338
|
||||||
|
return {
|
||||||
|
x: coords.x || 1,
|
||||||
|
y: coords.y || 1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Cypress.Commands.add("pickTool", { prevSubject: false }, tool =>
|
||||||
|
cy.contains("label", tool).click()
|
||||||
|
);
|
||||||
|
|
||||||
|
Cypress.Commands.add(
|
||||||
|
"canvasClick",
|
||||||
|
{ prevSubject: true },
|
||||||
|
($canvas, coords) => {
|
||||||
|
coords = normalizeCoords(coords);
|
||||||
|
cy.wrap($canvas)
|
||||||
|
.trigger("mousedown", coords.x, coords.y)
|
||||||
|
.trigger("mouseup", coords.x, coords.y);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Cypress.Commands.add(
|
||||||
|
"canvasDrag",
|
||||||
|
{ prevSubject: true },
|
||||||
|
($canvas, startCoods, endCoords) => {
|
||||||
|
startCoods = normalizeCoords(startCoods);
|
||||||
|
endCoords = normalizeCoords(endCoords);
|
||||||
|
|
||||||
|
cy.wrap($canvas)
|
||||||
|
.trigger("mousedown", startCoods.x, startCoods.y)
|
||||||
|
.trigger("mousemove", endCoords.x, endCoords.y)
|
||||||
|
.trigger("mouseup", endCoords.x, endCoords.y);
|
||||||
|
}
|
||||||
|
);
|
9
cypress/support/constants.js
Normal file
9
cypress/support/constants.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
export default {
|
||||||
|
tools: {
|
||||||
|
rectangle: /rectangle/i,
|
||||||
|
ellipse: /ellipse/i,
|
||||||
|
arrow: /arrow/i,
|
||||||
|
text: /text/i,
|
||||||
|
selection: /selection/i
|
||||||
|
}
|
||||||
|
};
|
20
cypress/support/index.js
Normal file
20
cypress/support/index.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
// ***********************************************************
|
||||||
|
// This example support/index.js is processed and
|
||||||
|
// loaded automatically before your test files.
|
||||||
|
//
|
||||||
|
// This is a great place to put global configuration and
|
||||||
|
// behavior that modifies Cypress.
|
||||||
|
//
|
||||||
|
// You can change the location of this file or turn off
|
||||||
|
// automatically serving support files with the
|
||||||
|
// 'supportFile' configuration option.
|
||||||
|
//
|
||||||
|
// You can read more here:
|
||||||
|
// https://on.cypress.io/configuration
|
||||||
|
// ***********************************************************
|
||||||
|
|
||||||
|
// Import commands.js using ES2015 syntax:
|
||||||
|
import "./commands";
|
||||||
|
|
||||||
|
// Alternatively you can use CommonJS syntax:
|
||||||
|
// require('./commands')
|
|
@ -15,7 +15,7 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/react": "16.9.17",
|
"@types/react": "16.9.17",
|
||||||
"@types/react-dom": "16.9.4",
|
"@types/react-dom": "16.9.4",
|
||||||
"gh-pages": "2.1.1",
|
"cypress": "^3.8.1",
|
||||||
"husky": "3.1.0",
|
"husky": "3.1.0",
|
||||||
"lint-staged": "9.5.0",
|
"lint-staged": "9.5.0",
|
||||||
"prettier": "1.19.1",
|
"prettier": "1.19.1",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue