Skip to content

Commit

Permalink
Speed up tool tests
Browse files Browse the repository at this point in the history
Shaves a few seconds off. Kinda disappointing, I was expecting it to be more of an improvement.
Is it worth the complexity? Well, I can always go back to doing visit() before each test, if resetting the state gets more complicated.
(As long as I don't introduce actual dependency on the state from earlier tests.)
  • Loading branch information
1j01 committed May 29, 2020
1 parent b841704 commit 96698d0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
20 changes: 19 additions & 1 deletion cypress/integration/tool-tests.spec.js
Expand Up @@ -7,10 +7,28 @@ context('tool tests', () => {
failureThresholdType: 'pixel'
};

beforeEach(() => {
// beforeAll isn't a thing, and beforeEach applies also to tests declared above it,
// so do this fake test + flag hack in order to execute some steps before the first test
let before_first_real_test = true;
it(`(fake test for setup)`, () => {
cy.visit('/')
cy.setResolution([800, 500]);
cy.window().should('have.property', 'colors'); // wait for app to be loaded
before_first_real_test = false;
});
beforeEach(() => {
if (before_first_real_test) return;
cy.window().then({timeout: 60000}, async (win)=> {
win.colors.foreground = "#000";
win.colors.background = "#fff";
win.brush_shape = win.default_brush_shape;
win.brush_size = win.default_brush_size
win.eraser_size = win.default_eraser_size;
win.airbrush_size = win.default_airbrush_size;
win.pencil_size = win.default_pencil_size;
win.stroke_size = win.default_stroke_size;
win.clear();
});
});

const simulateGesture = (win, {start, end, shift, shiftToggleChance=0.01, secondary, secondaryToggleChance, target}) => {
Expand Down
20 changes: 14 additions & 6 deletions src/app.js
Expand Up @@ -26,12 +26,20 @@ let palette = default_palette;
let polychrome_palette = palette;
let monochrome_palette = make_monochrome_palette();

let brush_shape = "circle";
let brush_size = 4;
let eraser_size = 8;
let airbrush_size = 9;
let pencil_size = 1;
let stroke_size = 1; // lines, curves, shape outlines
// declared like this for Cypress tests
window.default_brush_shape = "circle";
window.default_brush_size = 4;
window.default_eraser_size = 8;
window.default_airbrush_size = 9;
window.default_pencil_size = 1;
window.default_stroke_size = 1; // applies to lines, curves, shape outlines
// declared like this for Cypress tests
window.brush_shape = default_brush_shape;
window.brush_size = default_brush_size
window.eraser_size = default_eraser_size;
window.airbrush_size = default_airbrush_size;
window.pencil_size = default_pencil_size;
window.stroke_size = default_stroke_size; // applies to lines, curves, shape outlines
let tool_transparent_mode = false;

let stroke_color;
Expand Down

0 comments on commit 96698d0

Please sign in to comment.