-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transition from redux-saga to redux-logic and using Jest to test - Pa…
…rt One (#1655) * CHECKPOINT jest * Fix unnecessary addition of an eslint-disable directive * Initial transition to react-logic. Moved over unlickGithubIdentity logic. Still need to get react-saga and react-logic to play nicely. * Got redux-saga and redux-logic working at the same time. * Attempt to get jest working on IntelliJ * Make jest config more consistent; transform lodash-es * Mocks for bugsnag and firebase libraries These libraries are set up in code that runs at module load time, which is probably not a great practice, but for now we just mock out the libraries themselves so our modules will load without error. * Revert unnecessary change to karma config * Add some jest rules to eslint config * Write test for unlinkGithubIdentityTest.js * Small refactor * Fix yarn.lock with deduplicate * Fix yarn.lock again? * Refactored test, installed jest-extended (but didn't use it) * Fix package.json after rebase * Fix yarn.lock again * Fix incorrect merge with .eslintrc * Add jest override to .eslintrc * Lint fixing
- Loading branch information
Showing
17 changed files
with
1,526 additions
and
109 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
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,26 @@ | ||
import React, {Fragment} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import noop from 'lodash-es/noop'; | ||
|
||
function ErrorBoundary({children}) { | ||
return React.createElement(Fragment, null, children); | ||
} | ||
ErrorBoundary.propTypes = {children: PropTypes.node.isRequired}; | ||
|
||
export default function bugsnag() { | ||
return { | ||
use: noop, | ||
|
||
notify: noop, | ||
|
||
getPlugin(plugin) { | ||
if (plugin === 'react') { | ||
return ErrorBoundary; | ||
} | ||
|
||
throw new Error( | ||
`bugsnagClient.getPlugin mock called with unexpected plugin ${plugin}`, | ||
); | ||
}, | ||
}; | ||
} |
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,2 @@ | ||
const bugsnagReact = {}; | ||
export default bugsnagReact; |
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 constant from 'lodash-es/constant'; | ||
|
||
class AuthProvider { | ||
addScope() {} | ||
} | ||
|
||
export const firebase = { | ||
auth: Object.assign( | ||
() => ({}), | ||
{ | ||
GithubAuthProvider: AuthProvider, | ||
GoogleAuthProvider: AuthProvider, | ||
}, | ||
), | ||
|
||
initializeApp: constant({}), | ||
}; |
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,2 @@ | ||
/* eslint-disable import/no-anonymous-default-export */ | ||
export default {}; |
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,2 @@ | ||
const database = {}; | ||
export default database; |
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,25 +1,38 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
let targets; | ||
if (process.env.DEBUG === 'true') { | ||
targets = {browsers: 'last 1 Chrome version'}; | ||
} else { | ||
targets = JSON.parse( | ||
fs.readFileSync(path.resolve(__dirname, 'config/browsers.json')), | ||
); | ||
} | ||
module.exports = (api) => { | ||
let targets; | ||
|
||
module.exports = { | ||
presets: [ | ||
'@babel/preset-react', | ||
['@babel/preset-env', {targets, modules: false}], | ||
], | ||
plugins: ['@babel/plugin-syntax-dynamic-import'], | ||
compact: false, | ||
overrides: [ | ||
{ | ||
include: './node_modules/parse5-sax-parser/lib/index.js', | ||
}, | ||
], | ||
const isJest = api.caller(({name}) => name === 'babel-jest'); | ||
api.cache.using(() => `${isJest}:${process.env.NODE_ENV}`); | ||
|
||
if (isJest) { | ||
targets = {node: 'current'}; | ||
} else if (process.env.DEBUG === 'true') { | ||
targets = {browsers: 'last 1 Chrome version'}; | ||
} else { | ||
targets = JSON.parse( | ||
fs.readFileSync(path.resolve(__dirname, 'config/browsers.json')), | ||
); | ||
} | ||
|
||
const plugins = ['@babel/plugin-syntax-dynamic-import']; | ||
if (isJest) { | ||
plugins.push('babel-plugin-dynamic-import-node'); | ||
} | ||
|
||
return { | ||
presets: [ | ||
'@babel/preset-react', | ||
['@babel/preset-env', {targets, modules: isJest ? 'auto' : false}], | ||
], | ||
plugins, | ||
compact: false, | ||
overrides: [ | ||
{ | ||
include: './node_modules/parse5-sax-parser/lib/index.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* eslint-env node */ | ||
/* eslint-disable import/no-commonjs */ | ||
|
||
// For a detailed explanation regarding each configuration property, visit: | ||
// https://jestjs.io/docs/en/configuration.html | ||
|
||
module.exports = { | ||
testPathIgnorePatterns: [ | ||
'/node_modules/', | ||
'/bower_components/', | ||
], | ||
transformIgnorePatterns: ['node_modules/(?!(lodash-es)/)'], | ||
setupFilesAfterEnv: ['jest-extended'], | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import unlinkGithubIdentity from '../unlinkGithubIdentity'; | ||
|
||
import {unlinkGithub} from '../../clients/firebase'; | ||
|
||
jest.mock('../../clients/firebase.js'); | ||
|
||
test('should unlink Github Identity', async() => { | ||
const {type, payload: {providerId}} = await unlinkGithubIdentity.process(); | ||
expect(unlinkGithub).toHaveBeenCalledWith(); | ||
expect(type).toBe('IDENTITY_UNLINKED'); | ||
expect(providerId).toBe('github.com'); | ||
}); |
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 @@ | ||
import unlinkGithubIdentity from './unlinkGithubIdentity'; | ||
|
||
export default [unlinkGithubIdentity]; |
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,12 @@ | ||
import {createLogic} from 'redux-logic'; | ||
|
||
import {unlinkGithub} from '../clients/firebase'; | ||
import {identityUnlinked} from '../actions/user'; | ||
|
||
export default createLogic({ | ||
type: 'UNLINK_GITHUB_IDENTITY', | ||
async process() { | ||
await unlinkGithub(); | ||
return identityUnlinked('github.com'); | ||
}, | ||
}); |
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
Oops, something went wrong.