This is an automated email from the ASF dual-hosted git repository.
jialiang pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push:
new 831d589b3b AMBARI-26113: Switch the PhantomJS used by Karma tests to
chromium-browser (#3809)
831d589b3b is described below
commit 831d589b3b5dfba29c84094568e0fe844af852e2
Author: zrain <[email protected]>
AuthorDate: Thu Sep 5 11:07:44 2024 +0800
AMBARI-26113: Switch the PhantomJS used by Karma tests to chromium-browser
(#3809)
---
.gitignore | 1 +
Jenkinsfile | 5 +++--
ambari-admin/pom.xml | 4 ++--
.../src/main/resources/ui/admin-web/package.json | 4 +---
.../main/resources/ui/admin-web/test/karma.conf.js | 19 +++++++++++++++++--
ambari-web/app/router.js | 2 +-
ambari-web/app/utils/helper.js | 13 +++++++++++++
.../views/main/admin/stack_upgrade/versions_view.js | 2 +-
ambari-web/karma.conf.js | 11 +++++++++--
ambari-web/package.json | 3 +--
.../service/manage_config_groups_controller_test.js | 16 ++++++++--------
ambari-web/test/router_test.js | 6 +++---
.../main/admin/stack_upgrade/version_view_test.js | 12 ++++++------
13 files changed, 66 insertions(+), 32 deletions(-)
diff --git a/.gitignore b/.gitignore
index 2f96100263..6ed020ba06 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,4 @@ createDDL.jdbc
/dist
/build
ambari_python.egg-info
+**/Crashpad
diff --git a/Jenkinsfile b/Jenkinsfile
index 489683ba86..2d0da33bf8 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -96,8 +96,9 @@ pipeline {
parallel {
stage('Ambari WebUI Tests') {
steps {
- sh 'export CHROME_BIN=/usr/bin/chromium-browser'
- sh 'mvn -T 2C -am test -pl ambari-web,ambari-admin
-Dmaven.artifact.threads=10 -Drat.skip'
+ withEnv(['CHROME_BIN=/usr/bin/chromium-browser']) {
+ sh 'mvn -T 2C -am test -pl ambari-web,ambari-admin
-Dmaven.artifact.threads=10 -Drat.skip'
+ }
}
}
diff --git a/ambari-admin/pom.xml b/ambari-admin/pom.xml
index c88eb5e641..d0c1bef4a5 100644
--- a/ambari-admin/pom.xml
+++ b/ambari-admin/pom.xml
@@ -135,7 +135,7 @@
<commandlineArgs>${args.shell}
${basedir}${dirsep}set-ambari-version.${fileextension.shell}
${ambariVersion}</commandlineArgs>
</configuration>
</execution>
- <!-- <execution>
+ <execution>
<id>unit test</id>
<phase>test</phase>
<goals>
@@ -149,7 +149,7 @@
<argument>test-single-run</argument>
</arguments>
</configuration>
- </execution> -->
+ </execution>
</executions>
</plugin>
<plugin>
diff --git a/ambari-admin/src/main/resources/ui/admin-web/package.json
b/ambari-admin/src/main/resources/ui/admin-web/package.json
index d9995ac023..a3b442c2b1 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/package.json
+++ b/ambari-admin/src/main/resources/ui/admin-web/package.json
@@ -21,11 +21,9 @@
"http-server": "0.6.1",
"jasmine-core": "^3.1.0",
"karma": "^2.0.4",
- "karma-chrome-launcher": "0.1.4",
"karma-jasmine": "^1.1.2",
"karma-ng-html2js-preprocessor": "^1.0.0",
- "karma-phantomjs-launcher": "^1.0.4",
- "phantomjs": "^2.1.7",
+ "karma-chrome-launcher": "3.2.0",
"protractor": "1.0.0"
},
"scripts": {
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/karma.conf.js
b/ambari-admin/src/main/resources/ui/admin-web/test/karma.conf.js
index bb514cd473..fb6353e3b1 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/test/karma.conf.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/karma.conf.js
@@ -42,13 +42,28 @@ module.exports = function(config){
autoWatch : true,
+ colors: true,
+
+ logLevel: config.LOG_INFO,
+
+ captureTimeout: 60000,
+
+ browserNoActivityTimeout: 30000,
+
frameworks: ['jasmine'],
- browsers: ['PhantomJS'],
+ customLaunchers: {
+ ChromeHeadlessCustom: {
+ base: 'ChromeHeadless',
+ flags: ['--no-sandbox', '--disable-gpu', '--disable-translate',
'--disable-extensions']
+ }
+ },
+
+ browsers: ['ChromeHeadlessCustom'],
plugins : [
'karma-jasmine',
- 'karma-phantomjs-launcher',
+ 'karma-chrome-launcher',
'karma-ng-html2js-preprocessor'
],
diff --git a/ambari-web/app/router.js b/ambari-web/app/router.js
index c0a754a7eb..4d96cee6cd 100644
--- a/ambari-web/app/router.js
+++ b/ambari-web/app/router.js
@@ -665,7 +665,7 @@ App.Router = Em.Router.extend({
}),
sortedMappedVersions = mappedVersions.sort(),
latestVersion =
sortedMappedVersions[sortedMappedVersions.length-1].replace(/[^\d.-]/g, '');
- window.location.replace(App.appURLRoot + 'views/ADMIN_VIEW/' +
latestVersion + '/INSTANCE/#/');
+ App.replaceWindowLocation(App.appURLRoot + 'views/ADMIN_VIEW/' +
latestVersion + '/INSTANCE/#/')
}
},
diff --git a/ambari-web/app/utils/helper.js b/ambari-web/app/utils/helper.js
index d05724d4d4..7cc652e31a 100644
--- a/ambari-web/app/utils/helper.js
+++ b/ambari-web/app/utils/helper.js
@@ -1101,3 +1101,16 @@ App.logger = function() {
};
}();
+
+/**
+ * Replce cruuent window location.
+ * `window.location.replace` is a native function and cannot be intercepted by
Sinon,
+ * it needs to be intercepted manually. See
https://stackoverflow.com/a/52141931/14792586.
+ *
+ * Simple function, no test cases available.
+ *
+ * @param {string} location new location
+ **/
+App.replaceWindowLocation = function(location) {
+ window.location.replace(location);
+}
\ No newline at end of file
diff --git a/ambari-web/app/views/main/admin/stack_upgrade/versions_view.js
b/ambari-web/app/views/main/admin/stack_upgrade/versions_view.js
index 386ec4db93..b7c048a420 100644
--- a/ambari-web/app/views/main/admin/stack_upgrade/versions_view.js
+++ b/ambari-web/app/views/main/admin/stack_upgrade/versions_view.js
@@ -230,7 +230,7 @@ App.MainAdminStackVersionsView = Em.View.extend({
}),
sortedMappedVersions = mappedVersions.sort(),
latestVersion =
sortedMappedVersions[sortedMappedVersions.length-1].replace(/[^\d.-]/g, '');
- window.location.replace(App.appURLRoot + 'views/ADMIN_VIEW/' +
latestVersion + '/INSTANCE/#!/stackVersions');
+ App.replaceWindowLocation(App.appURLRoot + 'views/ADMIN_VIEW/' +
latestVersion + '/INSTANCE/#/')
}
});
},
diff --git a/ambari-web/karma.conf.js b/ambari-web/karma.conf.js
index b19287f779..b9e9212407 100644
--- a/ambari-web/karma.conf.js
+++ b/ambari-web/karma.conf.js
@@ -23,7 +23,7 @@ module.exports = function(config) {
basePath: '',
plugins: [
- 'karma-phantomjs-launcher',
+ 'karma-chrome-launcher',
'karma-mocha',
'karma-chai',
'karma-sinon',
@@ -159,6 +159,13 @@ module.exports = function(config) {
// enable / disable watching file and executing tests whenever any file
changes
autoWatch: true,
+
+ customLaunchers: {
+ ChromeHeadlessCustom: {
+ base: 'ChromeHeadless',
+ flags: ['--no-sandbox', '--disable-gpu', '--disable-translate',
'--disable-extensions']
+ }
+ },
// Start these browsers, currently available:
// - Chrome
@@ -167,7 +174,7 @@ module.exports = function(config) {
// - Opera (has to be installed with `npm install karma-opera-launcher`)
// - Safari (only Mac; has to be installed with `npm install
karma-safari-launcher`)
// - IE (only Windows; has to be installed with `npm install
karma-ie-launcher`)
- browsers: ['PhantomJS'],
+ browsers: ['ChromeHeadlessCustom'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
diff --git a/ambari-web/package.json b/ambari-web/package.json
index 7fcc59dc82..b4203d97c8 100644
--- a/ambari-web/package.json
+++ b/ambari-web/package.json
@@ -27,7 +27,7 @@
"chai": "~3.5.0",
"express": "2.5.8",
"karma": ">=0.11.14",
- "karma-phantomjs-launcher": "1.0.2",
+ "karma-chrome-launcher": "3.2.0",
"karma-babel-preprocessor": "^6.0.1",
"karma-chai": "~0.1.0",
"karma-commonjs-require": "~0.0.3",
@@ -36,7 +36,6 @@
"karma-mocha": "0.1.1",
"karma-sinon": "~1.0.2",
"mocha": "2.5.3",
- "phantomjs": "~2.1.0",
"sinon": "=1.7.3",
"sinon-chai": "~2.8.0"
},
diff --git
a/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js
b/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js
index db3151ebec..2995669d96 100644
---
a/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js
+++
b/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js
@@ -511,6 +511,7 @@ describe('App.ManageConfigGroupsController', function() {
c._onLoadPropertiesSuccess(data, null, params);
expect(JSON.stringify(c.get('configGroups'))).to.equal(JSON.stringify([
Em.Object.create({
+ name: 'group1',
properties: [
{
name: 'prop1',
@@ -522,32 +523,31 @@ describe('App.ManageConfigGroupsController', function() {
value: 'val2',
type: 'type1'
}
- ],
- name: 'group1'
+ ]
}),
Em.Object.create({
+ name: 'group2',
properties: [
{
name: 'prop3',
value: 'val3',
type: 'type1'
}
- ],
- name: 'group2'
+ ]
}),
Em.Object.create({
+ name: 'group3',
properties: [
{
name: 'prop4',
value: 'val4',
type: 'type2'
}
- ],
- name: 'group3'
+ ]
}),
Em.Object.create({
- properties: [],
- name: 'group4'
+ name: 'group4',
+ properties: []
})
]));
});
diff --git a/ambari-web/test/router_test.js b/ambari-web/test/router_test.js
index c177bbf749..88ee910492 100644
--- a/ambari-web/test/router_test.js
+++ b/ambari-web/test/router_test.js
@@ -88,10 +88,10 @@ describe('App.Router', function () {
describe('#adminViewInfoSuccessCallback', function () {
beforeEach(function () {
- sinon.stub(window.location, 'replace', Em.K);
+ sinon.stub(App, 'replaceWindowLocation', Em.K);
});
afterEach(function () {
- window.location.replace.restore();
+ App.replaceWindowLocation.restore();
});
var tests = [{
@@ -138,7 +138,7 @@ describe('App.Router', function () {
tests.forEach(function (data, index) {
it('should redirect to the latest version of admin view ("' +
data.expected + '") #' + (index + 1), function () {
router.adminViewInfoSuccessCallback(data.mockData);
- expect(window.location.replace.calledWith(data.expected)).to.be.true;
+ expect(App.replaceWindowLocation.calledWith(data.expected)).to.be.true;
});
});
});
diff --git
a/ambari-web/test/views/main/admin/stack_upgrade/version_view_test.js
b/ambari-web/test/views/main/admin/stack_upgrade/version_view_test.js
index b274c32fb3..11058e779e 100644
--- a/ambari-web/test/views/main/admin/stack_upgrade/version_view_test.js
+++ b/ambari-web/test/views/main/admin/stack_upgrade/version_view_test.js
@@ -472,11 +472,11 @@ describe('App.mainAdminStackVersionsView', function () {
};
before(function () {
sinon.spy(App, 'showConfirmationPopup');
- sinon.stub(window.location, 'replace', Em.K);
+ sinon.stub(App, 'replaceWindowLocation', Em.K);
});
after(function () {
App.showConfirmationPopup.restore();
- window.location.replace.restore();
+ App.replaceWindowLocation.restore();
});
beforeEach(function () {
@@ -494,7 +494,7 @@ describe('App.mainAdminStackVersionsView', function () {
popup.onPrimary();
var args = testHelpers.findAjaxRequest('name',
'ambari.service.load_server_version');
expect(args[0]).exists;
-
expect(window.location.replace.calledWith('/views/ADMIN_VIEW/2.1.0/INSTANCE/#!/stackVersions')).to.be.true;
+
expect(App.replaceWindowLocation.calledWith('/views/ADMIN_VIEW/2.1.0/INSTANCE/#/')).to.be.true;
});
});
@@ -516,11 +516,11 @@ describe('App.mainAdminStackVersionsView', function () {
};
before(function () {
sinon.spy(App, 'showConfirmationPopup');
- sinon.stub(window.location, 'replace', Em.K);
+ sinon.stub(App, 'replaceWindowLocation', Em.K);
});
after(function () {
App.showConfirmationPopup.restore();
- window.location.replace.restore();
+ App.replaceWindowLocation.restore();
});
beforeEach(function () {
@@ -538,7 +538,7 @@ describe('App.mainAdminStackVersionsView', function () {
popup.onPrimary();
var args = testHelpers.findAjaxRequest('name',
'ambari.service.load_server_version');
expect(args[0]).exists;
-
expect(window.location.replace.calledWith('/views/ADMIN_VIEW/2.1.0/INSTANCE/#!/stackVersions')).to.be.true;
+
expect(App.replaceWindowLocation.calledWith('/views/ADMIN_VIEW/2.1.0/INSTANCE/#/')).to.be.true;
});
});
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]