-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(jest): Migrate all unit tests from Karma to Jest (#1264)
- Loading branch information
Showing
112 changed files
with
11,949 additions
and
11,367 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
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,15 @@ | ||
const i18n = require('../../src/i18n/json/en-US.json'); | ||
const fixture = require('./fixtureLoader'); | ||
const Worker = require('./workerMock'); | ||
|
||
global.EventEmitter = require('events'); | ||
global.sinon = require('sinon'); | ||
|
||
global.__ = function translate(key) { | ||
return i18n[key] || key; | ||
}; | ||
global.BoxSDK = () => ({}); | ||
global.fixture = fixture; | ||
global.URL.createObjectURL = () => ''; | ||
global.URL.revokeObjectURL = () => ''; | ||
global.Worker = Worker; |
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,18 @@ | ||
import '@testing-library/jest-dom'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
import Enzyme, { mount, shallow } from 'enzyme'; | ||
|
||
expect.extend({ | ||
toContainSelector(received, selector) { | ||
return { | ||
message: `expected ${received} ${this.isNot ? 'not ' : ''}to contain ${selector}`, | ||
pass: !!received.querySelector(selector), | ||
}; | ||
}, | ||
}); | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
// Make Enzyme functions available in all test files without importing | ||
global.shallow = shallow; | ||
global.mount = mount; |
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,35 @@ | ||
Object.defineProperty(global.navigator, 'mimeTypes', { | ||
configurable: true, | ||
value: [], | ||
writable: true, | ||
}); | ||
|
||
Object.defineProperty(document, 'createRange', { | ||
value: () => ({ | ||
commonAncestorContainer: { | ||
nodeName: 'BODY', | ||
ownerDocument: document, | ||
}, | ||
createContextualFragment: fragment => { | ||
const el = document.createElement('div'); | ||
el.innerHTML = fragment; | ||
return el.children[0]; | ||
}, | ||
selectNode: () => {}, | ||
setStart: () => {}, | ||
setEnd: () => {}, | ||
}), | ||
}); | ||
|
||
Object.defineProperty(HTMLElement.prototype, 'offsetParent', { | ||
get() { | ||
return this.parentNode; | ||
}, | ||
}); | ||
|
||
Object.defineProperty(HTMLMediaElement.prototype, 'duration', { writable: true }); | ||
Object.defineProperty(HTMLMediaElement.prototype, 'ended', { writable: true }); | ||
Object.defineProperty(HTMLMediaElement.prototype, 'load', { value: jest.fn() }); | ||
Object.defineProperty(HTMLMediaElement.prototype, 'paused', { writable: true }); | ||
Object.defineProperty(HTMLMediaElement.prototype, 'play', { value: jest.fn() }); | ||
Object.defineProperty(HTMLMediaElement.prototype, 'played', { writable: 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 'test-file-stub'; |
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,21 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const readFixtureFile = filePath => fs.readFileSync(path.resolve('src', 'lib', filePath), 'utf8'); | ||
|
||
const resetFixtureFile = () => { | ||
document.body.innerHTML = ''; | ||
}; | ||
|
||
const setHTMLFixture = htmlContent => { | ||
document.body.outerHTML = htmlContent; | ||
}; | ||
|
||
const loadHTMLFixture = filePath => { | ||
return setHTMLFixture(readFixtureFile(filePath)); | ||
}; | ||
|
||
module.exports = { | ||
cleanup: resetFixtureFile, | ||
load: loadHTMLFixture, | ||
}; |
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 @@ | ||
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,32 @@ | ||
import React from 'react'; | ||
|
||
export const intlMock = { | ||
formatMessage: message => message.defaultMessage || message.message, | ||
formatDate: date => date, | ||
}; | ||
|
||
export const FormattedDate = () => <div />; | ||
FormattedDate.displayName = 'FormattedDate'; | ||
|
||
export const FormattedTime = () => <div />; | ||
FormattedTime.displayName = 'FormattedTime'; | ||
|
||
export const FormattedMessage = () => <div />; | ||
FormattedMessage.displayName = 'FormattedMessage'; | ||
|
||
export const addLocaleData = () => {}; | ||
|
||
export const createIntl = () => intlMock; | ||
|
||
export const defineMessages = messages => messages; | ||
|
||
export const intlShape = {}; | ||
|
||
export const injectIntl = Component => { | ||
const WrapperComponent = props => { | ||
const injectedProps = { ...props, intl: intlMock }; | ||
return <Component {...{ ...injectedProps }} />; | ||
}; | ||
WrapperComponent.displayName = Component.displayName || Component.name || 'Component'; | ||
return WrapperComponent; | ||
}; |
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,24 @@ | ||
const crypto = require('crypto'); | ||
|
||
module.exports = { | ||
getCacheKey(fileData, filePath, configStr, options) { | ||
return crypto | ||
.createHash('md5') | ||
.update(fileData) | ||
.update('\0', 'utf8') | ||
.update(filePath) | ||
.update('\0', 'utf8') | ||
.update(configStr) | ||
.update('\0', 'utf8') | ||
.update(JSON.stringify(options)) | ||
.digest('hex'); | ||
}, | ||
|
||
process: content => { | ||
// escape newlines | ||
const json = JSON.stringify(content) | ||
.replace(/\u2028/g, '\\u2028') | ||
.replace(/\u2029/g, '\\u2029'); | ||
return `module.exports = ${json};`; | ||
}, | ||
}; |
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 @@ | ||
module.exports = {}; |
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 @@ | ||
class Worker { | ||
constructor(stringUrl) { | ||
this.url = stringUrl; | ||
this.onmessage = () => {}; | ||
} | ||
|
||
postMessage(msg) { | ||
this.onmessage(msg); | ||
} | ||
} | ||
|
||
module.exports = Worker; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.