-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create empty mocks for jest #303
Merged
Merged
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
354c659
Add postinstall script for creating mocks
ba4efdf
Add new lines at the end
54be94d
Update postinstall script to add setupAppCenter.js file and to update…
7cdca52
Return if we can not find package.json
df4ee9b
Fix eslint errors
980045d
Fix eslint errors and modify eslint.rc in test apps
16a29bd
Reimplement mocking with js modules mocks
5d62992
Add AppCenter mocks to TestApp
c56d4f0
Check if jest is present as dependency
ba562fc
Fix indentation
12c0b91
Separate mocks added to appcenter modules
bfd5a94
Postinstall script in modules updated to modify package.json
7431b3d
Update TestApp package.json
e38e7df
Extract common code to link-scripts module
7cf3956
Rename mock files
6222c6e
Add js extension for require
688e28e
Update link-scripts path in postinstall
fe3fdc3
Move setup mock script to appcenter module
91565da
Remove mocks from TestApp
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"env": { | ||
"es6": true | ||
"es6": true, | ||
"jest": true | ||
}, | ||
"plugins": [ | ||
"react" | ||
|
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 @@ | ||
|
||
const Crashes = jest.mock('appcenter-crashes'); | ||
Crashes.generateTestCrash = jest.fn(); | ||
Crashes.hasCrashedInLastSession = jest.fn(); | ||
Crashes.lastSessionCrashReport = jest.fn(); | ||
Crashes.isEnabled = jest.fn(); | ||
Crashes.setEnabled = jest.fn(); | ||
Crashes.notifyUserConfirmation = jest.fn(); | ||
Crashes.setListener = jest.fn(); | ||
export default Crashes; |
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 @@ | ||
|
||
const Push = jest.mock('appcenter-push'); | ||
Push.isEnabled = jest.fn(); | ||
Push.setEnabled = jest.fn(); | ||
Push.setListener = jest.fn(); | ||
export default Push; |
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"env": { | ||
"es6": true | ||
"es6": true, | ||
"jest": true | ||
}, | ||
"plugins": [ | ||
"react" | ||
|
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,7 +1,8 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"env": { | ||
"es6": true | ||
"es6": true, | ||
"jest": true | ||
}, | ||
"plugins": [ | ||
"react" | ||
|
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,29 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const projectDirectory = path.resolve(__dirname, '..', '..', '..'); | ||
const setupFileName = `.${path.sep}node_modules${path.sep}appcenter-analytics${path.sep}test${path.sep}appCenterAnalyticsMock.js`; | ||
|
||
// Check if package.json has jest as dependency | ||
let packageJson = ''; | ||
const packageJsonFile = path.join(`${projectDirectory}`, 'package.json'); | ||
try { | ||
packageJson = JSON.parse(fs.readFileSync(packageJsonFile, 'utf8')); | ||
if (!Object.prototype.hasOwnProperty.call(packageJson.devDependencies, 'jest') && | ||
!Object.prototype.hasOwnProperty.call(packageJson.dependencies, 'jest')) { | ||
return; | ||
} | ||
} catch (e) { | ||
console.log('Could not read package.json file'); | ||
return; | ||
} | ||
|
||
// Add setup file for module | ||
if (Object.prototype.hasOwnProperty.call(packageJson, 'jest')) { | ||
if (packageJson.jest.setupFiles === undefined) { | ||
packageJson.jest.setupFiles = [setupFileName]; | ||
} else if (packageJson.jest.setupFiles.indexOf(setupFileName) === -1) { | ||
packageJson.jest.setupFiles.push(setupFileName); | ||
} | ||
fs.writeFileSync(packageJsonFile, JSON.stringify(packageJson)); | ||
} |
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,5 @@ | ||
jest.mock('appcenter-analytics', () => ({ | ||
trackEvent: jest.fn(), | ||
isEnabled: jest.fn(), | ||
setEnabled: 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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"env": { | ||
"es6": true | ||
"es6": true, | ||
"jest": true | ||
}, | ||
"plugins": [ | ||
"react" | ||
|
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,29 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const projectDirectory = path.resolve(__dirname, '..', '..', '..'); | ||
const setupFileName = `.${path.sep}node_modules${path.sep}appcenter-crashes${path.sep}test${path.sep}appCenterCrashesMock.js`; | ||
|
||
// Check if package.json has jest as dependency | ||
let packageJson = ''; | ||
const packageJsonFile = path.join(`${projectDirectory}`, 'package.json'); | ||
try { | ||
packageJson = JSON.parse(fs.readFileSync(packageJsonFile, 'utf8')); | ||
if (!Object.prototype.hasOwnProperty.call(packageJson.devDependencies, 'jest') && | ||
!Object.prototype.hasOwnProperty.call(packageJson.dependencies, 'jest')) { | ||
return; | ||
} | ||
} catch (e) { | ||
console.log('Could not read package.json file'); | ||
return; | ||
} | ||
|
||
// Add setup file for module | ||
if (Object.prototype.hasOwnProperty.call(packageJson, 'jest')) { | ||
if (packageJson.jest.setupFiles === undefined) { | ||
packageJson.jest.setupFiles = [setupFileName]; | ||
} else if (packageJson.jest.setupFiles.indexOf(setupFileName) === -1) { | ||
packageJson.jest.setupFiles.push(setupFileName); | ||
} | ||
fs.writeFileSync(packageJsonFile, JSON.stringify(packageJson)); | ||
} |
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 @@ | ||
jest.mock('appcenter-crashes', () => ({ | ||
generateTestCrash: jest.fn(), | ||
hasCrashedInLastSession: jest.fn(), | ||
lastSessionCrashReport: jest.fn(), | ||
isEnabled: jest.fn(), | ||
setEnabled: jest.fn(), | ||
notifyUserConfirmation: jest.fn(), | ||
setListener: 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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"env": { | ||
"es6": true | ||
"es6": true, | ||
"jest": true | ||
}, | ||
"plugins": [ | ||
"react" | ||
|
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,29 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const projectDirectory = path.resolve(__dirname, '..', '..', '..'); | ||
const setupFileName = `.${path.sep}node_modules${path.sep}appcenter-push${path.sep}test${path.sep}appCenterPushMock.js`; | ||
|
||
// Check if package.json has jest as dependency | ||
let packageJson = ''; | ||
const packageJsonFile = path.join(`${projectDirectory}`, 'package.json'); | ||
try { | ||
packageJson = JSON.parse(fs.readFileSync(packageJsonFile, 'utf8')); | ||
if (!Object.prototype.hasOwnProperty.call(packageJson.devDependencies, 'jest') && | ||
!Object.prototype.hasOwnProperty.call(packageJson.dependencies, 'jest')) { | ||
return; | ||
} | ||
} catch (e) { | ||
console.log('Could not read package.json file'); | ||
return; | ||
} | ||
|
||
// Add setup file for module | ||
if (Object.prototype.hasOwnProperty.call(packageJson, 'jest')) { | ||
if (packageJson.jest.setupFiles === undefined) { | ||
packageJson.jest.setupFiles = [setupFileName]; | ||
} else if (packageJson.jest.setupFiles.indexOf(setupFileName) === -1) { | ||
packageJson.jest.setupFiles.push(setupFileName); | ||
} | ||
fs.writeFileSync(packageJsonFile, JSON.stringify(packageJson)); | ||
} |
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,5 @@ | ||
jest.mock('appcenter-push', () => ({ | ||
isEnabled: jest.fn(), | ||
setEnabled: jest.fn(), | ||
setListener: 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
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,29 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const projectDirectory = path.resolve(__dirname, '..', '..', '..'); | ||
const setupFileName = `.${path.sep}node_modules${path.sep}appcenter${path.sep}test${path.sep}appCenterMock.js`; | ||
|
||
// Check if package.json has jest as dependency | ||
let packageJson = ''; | ||
const packageJsonFile = path.join(`${projectDirectory}`, 'package.json'); | ||
try { | ||
packageJson = JSON.parse(fs.readFileSync(packageJsonFile, 'utf8')); | ||
if (!Object.prototype.hasOwnProperty.call(packageJson.devDependencies, 'jest') && | ||
!Object.prototype.hasOwnProperty.call(packageJson.dependencies, 'jest')) { | ||
return; | ||
} | ||
} catch (e) { | ||
console.log('Could not read package.json file'); | ||
return; | ||
} | ||
|
||
// Add setup file for module | ||
if (Object.prototype.hasOwnProperty.call(packageJson, 'jest')) { | ||
if (packageJson.jest.setupFiles === undefined) { | ||
packageJson.jest.setupFiles = [setupFileName]; | ||
} else if (packageJson.jest.setupFiles.indexOf(setupFileName) === -1) { | ||
packageJson.jest.setupFiles.push(setupFileName); | ||
} | ||
fs.writeFileSync(packageJsonFile, JSON.stringify(packageJson)); | ||
} |
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 @@ | ||
jest.mock('appcenter', () => ({ | ||
getLogLevel: jest.fn(), | ||
setLogLevel: jest.fn(), | ||
getInstallId: jest.fn(), | ||
isEnabled: jest.fn(), | ||
setEnabled: jest.fn(), | ||
setCustomProperties: jest.fn(), | ||
getSdkVersion: jest.fn() | ||
})); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach seems ok now based on latest discussion.
However this is duplicated code, we can put shared script code in the
linker, I mean the core package and use it here.