Skip to content

Commit 9b4a963

Browse files
salman2013farhan
authored andcommitted
Enable Karma Js tests (#37351)
* fix: enable and fix webpack karma js tests for video block
1 parent 0a97a84 commit 9b4a963

23 files changed

+1108
-1101
lines changed

common/static/common/js/karma.common.conf.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,11 @@ function getBaseConfig(config, useRequireJs) {
332332
base: 'Firefox',
333333
prefs: {
334334
'app.update.auto': false,
335-
'app.update.enabled': false
335+
'app.update.enabled': false,
336+
'media.autoplay.default': 0, // allow autoplay
337+
'media.autoplay.blocking_policy': 0, // disable autoplay blocking
338+
'media.autoplay.allow-extension-background-pages': true,
339+
'media.autoplay.enabled.user-gestures-needed': false,
336340
}
337341
},
338342
ChromeDocker: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"watch-sass": "scripts/watch_sass.sh",
1616
"test": "npm run test-jest && npm run test-karma",
1717
"test-jest": "jest",
18-
"test-karma": "npm run test-karma-vanilla && npm run test-karma-require && echo 'WARNING: Skipped broken webpack tests. For details, see: https://github.com/openedx/edx-platform/issues/35956'",
18+
"test-karma": "npm run test-karma-vanilla && npm run test-karma-require && npm run test-xmodule-webpack && echo 'WARNING: Skipped broken webpack tests. For details, see: https://github.com/openedx/edx-platform/issues/35956'",
1919
"test-karma-vanilla": "npm run test-cms-vanilla && npm run test-xmodule-vanilla && npm run test-common-vanilla",
2020
"test-karma-require": "npm run test-cms-require && npm run test-common-require",
2121
"test-karma-webpack": "npm run test-cms-webpack && npm run test-lms-webpack && npm run test-xmodule-webpack",

webpack.common.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,11 @@ module.exports = Merge.merge({
671671
$: 'jQuery',
672672
backbone: 'Backbone',
673673
canvas: 'canvas',
674+
fs: 'fs',
674675
gettext: 'gettext',
675676
jquery: 'jQuery',
676677
logger: 'Logger',
678+
path: 'path',
677679
underscore: '_',
678680
URI: 'URI',
679681
XBlockToXModuleShim: 'XBlockToXModuleShim',

xmodule/assets/video/public/js/04_video_control.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import * as Time from './utils/time.js';
44

5-
65
// VideoControl module.
76
let VideoControl = function(state) {
87
let dfd = $.Deferred();

xmodule/js/karma_runner_webpack.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ import '../../common/static/common/js/spec_helpers/jasmine-waituntil.js';
2727
import '../../common/static/common/js/spec_helpers/jasmine-extensions.js';
2828
import '../../common/static/common/js/vendor/sinon.js';
2929

30+
import HtmlUtils from 'edx-ui-toolkit/js/utils/html-utils';
31+
import StringUtils from 'edx-ui-toolkit/js/utils/string-utils';
32+
33+
3034
// These libraries are used by the tests (and the code under test)
3135
// but not explicitly imported
3236
import 'jquery.ui';
3337

3438
// These
35-
import './src/video/10_main.js';
39+
import '../assets/video/public/js/10_main.js';
3640
import './spec/helper.js';
3741
import './spec/video_helper.js';
3842

@@ -71,11 +75,18 @@ import './spec/video/video_transcript_feedback_spec.js';
7175
import './spec/video/video_volume_control_spec.js';
7276
import './spec/time_spec.js';
7377

78+
7479
// overwrite the loaded method and manually start the karma after a delay
7580
// Somehow the code initialized in jQuery's onready doesn't get called before karma auto starts
7681

7782
// eslint-disable-next-line no-unused-expressions
7883
'use strict';
84+
85+
window._ = _;
86+
window.edx = window.edx || {};
87+
window.edx.HtmlUtils = HtmlUtils;
88+
window.edx.StringUtils = StringUtils;
89+
7990
window.__karma__.loaded = function() {
8091
setTimeout(function() {
8192
window.__karma__.start();

xmodule/js/karma_xmodule_webpack.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ var options = {
2323
specFiles: [],
2424

2525
fixtureFiles: [
26-
{pattern: 'fixtures/*.*'},
27-
{pattern: 'fixtures/hls/**/*.*'}
26+
{pattern: path.join(__dirname, 'fixtures/*.*')},
27+
{pattern: path.join(__dirname, 'fixtures/hls/**/*.*')}
2828
],
2929

3030
runFiles: [

xmodule/js/spec/helper.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@
255255
}
256256

257257
jasmine.stubRequests();
258-
state = new window.Video('#example');
258+
let runtime = jasmine.createSpyObj('TestRuntime', ['handlerUrl']);
259+
state = new window.Video(runtime, '#example');
259260

260261
state.resizer = (function() {
261262
var methods = [

xmodule/js/spec/time_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
import * as Time from 'time.js';
3+
import * as Time from '../../assets/video/public/js/utils/time.js';
44

55
describe('Time', function() {
66
describe('format', function() {
Lines changed: 62 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,77 @@
1-
(function(require) {
2-
require(
3-
['video/00_async_process.js'],
4-
function(AsyncProcess) {
5-
var getArrayNthLength = function(n, multiplier) {
6-
var result = [],
7-
mul = multiplier || 1;
1+
import AsyncProcess from '../../../assets/video/public/js/00_async_process.js';
82

9-
for (var i = 0; i < n; i++) {
10-
result[i] = i * mul;
11-
}
3+
let getArrayNthLength = function(n, multiplier) {
4+
let result = [],
5+
mul = multiplier || 1;
126

13-
return result;
14-
},
15-
items = getArrayNthLength(1000);
7+
for (let i = 0; i < n; i++) {
8+
result[i] = i * mul;
9+
}
1610

17-
describe('AsyncProcess', function() {
18-
it('Array is processed successfully', function(done) {
19-
var processedArray,
20-
expectedArray = getArrayNthLength(1000, 2),
21-
process = function(item) {
22-
return 2 * item;
23-
};
11+
return result;
12+
},
13+
items = getArrayNthLength(1000);
2414

25-
AsyncProcess.array(items, process).done(function(result) {
26-
processedArray = result;
27-
});
15+
describe('AsyncProcess', function() {
16+
it('Array is processed successfully', function(done) {
17+
var processedArray,
18+
expectedArray = getArrayNthLength(1000, 2),
19+
process = function(item) {
20+
return 2 * item;
21+
};
2822

29-
jasmine.waitUntil(function() {
30-
return processedArray;
31-
}).then(function() {
32-
expect(processedArray).toEqual(expectedArray);
33-
}).always(done);
34-
});
23+
AsyncProcess.array(items, process).done(function(result) {
24+
processedArray = result;
25+
});
3526

36-
it('If non-array is passed, error callback is called', function(done) {
37-
var isError,
38-
process = function() {};
27+
jasmine.waitUntil(function() {
28+
return processedArray;
29+
}).then(function() {
30+
expect(processedArray).toEqual(expectedArray);
31+
}).always(done);
32+
});
3933

40-
AsyncProcess.array('string', process).fail(function() {
41-
isError = true;
42-
});
34+
it('If non-array is passed, error callback is called', function(done) {
35+
var isError,
36+
process = function() {};
4337

44-
jasmine.waitUntil(function() {
45-
return isError;
46-
}).then(function() {
47-
expect(isError).toBeTruthy();
48-
}).always(done);
49-
});
38+
AsyncProcess.array('string', process).fail(function() {
39+
isError = true;
40+
});
5041

51-
it('If an empty array is passed, returns initial array', function(done) {
52-
var processedArray,
53-
process = function() {};
42+
jasmine.waitUntil(function() {
43+
return isError;
44+
}).then(function() {
45+
expect(isError).toBeTruthy();
46+
}).always(done);
47+
});
5448

55-
AsyncProcess.array([], process).done(function(result) {
56-
processedArray = result;
57-
});
49+
it('If an empty array is passed, returns initial array', function(done) {
50+
var processedArray,
51+
process = function() {};
5852

59-
jasmine.waitUntil(function() {
60-
return processedArray;
61-
}).then(function() {
62-
expect(processedArray).toEqual([]);
63-
}).always(done);
64-
});
53+
AsyncProcess.array([], process).done(function(result) {
54+
processedArray = result;
55+
});
6556

66-
it('If no process function passed, returns initial array', function(done) {
67-
var processedArray;
57+
jasmine.waitUntil(function() {
58+
return processedArray;
59+
}).then(function() {
60+
expect(processedArray).toEqual([]);
61+
}).always(done);
62+
});
6863

69-
AsyncProcess.array(items).done(function(result) {
70-
processedArray = result;
71-
});
64+
it('If no process function passed, returns initial array', function(done) {
65+
var processedArray;
7266

73-
jasmine.waitUntil(function() {
74-
return processedArray;
75-
}).then(function() {
76-
expect(processedArray).toEqual(items);
77-
}).always(done);
78-
});
79-
});
67+
AsyncProcess.array(items).done(function(result) {
68+
processedArray = result;
8069
});
81-
}(require));
70+
71+
jasmine.waitUntil(function() {
72+
return processedArray;
73+
}).then(function() {
74+
expect(processedArray).toEqual(items);
75+
}).always(done);
76+
});
77+
});

0 commit comments

Comments
 (0)