8000 curContext returns wrong values when used together with popStyle() in unit test · Issue #254 · processing-js/processing-js · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Dec 5, 2018. It is now read-only.
This repository was archived by the owner on Dec 5, 2018. It is now read-only.
curContext returns wrong values when used together with popStyle() in unit test #254
Open
@atgeflu

Description

@atgeflu

The following code will return different results when run in the browser or run as a unit test:

size(100,100);
var curContext = externals.context;

ellipse(0, 50, 33, 33);  // Left circle
console.log("expected 1/#ffffff (or rgba(255,255,255,1)): " + curContext.lineWidth + "/" + curContext.fillStyle);

pushStyle();  // Start a new style
strokeWeight(10);
fill(204, 153, 0);
ellipse(33, 50, 33, 33);  // Left-middle circle
console.log("expected 10/#cc9900 (or rgba(204,153,0,1)): " + curContext.lineWidth + "/" + curContext.fillStyle);

pushStyle();  // Start another new style
strokeWeight(8);
fill(153, 0, 0);
stroke(0, 102, 153);
ellipse(66, 50, 33, 33);  // Right-middle circle
console.log("expected 8/#990000 (or rgba(153,0,0,1)): " + curContext.lineWidth + "/" + curContext.fillStyle);
popStyle();  // Restore previous style

console.log("expected 10/#cc9900 (or rgba(204,153,0,1)): " + curContext.lineWidth + "/" + curContext.fillStyle);

popStyle();  // Restore original style

console.log("expected 1/#ffffff (or rgba(255,255,255,1)): " + curContext.lineWidth + "/" + curContext.fillStyle);

ellipse(100, 50, 33, 33);  // Right circle

In the browser all console.log calls will show the correct results. When run as unit tests curContext.lineWidth will return function () {} instead of 1 on the first console.log call. The second and third calls will be correct but the last two console.log calls will incorrectly show the same result as the third one (in other words popStyle will have no effect on the values of curContext.lineWidth and curContext.fillStyle.

See discussion in #234 as to where the potential issue may lie.

If this can be fixed it'd be good to later add unit tests for most style changes that can be done with pushStyle/popStyle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0