-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* reapply changes so it avoids conflicts * add pattern setTransform parameter check, increase code coverage to 100%, update to @babel/plugin-proposal-class-properties * add path 2d tests * fix var, double quotes to single quotes * fix addHitRegion, arcTo tests, update travis to remove node 4 and 5, add 9, 10, 11
- Loading branch information
Showing
80 changed files
with
1,521 additions
and
1,489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"presets": ["env"], | ||
"plugins": ["transform-class-properties", "version"] | ||
"presets": ["@babel/env"], | ||
"plugins": ["@babel/proposal-class-properties", "version"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
language: node_js | ||
node_js: | ||
- "4" | ||
- "5" | ||
- "6" | ||
- "7" | ||
- "8" | ||
- "9" | ||
- "10" | ||
- "11" | ||
after_success: | ||
- npm run coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
import mockWindow from '../../src/window'; | ||
let ctx; | ||
let grd; | ||
|
||
beforeEach(() => { | ||
ctx = document.createElement('canvas').getContext('2d'); | ||
grd = ctx.createLinearGradient(1, 2, 3, 4); | ||
}); | ||
|
||
describe('CanvasGradient', () => { | ||
|
||
test('CanvasGradient', () => { | ||
const canvasGradient = new CanvasGradient(); | ||
|
||
expect(canvasGradient).toBeDefined(); | ||
|
||
canvasGradient.addColorStop(); | ||
expect(grd).toBeDefined(); | ||
grd.addColorStop(); | ||
expect(grd.addColorStop).toBeCalled(); | ||
|
||
expect(canvasGradient.addColorStop).toBeCalled(); | ||
|
||
const other = new CanvasGradient(); | ||
expect(other.addColorStop).not.toBeCalled(); | ||
const grd2 = ctx.createLinearGradient(2, 3, 4, 5); | ||
expect(grd2.addColorStop).not.toBeCalled(); | ||
}); | ||
|
||
test('CanvasGradient different instance', () => { | ||
const canvasGradient1 = new CanvasGradient(); | ||
const canvasGradient2 = new CanvasGradient(); | ||
expect(canvasGradient1.addColorStop).not.toBe(canvasGradient2.addColorStop); | ||
}); | ||
|
||
test('CanvasGradient not override', () => { | ||
const saved = window.CanvasGradient; | ||
mockWindow(window); | ||
expect(saved === window.CanvasGradient).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,42 @@ | ||
import mockWindow from '../../src/window'; | ||
let ctx; | ||
let canvas; | ||
const img = new Image(); | ||
img.src = 'https://placekitten.com/400/300'; | ||
|
||
beforeEach(() => { | ||
canvas = document.createElement('canvas'); | ||
canvas.width = 400; | ||
canvas.height = 300; | ||
ctx = canvas.getContext('2d'); | ||
}); | ||
|
||
describe('CanvasPattern', () => { | ||
|
||
test('CanvasPattern', () => { | ||
const canvasPattern = new CanvasPattern(); | ||
|
||
const canvasPattern = ctx.createPattern(img, 'no-repeat'); | ||
expect(canvasPattern).toBeDefined(); | ||
expect(canvasPattern).toBeInstanceOf(CanvasPattern); | ||
}); | ||
|
||
canvasPattern.setTransform(); | ||
it('should have a setTransform function', () => { | ||
const canvasPattern = ctx.createPattern(img, 'no-repeat'); | ||
expect(typeof canvasPattern.setTransform).toBe('function'); | ||
}); | ||
|
||
it('should have callable setTransform', () => { | ||
const canvasPattern = ctx.createPattern(img, 'no-repeat'); | ||
canvasPattern.setTransform(ctx.getTransform()); | ||
expect(canvasPattern.setTransform).toBeCalled(); | ||
}); | ||
|
||
const other = new CanvasPattern(); | ||
expect(other.setTransform).not.toBeCalled(); | ||
it('should throw if arguments.length > 0 and transform not instanceof Object', () => { | ||
const canvasPattern = ctx.createPattern(img, 'no-repeat'); | ||
expect(() => canvasPattern.setTransform(1)).toThrow(TypeError); | ||
}); | ||
|
||
test('CanvasPattern different instance', () => { | ||
const canvasPattern1 = new CanvasPattern(); | ||
const canvasPattern2 = new CanvasPattern(); | ||
const canvasPattern1 = ctx.createPattern(img, 'no-repeat'); | ||
const canvasPattern2 = ctx.createPattern(img, 'no-repeat'); | ||
expect(canvasPattern1.setTransform).not.toBe(canvasPattern2.setTransform); | ||
}); | ||
|
||
test('CanvasPattern not override', () => { | ||
const saved = window.CanvasPattern; | ||
mockWindow(window); | ||
expect(saved === window.CanvasPattern).toBe(true); | ||
}); | ||
}); |
27 changes: 14 additions & 13 deletions
27
__tests__/classes/CanvasRenderingContext2D.addHitRegion.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
var canvas; | ||
var ctx; | ||
let canvas; | ||
let ctx; | ||
|
||
beforeEach(() => { | ||
canvas = document.createElement("canvas"); | ||
ctx = canvas.getContext("2d"); | ||
canvas = document.createElement('canvas'); | ||
ctx = canvas.getContext('2d'); | ||
canvas.width = 400; | ||
canvas.height = 300; | ||
}); | ||
|
||
describe("addHitRegion", () => { | ||
it("should be a function", () => { | ||
describe('addHitRegion', () => { | ||
it('should be a function', () => { | ||
expect(ctx.addHitRegion).toBeTruthy(); | ||
}); | ||
it("should be callable", () => { | ||
ctx.addHitRegion({ id: "test" }); | ||
|
||
it('should be callable', () => { | ||
ctx.addHitRegion({ id: 'test' }); | ||
expect(ctx.addHitRegion).toBeCalled(); | ||
}); | ||
|
||
it("should throw if called with no parameters", () => { | ||
it('should throw if called with no parameters', () => { | ||
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(); | ||
expect(() => ctx.addHitRegion({ id: "test", fillRule: "evenodd", })).not.toThrow(); | ||
expect(() => ctx.addHitRegion({ id: "test", fillRule: "nonzero", })).not.toThrow(); | ||
it('should throw if fillRule is set and isn\'t \'evenodd\' or \'nonzero\'', () => { | ||
expect(() => ctx.addHitRegion({ id: 'test', fillRule: 'wrong!' })).toThrow(); | ||
expect(() => ctx.addHitRegion({ id: 'test', fillRule: 'evenodd', })).not.toThrow(); | ||
expect(() => ctx.addHitRegion({ id: 'test', fillRule: 'nonzero', })).not.toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions
18
__tests__/classes/CanvasRenderingContext2D.bezierCurveTo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 8 additions & 8 deletions
16
__tests__/classes/CanvasRenderingContext2D.clearHitRegions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.