-
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
- Loading branch information
Showing
115 changed files
with
11,430 additions
and
11,269 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,12 @@ | ||
const consoleLogFn = global.console.log; | ||
|
||
function consoleLog(message, ...args) { | ||
// Workaround tos suppress AJV console log messages from Box3d Runtime | ||
if (typeof message === 'string' && message.indexOf('$ref: all keywords') >= 0) { | ||
return; | ||
} | ||
|
||
consoleLogFn(message, ...args); | ||
} | ||
|
||
global.console.log = consoleLog; |
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,44 @@ | ||
const fixtureLoader = require('./fixtureLoader'); | ||
const i18n = require('../../src/i18n/json/en-US.json'); | ||
|
||
// These should be updated to match the Preview version in package.json whenever a file in that third party directory | ||
// is updated. Also, update the matching configuration in constants.js, which is needed for main preview functionality | ||
const MEDIA_STATIC_ASSETS_VERSION = '2.14.0'; | ||
const MODEL3D_STATIC_ASSETS_VERSION = '1.12.0'; | ||
const TEXT_STATIC_ASSETS_VERSION = '0.114.0'; | ||
|
||
/* eslint-disable import/no-dynamic-require */ | ||
global.Box3D = require(`../../src/third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/box3d-runtime.min.js`); | ||
global.Papa = require(`../../src/third-party/text/${TEXT_STATIC_ASSETS_VERSION}/papaparse.min.js`); | ||
global.Remarkable = require(`../../src/third-party/text/${TEXT_STATIC_ASSETS_VERSION}/remarkable.min.js`); | ||
global.shaka = require(`../../src/third-party/media/${MEDIA_STATIC_ASSETS_VERSION}/shaka-player.compiled.js`); | ||
global.THREE = require(`../../src/third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/three.min.js`); | ||
/* eslint-enable import/no-dynamic-require */ | ||
|
||
global.EventEmitter = require('events'); | ||
global.sinon = require('sinon'); | ||
|
||
global.__ = function translate(key) { | ||
return i18n[key] || key; | ||
}; | ||
global.BoxSDK = () => ({}); | ||
global.document.createRange = () => ({ | ||
selectNode: () => {}, | ||
setEnd: () => {}, | ||
setStart: () => {}, | ||
commonAncestorContainer: { | ||
nodeName: 'BODY', | ||
ownerDocument: document, | ||
}, | ||
createContextualFragment: fragment => fragment, | ||
}); | ||
global.fixture = { | ||
cleanup: fixtureLoader.resetFixtureFile, | ||
load: fixtureLoader.loadHTMLFixture, | ||
}; | ||
global.pdfjsLib = { | ||
GlobalWorkerOptions: {}, | ||
}; | ||
global.pdfjsViewer = {}; | ||
global.URL.createObjectURL = () => ''; | ||
global.URL.revokeObjectURL = () => ''; |
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,10 @@ | ||
import '@testing-library/jest-dom'; | ||
|
||
expect.extend({ | ||
toContainSelector(received, selector) { | ||
return { | ||
message: `expected ${received} ${this.isNot ? 'not ' : ''}to contain ${selector}`, | ||
pass: !!received.querySelector(selector), | ||
}; | ||
}, | ||
}); |
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,25 @@ | ||
import Enzyme, { mount, shallow } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
// make Enzyme functions available in all test files without importing | ||
global.shallow = shallow; | ||
global.mount = mount; | ||
|
||
if (window.document) { | ||
window.document.createRange = () => ({ | ||
commonAncestorContainer: { | ||
nodeName: 'BODY', | ||
ownerDocument: document, | ||
}, | ||
createContextualFragment: fragment => { | ||
const el = document.createElement('div'); | ||
el.innerHTML = fragment; | ||
return el.children[0]; | ||
}, | ||
selectNode: () => {}, | ||
setStart: () => {}, | ||
setEnd: () => {}, | ||
}); | ||
} |
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 @@ | ||
// __mocks__/fileMock.js | ||
|
||
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,20 @@ | ||
const fs = require('fs'); | ||
|
||
const readFixtureFile = filePath => fs.readFileSync(`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 = { | ||
loadHTMLFixture, | ||
resetFixtureFile, | ||
}; |
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 messages = {}; | ||
export default messages; |
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,7 @@ | ||
Object.defineProperty(HTMLElement.prototype, 'offsetParent', { | ||
get() { | ||
return this.parentNode; | ||
}, | ||
}); | ||
Object.defineProperty(HTMLMediaElement.prototype, 'load', { value: jest.fn() }); | ||
Object.defineProperty(HTMLMediaElement.prototype, 'play', { value: jest.fn() }); |
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,9 @@ | ||
module.exports = { | ||
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,3 @@ | ||
// __mocks__/styleMock.js | ||
|
||
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,13 @@ | ||
class Worker { | ||
constructor(stringUrl) { | ||
this.url = stringUrl; | ||
this.onmessage = () => {}; | ||
} | ||
|
||
postMessage(msg) { | ||
this.onmessage(msg); | ||
} | ||
} | ||
|
||
global.Worker = Worker; | ||
window.Worker = Worker; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.