Skip to content

Conversation

@ygj6
Copy link
Contributor

@ygj6 ygj6 commented Oct 27, 2020

Summary

This week I tried to do something for the jQuery test migration, as follows:

I applied for a free browserstack account, and added browserstack configuration to my fork project. It seems that the jQuery test cases run properly in the real browser (Windows 10 Chrome) provided by the browserstack platform.

Local operation steps:

  1. git clone -b browserstack https://github.com/jquery/jquery.git
  2. export BROWSERSTACK_USERNAME=<your browserstack username>
    export BROWSERSTACK_ACCESS_KEY=<your browserstack access key>
  3. Run npm run test:browserstack

output:

       Running "karma:browserstack" (karma) task
       27 10 2020 14:21:24.584:INFO [karma-server]: Karma v5.1.0 server started at http://0.0.0.0:9876/
       27 10 2020 14:21:24.586:INFO [launcher]: Launching browsers bs_chrome_win10 with concurrency 3
       27 10 2020 14:21:24.655:INFO [launcher]: Starting browser chrome 86.0 (Windows 10) on BrowserStack
       27 10 2020 14:22:01.426:INFO [launcher.browserstack]: chrome 86.0 (Windows 10) session at https://automate.browserstack.com/builds/f5e04e82b7db52fab492e6147fb7ce6f44c8e337/sessions/8a87ce5a344ff150f8072beeb0be5d32606ca2fc
       27 10 2020 14:22:07.500:INFO [Chrome 86.0.4240.75 (Windows 10)]: Connected on socket Of1EpjUUAKiRdu4CAAAA with id 43017044
       Chrome 86.0.4240.75 (Windows 10): Executed 435 of 1094 SUCCESS (0 secs / 52.279 secs)
       Chrome 86.0.4240.75 (Windows 10): Executed 493 of 1094 SUCCESS (0 secs / 1 min 2.398 secs)
       Chrome 86.0.4240.75 (Windows 10): Executed 650 of 1094 SUCCESS (0 secs / 1 min 27.918 secs)
       Chrome 86.0.4240.75 (Windows 10): Executed 711 of 1094 SUCCESS (0 secs / 1 min 37.87 secs)
       Chrome 86.0.4240.75 (Windows 10): Executed 1094 of 1094 SUCCESS (4 mins 39.082 secs / 4 mins 2.227 secs)
       TOTAL: 1094 SUCCESS
       
       Done.

Next, I plan to continue to do it, such as integrating into github actions, configuring and running more real browsers, etc.;

I look forward to your guidance and suggestions.

Checklist

Copy link
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

We need to be able to pass a specific browser to BrowserStack as well as the latest & previous version, etc. We'll probably want something like https://github.com/jquery/sizzle/blob/master/test/karma/launchers.js defined so that we don't need to inline the launchers in Gruntfile and we need to be able to pass different browsers somehow.

@ygj6
Copy link
Contributor Author

ygj6 commented Dec 19, 2020

Refer to sizzle I made some changes:

  • Extract the karma configuration from Gruntfile.js to karma.conf.js.
  • Add browserstack browser configuration.
  • Register the karma-tests task to support running the browserstack test.

However, I encountered some problems when running the test. For example, some test cases failed to be executed during the test using the Firefox browser. I do not know whether the problem is a case problem or a configuration problem. Can you @mgol confirm it?
https://travis-ci.org/github/ygj6/jquery/jobs/750532994

@mgol
Copy link
Member

mgol commented Dec 21, 2020

Have a look at the Travis report:
https://travis-ci.com/github/jquery/jquery/jobs/462903353
The browser tests there have run on old versions of Chrome/Firefox: Chrome 83 (latest is 87), Firefox 63 (latest is 84!). That's why they failed.

Please have a look at our browser support matrix: https://jquery.com/browser-support/. We only want to run tests on these browsers.

@ygj6
Copy link
Contributor Author

ygj6 commented Dec 22, 2020

We only want to run tests on these browsers.

@mgol Yes, I know. I'm asking why Firefox 78 (ESR) and Firefox 83 fail in browserstack.

You can check the Travis report on ygj6/jquery:https://travis-ci.org/github/ygj6/jquery/jobs/750532994, This is run in the browserstack.

