Skip to content

Commit

Permalink
feat(prettier): add prettier, update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
jtenner authored and hustcc committed Apr 17, 2020
1 parent 90fc2bf commit 872079e
Show file tree
Hide file tree
Showing 75 changed files with 1,415 additions and 751 deletions.
7 changes: 0 additions & 7 deletions .npmignore

This file was deleted.

14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: node_js
node_js:
- "8"
- "9"
- "10"
- "11"
- "12"
- "13"
- '8'
- '9'
- '10'
- '11'
- '12'
- '13'
after_success:
- npm run coveralls
- npm run coveralls
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ The function will do `Number` type coercion and verify the inputs exactly like t
this is valid input.

```ts
expect(() => ctx.arc("10", "10", "20", "0", "6.14")).not.toThrow();
expect(() => ctx.arc('10', '10', '20', '0', '6.14')).not.toThrow();
```

Another part of the strategy is to validate input types. When using the
`CanvasRenderingContext2D#fill` function, if you pass it an invalid `fillRule` it will throw a
`TypeError` just like the browser does.

```ts
expect(() => ctx.fill("invalid!")).toThrow(TypeError);
expect(() => ctx.fill(new Path2D(), "invalid!")).toThrow(TypeError);
expect(() => ctx.fill('invalid!')).toThrow(TypeError);
expect(() => ctx.fill(new Path2D(), 'invalid!')).toThrow(TypeError);
```

We try to follow the ECMAScript specification as closely as possible.

## Snapshots

There are multiple ways to validate canvas state using snapshots. There are currently three methods
There are multiple ways to validate canvas state using snapshots. There are currently three methods
attached to the `CanvasRenderingContext2D` class. The first way to use this feature is by using the
`__getEvents` method.

