-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(test): add initial test harness and one simple test
- ensure that width/height of canvas are trimmed down after drawing a purple rectangle in the center - add test script that uses jest - (ci): change CI to run test and test:pub - configure jest and babel-jest - add coverage/ directory to gitignore - add babel-jest@23 for Babel 6 support - and configure it for .js files due to a jest bug - add .babelrc to configure babel-jest - can't use .babelrc.js as babel-jest@23 doesn't support it - jestjs/jest#5324 - can't use .babelrc for babel-loader (have to duplicate config) because babel-loader@6 has some bugs with it and babel-loader@7 doesn't support webpack@1 - babel/babel-loader#552 (deps): add jest, babel-jest, and canvas-prebuilt to devDeps - add canvas-prebuilt@1 to support jest's jsdom v11 - canvas is used by jsdom for, well, canvas interactions
- Loading branch information
Showing
6 changed files
with
33 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["es2015"] | ||
} |
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ npm-debug.log* | |
node_modules/ | ||
|
||
build/ | ||
coverage/ | ||
*.tgz | ||
|
||
.DS_Store | ||
|
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
transform: { | ||
// use babel-jest@23 for babel@6 support (https://github.com/facebook/jest/issues/8230#issuecomment-479470547) | ||
'\\.js$': require.resolve('babel-jest') | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import trimCanvas from '../index.js' | ||
|
||
describe('trimCanvas', () => { | ||
it('should trim whitespace', () => { | ||
const canvas = document.createElement('canvas') | ||
const ctx = canvas.getContext('2d') | ||
canvas.width = 1000 | ||
canvas.height = 1000 | ||
|
||
ctx.fillStyle = 'purple' | ||
ctx.fillRect(450, 450, 100, 100) // 100x100 purple box in center | ||
|
||
trimCanvas(canvas) | ||
expect(canvas.width).toBe(100) | ||
expect(canvas.height).toBe(100) | ||
}) | ||
}) |