make jest support files that import handlebars
Change-Id: I073ea3f8b54cf46cd2b4c2437aad5ee13c95dc7c Reviewed-on: https://gerrit.instructure.com/186286 Tested-by: Jenkins Reviewed-by: Clay Diffrient <cdiffrient@instructure.com> QA-Review: Clay Diffrient <cdiffrient@instructure.com> Product-Review: Brent Burgoyne <bburgoyne@instructure.com>
This commit is contained in:
parent
edd105b104
commit
a7b07e869e
|
@ -147,7 +147,7 @@ const buildPartialRequirements = partialPaths => {
|
|||
return requirements
|
||||
}
|
||||
|
||||
module.exports = function i18nLinerHandlebarsLoader(source) {
|
||||
function i18nLinerHandlebarsLoader(source) {
|
||||
this.cacheable()
|
||||
const name = resourceName(this.resourcePath)
|
||||
const dependencies = ['handlebars/runtime']
|
||||
|
@ -187,3 +187,13 @@ module.exports = function i18nLinerHandlebarsLoader(source) {
|
|||
)
|
||||
return compiledTemplate
|
||||
}
|
||||
|
||||
module.exports = i18nLinerHandlebarsLoader
|
||||
|
||||
module.exports.compile = (source, path) => {
|
||||
const context = {
|
||||
cacheable: () => {},
|
||||
resourcePath: path
|
||||
}
|
||||
return i18nLinerHandlebarsLoader.call(context, source)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,9 @@ module.exports = {
|
|||
moduleNameMapper: {
|
||||
'^i18n!(.*$)': '<rootDir>/jest/i18nTransformer.js',
|
||||
'^compiled/(.*)$': '<rootDir>/app/coffeescripts/$1',
|
||||
'^coffeescripts/(.*)$': '<rootDir>/app/coffeescripts/$1',
|
||||
'^jsx/(.*)$': '<rootDir>/app/jsx/$1',
|
||||
'^jst/(.*)$': '<rootDir>/app/views/jst/$1',
|
||||
"^timezone$": "<rootDir>/public/javascripts/timezone_core.js",
|
||||
"\\.svg$": "<rootDir>/jest/imageMock.js"
|
||||
},
|
||||
|
@ -48,11 +50,12 @@ module.exports = {
|
|||
|
||||
coverageDirectory: '<rootDir>/coverage-jest/',
|
||||
|
||||
moduleFileExtensions: [...defaults.moduleFileExtensions, 'coffee'],
|
||||
moduleFileExtensions: [...defaults.moduleFileExtensions, 'coffee', 'handlebars'],
|
||||
|
||||
transform: {
|
||||
'^i18n': '<rootDir>/jest/i18nTransformer.js',
|
||||
'^.+\\.coffee': '<rootDir>/jest/coffeeTransformer.js',
|
||||
'^.+\\.handlebars': '<rootDir>/jest/handlebarsTransformer.js',
|
||||
'^.+\\.jsx?$': 'babel-jest'
|
||||
},
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (C) 2017 - present Instructure, Inc.
|
||||
*
|
||||
* This file is part of Canvas.
|
||||
*
|
||||
* Canvas is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License as published by the Free
|
||||
* Software Foundation, version 3 of the License.
|
||||
*
|
||||
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const {transform} = require('babel-core')
|
||||
const {compile} = require('../frontend_build/i18nLinerHandlebars')
|
||||
|
||||
exports.process = (source, path) => {
|
||||
const amd = compile(source, path)
|
||||
const cjs = transform(amd, {plugins: ['transform-amd-to-commonjs']}).code
|
||||
return cjs
|
||||
}
|
Loading…
Reference in New Issue