Reapply "Switch container factory to webpack"

This reverts commit 18d93b00ba.
This commit is contained in:
Calen Pennington
2018-06-07 15:52:05 -04:00
parent 947d82737e
commit be3c7e05c5
158 changed files with 7368 additions and 6805 deletions

View File

@@ -4,9 +4,17 @@
(function(define, require) {
'use strict';
/* RequireJS */
define(['jquery', 'underscore', 'gettext', 'common/js/components/views/feedback_notification',
'common/js/components/views/feedback_prompt'],
function($, _, gettext, NotificationView, PromptView) {
/* End RequireJS */
/* Webpack
define(['jquery', 'underscore', 'gettext', 'common/js/components/views/feedback_notification',
'common/js/components/views/feedback_prompt', 'scriptjs'],
function($, _, gettext, NotificationView, PromptView, $script) {
/* End Webpack */
var toggleExpandCollapse, showLoadingIndicator, hideLoadingIndicator, confirmThenRunOperation,
runOperationShowingMessage, withDisabledElement, disableElementWhileRunning,
getScrollOffset, setScrollOffset, setScrollTop, redirect, reload, hasChangedAttributes,
@@ -21,11 +29,9 @@
*/
toggleExpandCollapse = function(target, collapsedClass) {
// Support the old 'collapsed' option until fully switched over to is-collapsed
if (!collapsedClass) {
collapsedClass = 'collapsed';
}
var collapsed = collapsedClass || 'collapsed';
target.closest('.expand-collapse').toggleClass('expand collapse');
target.closest('.is-collapsible, .window').toggleClass(collapsedClass);
target.closest('.is-collapsible, .window').toggleClass(collapsed);
target.closest('.is-collapsible').children('article').slideToggle();
};
@@ -231,20 +237,20 @@
};
// Ensure that sum length of key field values <= ${MAX_SUM_KEY_LENGTH} chars.
validateTotalKeyLength = function(key_field_selectors) {
validateTotalKeyLength = function(keyFieldSelectors) {
var totalLength = _.reduce(
key_field_selectors,
keyFieldSelectors,
function(sum, ele) { return sum + $(ele).val().length; },
0
);
return totalLength <= MAX_SUM_KEY_LENGTH;
};
checkTotalKeyLengthViolations = function(selectors, classes, key_field_selectors, message_tpl) {
if (!validateTotalKeyLength(key_field_selectors)) {
checkTotalKeyLengthViolations = function(selectors, classes, keyFieldSelectors, messageTpl) {
if (!validateTotalKeyLength(keyFieldSelectors)) {
$(selectors.errorWrapper).addClass(classes.shown).removeClass(classes.hiding);
$(selectors.errorMessage).html(
'<p>' + _.template(message_tpl)({limit: MAX_SUM_KEY_LENGTH}) + '</p>'
'<p>' + _.template(messageTpl)({limit: MAX_SUM_KEY_LENGTH}) + '</p>'
);
$(selectors.save).addClass(classes.disabled);
} else {
@@ -259,6 +265,7 @@
*/
loadJavaScript = function(url) {
var deferred = $.Deferred();
/* RequireJS */
require([url],
function() {
deferred.resolve();
@@ -266,6 +273,12 @@
function() {
deferred.reject();
});
/* End RequireJS */
/* Webpack
$script(url, url, function () {
deferred.resolve();
});
/* End Webpack */
return deferred.promise();
};

View File

@@ -45,8 +45,6 @@ var webdriver = require('selenium-webdriver');
var firefox = require('selenium-webdriver/firefox');
var webpackConfig = require(path.join(appRoot, 'webpack.dev.config.js'));
delete webpackConfig.entry;
// The following crazy bit is to work around the webpack.optimize.CommonsChunkPlugin
// plugin. The problem is that it it factors out the code that defines webpackJsonp
// and puts in in the commons JS, which Karma doesn't know to load first. This is a
@@ -56,8 +54,7 @@ delete webpackConfig.entry;
// https://github.com/webpack-contrib/karma-webpack/issues/24#issuecomment-257613167
//
// This should be fixed in v3 of karma-webpack
const commonsChunkPluginIndex = webpackConfig.plugins.findIndex(plugin => plugin.chunkNames);
webpackConfig.plugins.splice(commonsChunkPluginIndex, 1);
var commonsChunkPluginIndex = webpackConfig.plugins.findIndex(function(plugin) { return plugin.chunkNames; });
// Files which are needed by all lms/cms suites.
var commonFiles = {
@@ -83,6 +80,10 @@ var commonFiles = {
]
};
webpackConfig.plugins.splice(commonsChunkPluginIndex, 1);
delete webpackConfig.entry;
/**
* Customize the name attribute in xml testcase element
* @param {Object} browser
@@ -124,6 +125,8 @@ function reporters(config) {
* @return {Object}
*/
function getBasepathAndFilename(filepath) {
var file, dir;
if (!filepath) {
// these will configure the reporters to create report files relative to this karma config file
return {
@@ -131,9 +134,8 @@ function getBasepathAndFilename(filepath) {
file: undefined
};
}
var file = filepath.replace(/^.*[\\\/]/, ''),
dir = filepath.replace(file, '');
file = filepath.replace(/^.*[\\/]/, '');
dir = filepath.replace(file, '');
return {
dir: dir,
@@ -148,13 +150,13 @@ function getBasepathAndFilename(filepath) {
* @return {Object}
*/
function coverageSettings(config) {
var path = getBasepathAndFilename(config.coveragereportpath);
var pth = getBasepathAndFilename(config.coveragereportpath);
return {
dir: path.dir,
dir: pth.dir,
subdir: '.',
includeAllSources: true,
reporters: [
{type: 'cobertura', file: path.file},
{type: 'cobertura', file: pth.file},
{type: 'text-summary'}
]
};
@@ -167,10 +169,10 @@ function coverageSettings(config) {
* @return {Object}
*/
function junitSettings(config) {
var path = getBasepathAndFilename(config.junitreportpath);
var pth = getBasepathAndFilename(config.junitreportpath);
return {
outputDir: path.dir,
outputFile: path.file,
outputDir: pth.dir,
outputFile: pth.file,
suite: 'javascript',
useBrowserName: false,
nameFormatter: junitNameFormatter,
@@ -185,14 +187,15 @@ function junitSettings(config) {
* @return {String}
*/
// I'd like to fix the no-shadow violation on the next line, but it would break this shared conf's API.
function defaultNormalizeFunc(appRoot, pattern) { // eslint-disable-line no-shadow
if (pattern.match(/^common\/js/)) {
pattern = path.join(appRoot, '/common/static/' + pattern);
} else if (pattern.match(/^xmodule_js\/common_static/)) {
pattern = path.join(appRoot, '/common/static/' +
pattern.replace(/^xmodule_js\/common_static\//, ''));
function defaultNormalizeFunc(appRoot, pattern) { // eslint-disable-line no-shadow
var pat = pattern;
if (pat.match(/^common\/js/)) {
pat = path.join(appRoot, '/common/static/' + pat);
} else if (pat.match(/^xmodule_js\/common_static/)) {
pat = path.join(appRoot, '/common/static/' +
pat.replace(/^xmodule_js\/common_static\//, ''));
}
return pattern;
return pat;
}
function normalizePathsForCoverage(files, normalizeFunc, preprocessors) {
@@ -225,7 +228,7 @@ function setDefaults(files) {
return files.map(function(f) {
var file = _.isObject(f) ? f : {pattern: f};
if (!file.included && !file.webpack) {
f.included = false;
file.included = false;
}
return file;
});
@@ -244,7 +247,7 @@ function getBaseConfig(config, useRequireJs) {
'node_modules/bootstrap/dist/js/bootstrap.js',
'node_modules/underscore/underscore.js',
'node_modules/backbone/backbone.js',
'common/static/js/test/i18n.js',
'common/static/js/test/i18n.js'
];
if (useRequireJs) {
@@ -276,22 +279,21 @@ function getBaseConfig(config, useRequireJs) {
var hostname = 'localhost';
var port = 9876;
var customPlugin = {
'framework:custom': ['factory', initFrameworks]
};
if (process.env.hasOwnProperty('BOK_CHOY_HOSTNAME')) {
hostname = process.env.BOK_CHOY_HOSTNAME;
if (hostname === 'edx.devstack.lms') {
port = 19876;
}
else {
} else {
port = 19877;
}
}
initFrameworks.$inject = ['config.files'];
var customPlugin = {
'framework:custom': ['factory', initFrameworks]
};
return {
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
@@ -370,7 +372,7 @@ function getBaseConfig(config, useRequireJs) {
ChromeDocker: {
base: 'SeleniumWebdriver',
browserName: 'chrome',
getDriver: function () {
getDriver: function() {
return new webdriver.Builder()
.forBrowser('chrome')
.usingServer('http://edx.devstack.chrome:4444/wd/hub')
@@ -380,7 +382,7 @@ function getBaseConfig(config, useRequireJs) {
FirefoxDocker: {
base: 'SeleniumWebdriver',
browserName: 'firefox',
getDriver: function () {
getDriver: function() {
var options = new firefox.Options(),
profile = new firefox.Profile();
profile.setPreference('focusmanager.testmode', true);
@@ -419,8 +421,9 @@ function getBaseConfig(config, useRequireJs) {
}
function configure(config, options) {
var useRequireJs = options.useRequireJs === undefined ? true : useRequireJs,
baseConfig = getBaseConfig(config, useRequireJs);
var useRequireJs = options.useRequireJs === undefined ? true : options.useRequireJs,
baseConfig = getBaseConfig(config, useRequireJs),
files, filesForCoverage, preprocessors;
if (options.includeCommonFiles) {
_.forEach(['libraryFiles', 'sourceFiles', 'specFiles', 'fixtureFiles'], function(collectionName) {
@@ -428,7 +431,7 @@ function configure(config, options) {
});
}
var files = _.flatten(
files = _.flatten(
_.map(
['libraryFilesToInclude', 'libraryFiles', 'sourceFiles', 'specFiles', 'fixtureFiles', 'runFiles'],
function(collectionName) { return options[collectionName] || []; }
@@ -447,7 +450,7 @@ function configure(config, options) {
// We set it to false by default because RequireJS should be used instead.
files = setDefaults(files);
var filesForCoverage = _.flatten(
filesForCoverage = _.flatten(
_.map(
['sourceFiles', 'specFiles'],
function(collectionName) { return options[collectionName]; }
@@ -456,7 +459,7 @@ function configure(config, options) {
// If we give symlink paths to Istanbul, coverage for each path gets tracked
// separately. So we pass absolute paths to the karma-coverage preprocessor.
var preprocessors = _.extend(
preprocessors = _.extend(
{},
options.preprocessors,
normalizePathsForCoverage(filesForCoverage, options.normalizePathsForCoverageFunc, options.preprocessors)

View File

@@ -1,11 +1,10 @@
/**
* Provides helper methods for invoking Studio modal windows in Jasmine tests.
*/
(function(define) {
'use strict';
define(['jquery', 'common/js/components/views/feedback_notification', 'common/js/components/views/feedback_prompt',
'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers'],
function($, NotificationView, Prompt, AjaxHelpers) {
define(['underscore', 'jquery', 'common/js/components/views/feedback_notification', 'common/js/components/views/feedback_prompt',
'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers'],
function(_, $, NotificationView, Prompt, AjaxHelpers) {
'use strict';
var installViewTemplates, createFeedbackSpy, verifyFeedbackShowing,
verifyFeedbackHidden, createNotificationSpy, verifyNotificationShowing,
verifyNotificationHidden, createPromptSpy, confirmPrompt, inlineEdit, verifyInlineEditChange,
@@ -42,11 +41,11 @@
return createFeedbackSpy(NotificationView, type || 'Mini');
};
verifyNotificationShowing = function(notificationSpy, text) {
verifyNotificationShowing = function() {
verifyFeedbackShowing.apply(this, arguments);
};
verifyNotificationHidden = function(notificationSpy) {
verifyNotificationHidden = function() {
verifyFeedbackHidden.apply(this, arguments);
};
@@ -63,11 +62,11 @@
}
};
verifyPromptShowing = function(promptSpy, text) {
verifyPromptShowing = function() {
verifyFeedbackShowing.apply(this, arguments);
};
verifyPromptHidden = function(promptSpy) {
verifyPromptHidden = function() {
verifyFeedbackHidden.apply(this, arguments);
};
@@ -148,5 +147,5 @@
submitAndVerifyFormSuccess: submitAndVerifyFormSuccess,
submitAndVerifyFormError: submitAndVerifyFormError
};
});
}).call(this, define || RequireJS.define);
}
);

View File

@@ -1,27 +0,0 @@
define([], function() {
'use strict';
return function invokePageFactory(name, factory) {
var args;
if (typeof window.pageFactoryArguments === 'undefined') {
throw Error(
'window.pageFactoryArguments must be initialized before calling invokePageFactory(' +
name +
'). Use the <%static:invoke_page_bundle> template tag.'
);
}
args = window.pageFactoryArguments[name];
if (typeof args === 'undefined') {
throw Error(
'window.pageFactoryArguments["' +
name +
'"] must be initialized before calling invokePageFactory(' +
name +
'). Use the <%static:invoke_page_bundle> template tag.'
);
}
factory.apply(null, window.pageFactoryArguments[name]);
};
});

View File

@@ -1,14 +1,14 @@
(function() {
'use strict';
XBlock.Runtime.v1 = (function() {
this.XBlock.Runtime.v1 = (function() {
function v1() {
var _this = this;
var block = this;
this.childMap = function() {
return v1.prototype.childMap.apply(_this, arguments);
return v1.prototype.childMap.apply(block, arguments);
};
this.children = function() {
return v1.prototype.children.apply(_this, arguments);
return v1.prototype.children.apply(block, arguments);
};
}
@@ -17,14 +17,15 @@
};
v1.prototype.childMap = function(block, childName) {
var child, _i, _len, _ref;
_ref = this.children(block);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
var child, idx, len, ref;
ref = this.children(block);
for (idx = 0, len = ref.length; idx < len; idx++) {
child = ref[idx];
if (child.name === childName) {
return child;
}
}
return null;
};
/**