-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UI Framework Jest tests to npm test script. Create separate scrip…
…ts for watching and generating coverage reports.
- Loading branch information
Showing
6 changed files
with
79 additions
and
34 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 |
---|---|---|
@@ -1,36 +1,37 @@ | ||
const jest = require('jest'); | ||
const path = require('path'); | ||
|
||
const rootDir = 'ui_framework'; | ||
const resolve = relativePath => path.resolve(__dirname, '..', '', relativePath); | ||
|
||
const config = { | ||
rootDir, | ||
collectCoverage: true, | ||
collectCoverageFrom: [ | ||
'components/**/*.js', | ||
// Seems to be a bug with jest or micromatch, in which the above glob doesn't match subsequent | ||
// levels of directories, making this glob necessary. | ||
'components/**/**/*.js', | ||
'!components/index.js', | ||
'!components/**/*/index.js', | ||
], | ||
coverageDirectory: '<rootDir>/jest/report', | ||
coverageReporters: ['html'], | ||
moduleFileExtensions: ['jsx', 'js', 'json'], | ||
moduleNameMapper: { | ||
'^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm)$': resolve('config/jest/FileStub.js'), | ||
'^.+\\.css$': resolve('config/jest/CSSStub.js'), | ||
'^.+\\.scss$': resolve('config/jest/CSSStub.js') | ||
}, | ||
testPathIgnorePatterns: ['<rootDir>/(dist|doc_site|jest)/'], | ||
testEnvironment: 'node', | ||
testRegex: '.*\.test\.(js|jsx)$', | ||
snapshotSerializers: ['<rootDir>/../node_modules/enzyme-to-json/serializer'] | ||
}; | ||
const platform = require('os').platform(); | ||
const config = require('./utils/ui_framework_test_config'); | ||
|
||
module.exports = function (grunt) { | ||
grunt.registerTask('uiFramework:test', function () { | ||
const done = this.async(); | ||
Promise.all([uiFrameworkTest()]).then(done); | ||
}); | ||
|
||
function uiFrameworkTest() { | ||
const serverCmd = { | ||
cmd: /^win/.test(platform) ? '.\\node_modules\\.bin\\jest.cmd' : './node_modules/.bin/jest', | ||
args: [ | ||
'--env=jsdom', | ||
`--config=${JSON.stringify(config)}`, | ||
], | ||
opts: { stdio: 'inherit' } | ||
}; | ||
|
||
return new Promise((resolve, reject) => { | ||
grunt.util.spawn(serverCmd, (error, result, code) => { | ||
if (error || code !== 0) { | ||
const message = result.stderr || result.stdout; | ||
|
||
const argv = process.argv.slice(2); | ||
grunt.log.error(message); | ||
|
||
argv.push('--config', JSON.stringify(config)); | ||
return reject(); | ||
} | ||
|
||
jest.run(argv); | ||
grunt.log.writeln(result); | ||
|
||
resolve(); | ||
}); | ||
|
||
}); | ||
} | ||
}; |
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,8 @@ | ||
const jest = require('jest'); | ||
const config = require('./ui_framework_test_config'); | ||
|
||
const argv = process.argv.slice(2); | ||
|
||
argv.push('--config', JSON.stringify(config)); | ||
|
||
jest.run(argv); |
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,27 @@ | ||
const path = require('path'); | ||
const rootDir = 'ui_framework'; | ||
const resolve = relativePath => path.resolve(__dirname, '..', '', relativePath); | ||
|
||
module.exports = { | ||
rootDir, | ||
collectCoverageFrom: [ | ||
'components/**/*.js', | ||
// Seems to be a bug with jest or micromatch, in which the above glob doesn't match subsequent | ||
// levels of directories, making this glob necessary. | ||
'components/**/**/*.js', | ||
'!components/index.js', | ||
'!components/**/*/index.js', | ||
], | ||
coverageDirectory: '<rootDir>/jest/report', | ||
coverageReporters: ['html'], | ||
moduleFileExtensions: ['jsx', 'js', 'json'], | ||
moduleNameMapper: { | ||
'^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm)$': resolve('config/jest/FileStub.js'), | ||
'^.+\\.css$': resolve('config/jest/CSSStub.js'), | ||
'^.+\\.scss$': resolve('config/jest/CSSStub.js') | ||
}, | ||
testPathIgnorePatterns: ['<rootDir>/(dist|doc_site|jest)/'], | ||
testEnvironment: 'node', | ||
testRegex: '.*\.test\.(js|jsx)$', | ||
snapshotSerializers: ['<rootDir>/../node_modules/enzyme-to-json/serializer'] | ||
}; |
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