Expand Down Expand Up @@ -175,10 +175,10 @@ canvas.toDataURL.mockReturnValueOnce(

## Contributors

* [@hustcc](https://github.com/hustcc)
* [@jtenner](https://github.com/jtenner)
* [@evanoc0](https://github.com/evanoc0)
- [@hustcc](https://github.com/hustcc)
- [@jtenner](https://github.com/jtenner)
- [@evanoc0](https://github.com/evanoc0)

## License

MIT@[hustcc](https://github.com/hustcc).
MIT@[hustcc](https://github.com/hustcc).
4 changes: 2 additions & 2 deletions __tests__/classes/CanvasGradient.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ beforeEach(() => {
describe('CanvasGradient', () => {
test('CanvasGradient', () => {
expect(grd).toBeDefined();
grd.addColorStop(1.0, "blue");
grd.addColorStop(1.0, 'blue');
expect(grd.addColorStop).toBeCalledWith(1.0, 'blue');

const grd2 = ctx.createLinearGradient(2, 3, 4, 5);
Expand All @@ -22,7 +22,7 @@ describe('CanvasGradient', () => {
expect(grd1.addColorStop).not.toBe(grd2.addColorStop);
});

[Infinity, NaN, -Infinity].forEach(value => {
[Infinity, NaN, -Infinity].forEach((value) => {
test('CanvasGradient should throw if offset is ' + value, () => {
expect(() => {
var grd = ctx.createLinearGradient(1, 2, 3, 4);
Expand Down
1 change: 0 additions & 1 deletion __tests__/classes/CanvasPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ beforeEach(() => {
});

describe('CanvasPattern', () => {

test('CanvasPattern', () => {
const ptrn = ctx.createPattern(img, 'no-repeat');
expect(ptrn).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
let ctx;
beforeEach(() => {
// get a new context each test
ctx = document.createElement('canvas')
.getContext('2d');
ctx = document.createElement('canvas').getContext('2d');
});

afterEach(() => {
Expand All @@ -11,12 +10,12 @@ afterEach(() => {
});

describe('__clearDrawCalls', () => {
it("should clear the list of draw calls", () => {
it('should clear the list of draw calls', () => {
ctx.fillRect(1, 2, 3, 4);
ctx.__clearDrawCalls();
});

it("should not prevent additional draw calls from being collected", () => {
it('should not prevent additional draw calls from being collected', () => {
ctx.fillRect(1, 2, 3, 4);
ctx.__clearDrawCalls();
ctx.fillRect(1, 2, 3, 4);
Expand Down
7 changes: 3 additions & 4 deletions __tests__/classes/CanvasRenderingContext2D.__clearEvents.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
let ctx;
beforeEach(() => {
// get a new context each test
ctx = document.createElement('canvas')
.getContext('2d');
ctx = document.createElement('canvas').getContext('2d');
});

afterEach(() => {
Expand All @@ -11,12 +10,12 @@ afterEach(() => {
});

describe('__clearEvents', () => {
it("should clear the list of events", () => {
it('should clear the list of events', () => {
ctx.fillRect(1, 2, 3, 4);
ctx.__clearEvents();
});

it("should not prevent additional events from being collected", () => {
it('should not prevent additional events from being collected', () => {
ctx.fillRect(1, 2, 3, 4);
ctx.__clearEvents();
ctx.fillRect(1, 2, 3, 4);
Expand Down
7 changes: 3 additions & 4 deletions __tests__/classes/CanvasRenderingContext2D.__clearPath.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
let ctx;
beforeEach(() => {
// get a new context each test
ctx = document.createElement('canvas')
.getContext('2d');
ctx = document.createElement('canvas').getContext('2d');
});

afterEach(() => {
Expand All @@ -11,12 +10,12 @@ afterEach(() => {
});

describe('__clearEvents', () => {
it("should clear the list of events", () => {
it('should clear the list of events', () => {
ctx.arc(1, 2, 3, 4, 5);
ctx.__clearPath();
});

it("should not prevent additional events from being collected", () => {
it('should not prevent additional events from being collected', () => {
ctx.arc(1, 2, 3, 4, 5);
ctx.__clearPath();
ctx.arc(1, 2, 3, 4, 5);
Expand Down
11 changes: 5 additions & 6 deletions __tests__/classes/CanvasRenderingContext2D.__getClippingPath.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
let ctx;
beforeEach(() => {
// get a new context each test
ctx = document.createElement('canvas')
.getContext('2d');
ctx = document.createElement('canvas').getContext('2d');
});

afterEach(() => {
Expand All @@ -11,11 +10,11 @@ afterEach(() => {
});

describe('__getClippingRegion', () => {
it("should be empty when there are no path elements", () => {
it('should be empty when there are no path elements', () => {
ctx.clip();
});

it("should store the clipping region", () => {
it('should store the clipping region', () => {
ctx.rect(1, 2, 3, 4);
ctx.arc(1, 2, 3, 4, 5);
ctx.clip();
Expand All @@ -30,7 +29,7 @@ describe('__getClippingRegion', () => {
ctx.clip();
});

it("should save the clipping region correctly when saved", () => {
it('should save the clipping region correctly when saved', () => {
ctx.rect(1, 2, 3, 4);
ctx.arc(1, 2, 3, 4, 5);
ctx.clip();
Expand All @@ -39,7 +38,7 @@ describe('__getClippingRegion', () => {
expect(region).toStrictEqual(ctx.__getClippingRegion());
});

it("should save the clipping region correctly when saved", () => {
it('should save the clipping region correctly when saved', () => {
ctx.rect(1, 2, 3, 4);
ctx.arc(1, 2, 3, 4, 5);
ctx.clip();
Expand Down
3 changes: 1 addition & 2 deletions __tests__/classes/CanvasRenderingContext2D.__getDrawCalls.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
let ctx;
beforeEach(() => {
// get a new context each test
ctx = document.createElement('canvas')
.getContext('2d');
ctx = document.createElement('canvas').getContext('2d');
});

const img = new Image();
Expand Down
3 changes: 1 addition & 2 deletions __tests__/classes/CanvasRenderingContext2D.__getEvents.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
let ctx;
beforeEach(() => {
// get a new context each test
ctx = document.createElement('canvas')
.getContext('2d');
ctx = document.createElement('canvas').getContext('2d');
});

const img = new Image();
Expand Down
3 changes: 1 addition & 2 deletions __tests__/classes/CanvasRenderingContext2D.__getPath.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
let ctx;
beforeEach(() => {
// get a new context each test
ctx = document.createElement('canvas')
.getContext('2d');
ctx = document.createElement('canvas').getContext('2d');
});

const path = new Path2D();
Expand Down
14 changes: 10 additions & 4 deletions __tests__/classes/CanvasRenderingContext2D.addHitRegion.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ describe('addHitRegion', () => {
expect(() => ctx.addHitRegion()).toThrow(DOMException);
});

it('should throw if fillRule is set and isn\'t \'evenodd\' or \'nonzero\'', () => {
expect(() => ctx.addHitRegion({ id: 'test', fillRule: 'wrong!' })).toThrow();
it("should throw if fillRule is set and isn't 'evenodd' or 'nonzero'", () => {
expect(() =>
ctx.addHitRegion({ id: 'test', fillRule: 'wrong!' })
).toThrow();
});

it('should not throw if fillRule is valid', () => {
expect(() => ctx.addHitRegion({ id: 'test', fillRule: 'evenodd' })).not.toThrow();
expect(() => ctx.addHitRegion({ id: 'test', fillRule: 'nonzero' })).not.toThrow();
expect(() =>
ctx.addHitRegion({ id: 'test', fillRule: 'evenodd' })
).not.toThrow();
expect(() =>
ctx.addHitRegion({ id: 'test', fillRule: 'nonzero' })
).not.toThrow();
});
});
6 changes: 3 additions & 3 deletions __tests__/classes/CanvasRenderingContext2D.arc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ describe('arc', () => {
expect(ctx.arc).toBeCalled();
});

it('shouldn\'t accept parameters less than 7', () => {
it("shouldn't accept parameters less than 7", () => {
expect(() => ctx.arc()).toThrow(TypeError);
expect(() => ctx.arc(1)).toThrow(TypeError);
expect(() => ctx.arc(1, 2,)).toThrow(TypeError);
expect(() => ctx.arc(1, 2)).toThrow(TypeError);
expect(() => ctx.arc(1, 2, 3)).toThrow(TypeError);
expect(() => ctx.arc(1, 2, 3, 4)).toThrow(TypeError);
});
Expand All @@ -37,7 +37,7 @@ describe('arc', () => {
[1, 2, NaN, 4, 5],
[1, 2, 3, NaN, 5],
[1, 2, 3, 4, NaN],
].forEach(e => {
].forEach((e) => {
expect(() => ctx.arc(...e)).not.toThrow();
});
});
Expand Down
8 changes: 4 additions & 4 deletions __tests__/classes/CanvasRenderingContext2D.arcTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('arcTo', () => {
expect(ctx.arcTo).toBeCalled();
});

it('shouldn\'t accept parameters less than 5', () => {
it("shouldn't accept parameters less than 5", () => {
expect(() => ctx.arcTo(1, 2, 3)).toThrow(DOMException);
});

Expand All @@ -31,7 +31,7 @@ describe('arcTo', () => {
[1, 2, 3, 4, 5],
[null, void 0, '', NaN, Infinity],
[-100, -100, 100, 0, 0],
].forEach(e => {
].forEach((e) => {
expect(() => ctx.arcTo(...e)).not.toThrow();
});
});
Expand All @@ -42,8 +42,8 @@ describe('arcTo', () => {
[1, NaN, 2, 3, -1],
[1, 2, NaN, 3, -1],
[1, 2, 3, NaN, -1],
].forEach(e => {
].forEach((e) => {
expect(() => ctx.arcTo(...e)).not.toThrow();
});
});
})
});
7 changes: 3 additions & 4 deletions __tests__/classes/CanvasRenderingContext2D.clip.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@ describe('clip', () => {
});

it('should clip paths', () => {
expect(() => ctx.clip(p)).not.toThrow();
expect(() => ctx.clip(p)).not.toThrow();
});

it('should throw if clipRule is not valid clipRule', () => {
[null, 1, Infinity, NaN, void 0, 'bad!'].forEach(e => {
[null, 1, Infinity, NaN, void 0, 'bad!'].forEach((e) => {
expect(() => ctx.clip(p, e)).toThrow(TypeError);
expect(() => ctx.clip(e)).toThrow(TypeError);
});
});

it('should accept valid fillRules', () => {
['evenodd', 'nonzero'].forEach(e => {
['evenodd', 'nonzero'].forEach((e) => {
expect(() => ctx.clip(e)).not.toThrow();
expect(() => ctx.clip(p, e)).not.toThrow();
});
});
});

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('createImageData', () => {
[NaN, 1],
[1, NaN],
['test', null],
].forEach(value => {
].forEach((value) => {
expect(() => ctx.createImageData(...value)).toThrow(TypeError);
});
});
Expand Down
Loading

0 comments on commit 872079e

Please sign in to comment.