Travis report on browserstack:

Firefox 83.0 (Windows 10) manipulation jQuery.append with crossorigin attribute FAILED
	Origin header sent
	Expected: true
	Actual: false
	window.corsCallback@test/unit/manipulation.js:2311:10
	@test/data/mock.php=script&cors=1&callback=corsCallback:1:13

Firefox 78.0 (Windows 7) manipulation jQuery.append with crossorigin attribute FAILED
	Origin header sent
	Expected: true
	Actual: false
	window.corsCallback@test/unit/manipulation.js:2311:10
	@test/data/mock.php=script&cors=1&callback=corsCallback:1:13

@mgol
Copy link
Member

mgol commented Dec 22, 2020

@ygj6 Where do you see these errors? Travis shows old versions of Chrome/Firefox as I mentioned above & I don't see errors anywhere else.

@ygj6
Copy link
Contributor Author

ygj6 commented Dec 23, 2020

Please check this Travis report on my repository ygj6/jquery: https://travis-ci.org/github/ygj6/jquery/jobs/750532994

In this PR, the secure in .travis.yml is generated by my ygj6/jquery repository. Therefore, the secure does not take effect in the jquery/jquery repository, Please replace the secure to the correct secure generated by the jquery/jquery repository.

The way to generate encryption-keys(secure) :
Use travis to generate encryption-keys(secure) containing BROWSER_STACK_USERNAME=*** and BROWSER_STACK_ACCESS_KEY=***.
https://docs.travis-ci.com/user/encryption-keys/#usage

@mgol
Copy link
Member

mgol commented Dec 23, 2020

@ygj6 I think you can find the reason here:

