Skip to content

Commit

Permalink
(test): add initial test harness
Browse files Browse the repository at this point in the history
- add 1 simple test for existence of canvas and instance methods
  - (pkg): test code shouldn't be in the package, just source
    - currently preferring to keep source and tests co-located

- change test script to use jest, and move prev test to test:pub
  - (ci): change CI to run test and test:pub
- configure jest and enzyme for testing usage
  - make jest importable too
  - 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 because babel-loader@6
      has some bugs with it and @7 doesn't support webpack@1
      - babel/babel-loader#552

- use jest instead of ava mainly because there's less to
  configure / install (directly at least, still a lot indirectly),
  it's popular / well-supported in React community, and supports
  configuration outside of package.json
  - see #33 for some more details

(deps): add jest, enzyme, and supporting deps to devDeps
- add babel-jest@23 for Babel 6 support
  - and configure it for .js files due to a jest bug
- add canvas-prebuilt@1 to support jest's jsdom v11
  - canvas is used by jsdom for, well, canvas interactions
- add enzyme-adapter-react-16 to configure Enzyme with React 16
  - upgrade to React 16 in devDeps bc adapter-react-15 requires
    react-test-renderer and no drawbacks in upgrading
  • Loading branch information
agilgur5 committed Jul 29, 2019
1 parent 8f0ca6a commit e5a7439
Show file tree
Hide file tree
Showing 8 changed files with 8,965 additions and 1,287 deletions.
7 changes: 7 additions & 0 deletions .babelrc
@@ -0,0 +1,7 @@
{
"presets": [
"es2015",
"react",
"stage-2"
]
}
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -4,3 +4,4 @@ node_js: '8.9'

before_script: npm run lint
script: npm test
after_script: npm run test:pub
14 changes: 14 additions & 0 deletions jest.config.js
@@ -0,0 +1,14 @@
module.exports = {
moduleNameMapper: {
// allow importing of Jest as an ES Module (https://github.com/facebook/jest/pull/7571#issuecomment-498634094)
'^jest$': '<rootDir>/test-utils/jest-export.js'
},
setupFilesAfterEnv: [
// configure enzyme w/ react adapter
'<rootDir>/test-utils/configure-enzyme.js'
],
transform: {
// use babel-jest@23 for babel@6 support (https://github.com/facebook/jest/issues/8230#issuecomment-479470547)
'\\.js$': require.resolve('babel-jest')
}
}

0 comments on commit e5a7439

Please sign in to comment.