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

fix(transform): slice transform on save, node 13 #52

Merged
merged 3 commits into from
Nov 4, 2019
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
11 changes: 10 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"presets": ["@babel/env"],
"presets": [
[
"@babel/env",
{
"targets": {
"node": "8"
}
}
]
],
"plugins": ["@babel/proposal-class-properties", "version"]
}
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
language: node_js
node_js:
- "6"
- "7"
- "8"
- "9"
- "10"
- "11"
- "12"
- "13"
after_success:
- npm run coveralls
30 changes: 19 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# CHANGELOG

# Version 2.1.1
## Version 2.2.0

- Feature: Support for ImageData instantiation using a source array(#45)
- Bug: Slice canvas transform value when pushing (#50)
- Remove support for node 6 and 7
- switch babel env to target node 8
- add support for node 13
- update package versions
- fix lineWidth bug

# Version 2.1.0
## Version 2.1.1

- Feature: Support for ImageData instantiation using a source array (#45)

## Version 2.1.0

This minor version bump now has some major snapshot support but is backwards compatible.

Expand All @@ -29,13 +38,13 @@ Changes:
- Feature: Add `_path` and `_events` to `Path2D`
- Testing: Add and test snapshot outputs

# Version 2.0.0
## Version 2.0.0

Just publish a stable version.

# Version 2.0.0-beta.1
## Version 2.0.0-beta.1

## Class Instances
### Class Instances

The Version 2.0.0-beta.1 of `jest-canvas-mock` is a complete overhaul of the mocking strategy entirely. Originally, the `canvas.getCanvas('2d')` method would return a single object that contained a set of methods without any property definitions. This caused problems for people who wanted to use `jest` to test and verify `instanceof` checks.

Expand All @@ -47,7 +56,7 @@ const ctx = document.createElement('canvas').getContext('2d');
expect(ctx).toBeInstanceOf(CanvasRenderingContext2D);
```

## Bound Mock Functions
### Bound Mock Functions

When each `CanvasRenderingContext2D` object is created, all the methods are properly mocked with the `jest.fn()` method, and bound to the instance. It's still possible to verify that a function was called on the context. The main difference now is that the methods actually perform runtime checks on the passed parameters.

Expand All @@ -64,7 +73,7 @@ expect(ctx.arc).toBeCalledWith(0, 0, 100, 0, PI_2);
expect(() => ctx.arc(0, 0, -10, 0, PI_2)).toThrow(DOMExpection);
```

# Parsing Colors and Fonts, Saving, Restoring
### Parsing Colors and Fonts, Saving, Restoring

Another really big change is that the mocking strategy now attempts to conform to the html living specification. In order to do this, two packages were added as dependencies so that css colors and fonts can be more properly parsed. This is not perfect, and any problems with the color parser or font parser should be reported in the Issues tab.

Expand Down Expand Up @@ -99,7 +108,7 @@ expect(ctx.font).toBe('10px sans-serif');

For all these reasons, the `jest-canvas-mock` package was bumped a major version to `2.0.0`.

## CanvasRenderingContext2D prototype
### CanvasRenderingContext2D prototype

- Implemented Stack Properties for the following items:
- `direction`
Expand Down Expand Up @@ -371,7 +380,7 @@ For all these reasons, the `jest-canvas-mock` package was bumped a major version
- throws `TypeError` if `arguments.length < 2`
- performs a translate operation on the current `transform` stack value if every parameter is finite

## Other Changes By File
### Other Changes By File

- src/CanvasGradient.js
- Added Class for `instanceof` checks
Expand Down Expand Up @@ -452,4 +461,3 @@ For all these reasons, the `jest-canvas-mock` package was bumped a major version
- This function cannot normally be constructed
- mocked to accept a `text` parameter
- sets `width` property to `text.length`

4 changes: 4 additions & 0 deletions __tests__/classes/CanvasRenderingContext2D.lineWidth.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ describe('lineWidth', () => {
ctx.save();
ctx.lineWidth = 10;
expect(ctx.lineWidth).toBe(10);
ctx.save();
expect(ctx.lineWidth).toBe(10);
ctx.restore();
expect(ctx.lineWidth).toBe(10);
ctx.restore();
expect(ctx.lineWidth).toBe(2);
});
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
"parse-color": "^1.0.0"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@commitlint/cli": "^7.5.2",
"@commitlint/config-angular": "^7.5.0",
"babel-jest": "^24.8.0",
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/preset-env": "^7.6.3",
"@commitlint/cli": "^8.2.0",
"@commitlint/config-angular": "^8.2.0",
"babel-jest": "^24.9.0",
"babel-plugin-version": "^0.2.3",
"coveralls": "^3.0.3",
"husky": "^2.2.0",
"jest": "^24.8.0"
"coveralls": "^3.0.7",
"husky": "^3.0.9",
"jest": "^24.9.0"
},
"commitlint": {
"extends": [
Expand Down
4 changes: 2 additions & 2 deletions src/classes/CanvasRenderingContext2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ export default class CanvasRenderingContext2D {
}

save() {
this._transformStack.push(this._transformStack[this._stackIndex]);
this._transformStack.push(this._transformStack[this._stackIndex].slice());
this._directionStack.push(this._directionStack[this._stackIndex]);
this._fillStyleStack.push(this._fillStyleStack[this._stackIndex]);
this._filterStack.push(this._filterStack[this._stackIndex]);
Expand All @@ -1091,7 +1091,7 @@ export default class CanvasRenderingContext2D {
this._lineDashStack.push(this._lineDashStack[this._stackIndex]);
this._lineDashOffsetStack.push(this._lineDashOffsetStack[this._stackIndex]);
this._lineJoinStack.push(this._lineJoinStack[this._stackIndex]);
this._lineWidthStack.push(this._lineWidthStack[this.stackIndex]);
this._lineWidthStack.push(this._lineWidthStack[this._stackIndex]);
this._miterLimitStack.push(this._miterLimitStack[this._stackIndex]);
this._shadowBlurStack.push(this._shadowBlurStack[this._stackIndex]);
this._shadowColorStack.push(this._shadowColorStack[this._stackIndex]);
Expand Down