// We need to simulate cross-domain requests with the feature that
// both 127.0.0.1 and localhost point to the mock http server.
// Skip the the test if we are not in localhost but make sure we run
// it in Karma.
QUnit[
jQuery.ajax && ( window.__karma__ || location.hostname === "localhost" ) ?
"test" :
"skip"
]( "jQuery.append with crossorigin attribute", function( assert ) {

We need localhost & 127.0.0.1 to resolve to the same address on which Karma runs and I guess that's not the case when we use BrowserStack? We might need to skip that test when BrowserStack is used as well.

@ygj6
Copy link
Contributor Author

ygj6 commented Dec 26, 2020

I tested and found these:

  • Browserstack+chrome 87 test scene request header information has origin, browserstack+firefox 83 scene request header information does not have origin;
  • Both Chrome Headless and firefox headless have origin in the scene request header;
  • Use my PC Chrome 87 and Firefox 84 test request header information has origin.

Although the request header of browserstack+firefox does not contain origin, but the corsCallback can be successfully called,
it should be crossorigin success. I have checked many documents. I still do not know why the difference exists.
Can we modify the test case, for example, change typeof response.headers.origin === "string" to typeof response.headers.referer === "string", and the test will pass.

window.corsCallback = function( response ) {
assert.ok( typeof response.headers.origin === "string", "Origin header sent" );
window.clearTimeout( timeout );
done();
};

We can also use the skip case in the browserstack+firefox scenario.


Browser request header details:

Browserstack + Firefox 83(no origin)

 Object{headers: Object{host: 'bs-local.com:9876', user-agent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0', accept: '*/*', accept-language: 'en-US,en;q=0.5', accept-encoding: 'gzip, deflate', connection: 'keep-alive', referer: 'http://bs-local.com:9876/context.html', cookie: 'io=7qIGNAvrEzW9nQD-AAAA'}}

Browserstack + Chrome 87(has origin)

Object{headers: Object{host: 'bs-local.com:9876', origin: 'http://bs-local.com:9876', user-agent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36', accept: '/', referer: 'http://bs-local.com:9876/context.html', accept-encoding: 'gzip, deflate', accept-language: 'en-US,en;q=0.9', cookie: 'io=OjuTbAOmXNy5kYj6AAAA', connection: 'keep-alive'}}`

FirefoxHeadless(has origin)

 Object{headers: Object{host: '127.0.0.1:9876', user-agent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0', accept: '/', accept-language: 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2', accept-encoding: 'gzip, deflate', origin: 'http://localhost:9876', connection: 'keep-alive', referer: 'http://localhost:9876/context.html'}}

ChromeHeadless(has origin)

Object{headers: Object{host: '127.0.0.1:9876', connection: 'keep-alive', origin: 'http://localhost:9876', user-agent:  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/87.0.4280.88 Safari/537.36', accept: '/', sec-fetch-site: 'cross-site', sec-fetch-mode: 'cors', sec-fetch-dest: 'script', referer: 'http://localhost:9876/context.html', accept-encoding: 'gzip, deflate, br', accept-language: 'zh-CN'}}

PC + Firefox 84(has origin)

Object{headers: Object{host: '127.0.0.1:9876', user-agent: 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0', accept: '/', accept-language: 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2', accept-encoding: 'gzip, deflate', origin: 'http://localhost:9876', connection: 'keep-alive', referer: 'http://localhost:9876/context.html'}}

PC + Chrome 87(has origin)

Object{headers: Object{host: '127.0.0.1:9876', connection: 'keep-alive', origin: 'http://localhost:9876', user-agent: 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36', accept: '/', sec-fetch-site: 'cross-site', sec-fetch-mode: 'cors', sec-fetch-dest: 'script', referer: 'http://localhost:9876/context.html', accept-encoding: 'gzip, deflate, br', accept-language: 'zh-CN,zh;q=0.9'}}

@mgol
Copy link
Member

mgol commented Dec 26, 2020

Can we modify the test case, for example, change typeof response.headers.origin === "string" to typeof response.headers.referer === "string", and the test will pass.

We cannot. The whole point of this test is to check whether we got a CORS request which we verify by checking for the Origin header; Referer is always sent so it doesn't work as a replacement.

We should add that in a comment as it may not be clear why we're checking for the Origin header, indeed.

@ygj6
Copy link
Contributor Author

ygj6 commented Jan 22, 2021

Now, skipping the cross-domain test in browserstack, all the real browser tests have passed.
https://travis-ci.org/github/ygj6/jquery/jobs/752090159

@mgol Next, do I need to do anything else for this PR?

Base automatically changed from master to main February 1, 2021 22:02
Copy link
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ygj6 some of our tests are flakey so we need a more granular way of restarting jobs that won't re-run all tests in all browsers. In our existing test system, TestSwarm, we can restart each module in each browser, see e.g.: http://swarm.jquery.org/job/11073 (Web Archive link in case it goes down). I'm not sure if we have to be as granular but at least separating browsers would be necessary.

// it in Karma.
QUnit[
jQuery.ajax && ( window.__karma__ || location.hostname === "localhost" ) ?
jQuery.ajax && ( ( window.__karma__ && location.hostname !== "bs-local.com" ) || location.hostname === "localhost" ) ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want this test running in Karma and this condition creates a risk of us skipping it completely. Can you elaborate? Whatever we need to exclude, we need to do it in a safer way.

- BROWSERS="FirefoxHeadless"
addons:
firefox: latest-esr
- name: "Browser tests: browsertack tests"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A typo + different casing:

Suggested change
- name: "Browser tests: browsertack tests"
- name: "Browser tests: BrowserStack tests"

@mgol
Copy link
Member

mgol commented Sep 17, 2021

Closing & re-opening the PR to trigger the EasyCLA check...

@mgol mgol closed this Sep 17, 2021
@mgol mgol reopened this Sep 17, 2021
@linux-foundation-easycla
Copy link

CLA Not Signed

@mgol
Copy link
Member

mgol commented Dec 6, 2021

@ygj6 Hey! It's been a while; are you still interested in finalizing this PR? Your other PR adding GitHub Actions: #4800 has landed, we'll soon remove the Travis setup completely so this needs to be setup in GitHub Actions now. Plus, my other comments need to be addressed.

@ygj6
Copy link
Contributor Author

ygj6 commented Dec 31, 2021

It's an honor to contribute to jquery.
Since the PR submission is a little long, I need to spend time sorting out the code.

@mgol
Copy link
Member

mgol commented May 16, 2022

@ygj6 Hey, any updates?

@timmywil
Copy link
Member

Thanks for your contribution. However, this PR has grown stale and will not be needed soon.

@timmywil timmywil closed this Feb 16, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants