8000 Tests: migrate testing infrastructure to minimal dependencies · jquery/jquery@ef434cd · GitHub
[go: up one dir, main page]

Skip to content

Commit ef434cd

Browse files
authored
Tests: migrate testing infrastructure to minimal dependencies
This is a complete rework of our testing infrastructure. The main goal is to modernize and drop deprecated or undermaintained dependencies (specifically, grunt, karma, and testswarm). We've achieved that by limiting our dependency list to ones that are unlikely to drop support any time soon. The new dependency list includes: - `qunit` (our trusty unit testing library) - `selenium-webdriver` (for spinning up local browsers) - `express` (for starting a test server and adding middleware) - express middleware includes uses of `body-parser` and `raw-body` - `yargs` (for constructing a CLI with pretty help text) - BrowserStack (for running each of our QUnit modules separately in all of our supported browsers) - `browserstack-local` (for opening a local tunnel. This is the same package still currently used in the new Browserstack SDK) - We are not using any other BrowserStack library. The newest BrowserStack SDK does not fit ou 8000 r needs (and isn't open source). Existing libraries, such as `node-browserstack` or `browserstack-runner`, either do not quite fit our needs, are under-maintained and out-of-date, or are not robust enough to meet all of our requirements. We instead call the [BrowserStack REST API](https://github.com/browserstack/api) directly. **BrowserStack** - automatically retries individual modules in case of test failure(s) - automatically attempts to re-establish broken tunnels - automatically refreshes the page in case a test run has stalled - Browser workers are reused when running isolated modules in the same browser - runs all browsers concurrently and uses as many sessions as are available under the BrowserStack plan. It will wait for available sessions if there are none. - supports filtering the available list of browsers by browser name, browser version, device, OS, and OS version (see `npm run test:unit -- --list-browsers` for more info). It will retrieve the latest matching browser available if any of those parameters are not specified. Supports latest and latest-\d+ in place of browser version. - cleans up after itself (closes the local tunnel, stops the test server, etc.) - Requires `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` environment variables. **Selenium** - supports running any local browser as long as the driver is installed, including support for headless mode in Chrome, FF, and Edge - supports running `basic` tests on the latest [jsdom](https://github.com/jsdom/jsdom#readme), which can be seen in action in this PR (see `test:browserless`) - Node tests will run as before in PRs and all non-dependabot branches, but now includes tests on real Safari in a GH actions macos image instead of playwright-webkit. - can run multiple browsers and multiple modules concurrently Other notes: - Stale dependencies have been removed and all remaining dependencies have been upgraded with a few exceptions: - `sinon`: stopped supporting IE in version 10. But, `sinon` has been updated to 9.x. - `husky`: latest does not support Node 10 and runs on `npm install`. Needed for now until git builds are migrated to GitHub Actions. - `rollup`: latest does not support Node 10. Needed for now until git builds are migrated to GitHub Actions. - BrowserStack tests are set to run on each `main` branch commit - `debug` mode leaves Selenium browsers open whether they pass or fail and leaves browsers with test failures open on BrowserStack. The latter is to avoid leaving open too many sessions. - This PR includes a workflow to dispatch BrowserStack runs on-demand - The Node version used for most workflow tests has been upgraded to 20.x - updated supportjQuery to 3.7.1 Run `npm run test:unit -- --help` for CLI documentation Close gh-5427
1 parent 633f688 commit ef434cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+14446
-14901
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Browserstack (Manual Dispatch)
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
module:
7+
description: 'Module to test'
8+
required: true
9+
type: choice
10+
options:
11+
- 'basic'
12+
- 'ajax'
13+
- 'animation'
14+
- 'attributes'
15+
- 'callbacks'
16+
- 'core'
17+
- 'css'
18+
- 'data'
19+
- 'deferred'
20+
- 'deprecated'
21+
- 'dimensions'
22+
- 'effects'
23+
- 'event'
24+
- 'manipulation'
25+
- 'offset'
26+
- 'queue'
27+
- 'selector'
28+
- 'serialize'
29+
- 'support'
30+
- 'traversing'
31+
- 'tween'
32+
browser:
33+
description: 'Browser to test, in form of \"browser_[browserVersion | :device]_os_osVersion\"'
34+
required: false
35+
type: string
36+
default: 'chrome__windows_11'
37+
38+
jobs:
39+
test:
40+
runs-on: ubuntu-latest
41+
environment: browserstack
42+
env:
43+
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
44+
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
45+
steps:
46+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
47+
48+
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
49+
with:
50+
node-version: 20
51+
52+
- name: Install dependencies
53+
run: npm ci
54+
55+
- name: Build jQuery
56+
run: npm run build:all
57+
58+
- name: Pretest script
59+
run: npm run pretest
60+
61+
- name: Run tests
62+
run: npm run test:unit -- -v --browserstack ${{ inputs.browser }} -m ${{ inputs.module }}

.github/workflows/browserstack.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Browserstack
2+
3+
on:
4+
push:
5+
branches:
6+
- 3.x-stable
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
environment: browserstack
12+
env:
13+
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
14+
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
15+
NODE_VERSION: 20.x
16+
name: ${{ matrix.BROWSER }}
17+
concurrency:
18+
group: ${{ github.workflow }} ${{ matrix.BROWSER }}
19+
timeout-minutes: 30
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
BROWSER:
24+
- 'IE_11'
25+
- 'IE_10'
26+
- 'IE_9'
27+
- 'Safari_latest'
28+
- 'Safari_latest-1'
29+
- 'Chrome_latest'
30+
- 'Chrome_latest-1'
31+
- 'Opera_latest'
32+
- 'Edge_latest'
33+
- 'Edge_latest-1'
34+
- 'Edge_18'
35+
- 'Firefox_latest'
36+
- 'Firefox_latest-1'
37+
- 'Firefox_115'
38+
- 'Firefox_102'
39+
- 'Firefox_91'
40+
- 'Firefox_78'
41+
- 'Firefox_60'
42+
- 'Firefox_48'
43+
- '__iOS_17'
44+
- '__iOS_16'
45+
- '__iOS_15'
46+
- '__iOS_14'
47+
- '__iOS_13'
48+
- '__iOS_12'
49+
- '__iOS_11'
50+
- '__iOS_10'
51+
- '__iOS_9'
52+
- '__iOS_8'
53+
steps:
54+
- name: Checkout
55+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
56+
57+
- name: Use Node.js ${{ env.NODE_VERSION }}
58+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
59+
with:
60+
node-version: ${{ env.NODE_VERSION }}
61+
62+
- name: Cache
63+
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
64+
with:
65+
path: ~/.npm
66+
key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-npm-lock-${{ hashFiles('**/package-lock.json') }}
67+
restore-keys: |
68+
${{ runner.os }}-node-${{ env.NODE_VERSION }}-npm-lock-
69+
70+
- name: Install dependencies
71+
run: npm install
72+
73+
- name: Build jQuery
74+
run: npm run build:all
75+
76+
- name: Pretest script
77+
run: npm run pretest
78+
79+
- name: Run tests
80+
run: npm run test:unit -- -v --browserstack "${{ matrix.BROWSER }}" --run-id ${{ github.run_id }} --isolate --retries 3

.github/workflows/node.js.yml

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: Node
22

33
on:
44
pull_request:
@@ -9,45 +9,49 @@ permissions:
99
contents: read # to fetch code (actions/checkout)
1010

1111
jobs:
12-
build:
12+
build-and-test:
1313
runs-on: ubuntu-latest
14+
name: ${{ matrix.NPM_SCRIPT }} - ${{ matrix.NAME }} (${{ matrix.NODE_VERSION }})
1415
strategy:
1516
fail-fast: false
1617
matrix:
17-
# Node.js 10 is required by jQuery infra
18-
# Do not remove 16.x until jsdom tests are re-enabled on newer Node.js versions.
19-
NODE_VERSION: [10.x, 16.x, 18.x, 20.x]
18+
NAME: ["Node"]
19+
NODE_VERSION: [18.x, 20.x]
2020
NPM_SCRIPT: ["test:browserless"]
2121
include:
22-
- NAME: "Browser tests: full build, Chrome, Firefox & WebKit"
23-
NODE_VERSION: "18.x"
22+
- NAME: "Node"
23+
NODE_VERSION: "20.x"
24+
NPM_SCRIPT: "lint"
25+
- NAME: "Chrome/Firefox"
26+
NODE_VERSION: "2 10000 0.x"
2427
NPM_SCRIPT: "test:browser"
25-
BROWSERS: "ChromeHeadless,FirefoxHeadless,WebkitHeadless"
26-
- NAME: "Browser tests: slim build, Chrome"
27-
NODE_VERSION: "18.x"
28+
- NAME: "Chrome"
29+
NODE_VERSION: "20.x"
2830
NPM_SCRIPT: "test:slim"
29-
BROWSERS: "ChromeHeadless"
30-
- NAME: "Browser tests: no-deprecated build, Chrome"
31-
NODE_VERSION: "18.x"
31+
- NAME: "Chrome"
32+
NODE_VERSION: "20.x"
3233
NPM_SCRIPT: "test:no-deprecated"
33-
BROWSERS: "ChromeHeadless"
34-
- NAME: "Browser tests: selector-native build, Chrome"
35-
NODE_VERSION: "18.x"
34+
- NAME: "Chrome"
35+
NODE_VERSION: "20.x"
3636
NPM_SCRIPT: "test:selector-native"
37-
BROWSERS: "ChromeHeadless"
38-
- NAME: "Browser tests: AMD build, Chrome stable"
39-
NODE_VERSION: "18.x"
37+
- NAME: "Chrome"
38+
NODE_VERSION: "20.x"
4039
NPM_SCRIPT: "test:amd"
41-
BROWSERS: "ChromeHeadless"
42-
- NAME: "Browser tests: full build, Firefox ESR"
43-
NODE_VERSION: "18.x"
44-
NPM_SCRIPT: "test:browser"
45-
BROWSERS: "FirefoxHeadless"
46-
40+
- NAME: "Firefox ESR"
41+
NODE_VERSION: "20.x"
42+
NPM_SCRIPT: "test:firefox"
43+
- NAME: "Node 10 Build"
44+
NODE_VERSION: "10.x"
45+
NPM_SCRIPT: "build:main"
4746
steps:
4847
- name: Checkout
4948
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
5049

50+
- name: Use Node.js ${{ matrix.NODE_VERSION }}
51+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
52+
with:
53+
node-version: ${{ matrix.NODE_VERSION }}
54+
5155
- name: Cache
5256
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
5357
with:
@@ -56,31 +60,49 @@ jobs:
5660
restore-keys: |
5761
${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-npm-lock-
5862
59-
- name: Use Node.js ${{ matrix.NODE_VERSION }}
60-
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
61-
with:
62-
node-version: ${{ matrix.NODE_VERSION }}
63-
6463
- name: Install firefox ESR
6564
run: |
66-
export FIREFOX_SOURCE_URL='https://download.mozilla.org/?product=firefox-esr-latest&lang=en-US&os=linux64'
65+
export FIREFOX_SOURCE_URL='https://download.mozilla.org/?product=firefox-esr-latest-ssl&lang=en-US&os=linux64'
6766
wget --no-verbose $FIREFOX_SOURCE_URL -O - | tar -jx -C ${HOME}
6867
if: contains(matrix.NAME, 'Firefox ESR')
6968

7069
- name: Install dependencies
7170
run: npm install
7271

73-
- name: Install Playwright dependencies
74-
run: npx playwright-webkit install-deps
75-
if: matrix.NPM_SCRIPT == 'test:browser' && contains(matrix.BROWSERS, 'WebkitHeadless')
76-
77-
- name: Lint code
78-
run: npm run build && npm run lint
79-
if: matrix.NODE_VERSION == '18.x'
72+
- name: Build All for Linting
73+
run: npm run build:all
74+
if: contains(matrix.NPM_SCRIPT, 'lint')
8075

8176
- name: Run tests
82-
env:
83-
BROWSERS: ${{ matrix.BROWSERS }}
8477
run: |
8578
export PATH=${HOME}/firefox:$PATH
79+
export FIREFOX_BIN=${HOME}/firefox/firefox
8680
npm run ${{ matrix.NPM_SCRIPT }}
81+
82+
safari:
83+
runs-on: macos-latest
84+
env:
85+
NODE_VERSION: 20.x
86+
name: test:safari - Safari
87+
steps:
88+
- name: Checkout
89+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
90+
91+
- name: Use Node.js ${{ env.NODE_VERSION }}
92+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
93+
with:
94+
node-version: ${{ env.NODE_VERSION }}
95+
96+
- name: Cache
97+
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
98+
with:
99+
path: ~/.npm
100+
key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-npm-lock-${{ hashFiles('**/package-lock.json') }}
101+
restore-keys: |
102+
${{ runner.os }}-node-${{ env.NODE_VERSION }}-npm-lock-
103+
104+
- name: Install dependencies
105+
run: npm install
106+
107+
- name: Run tests
108+
run: npm run test:safari

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ npm-debug.log*
1919

2020
/test/data/core/jquery-iterability-transpiled.js
2121
/test/data/qunit-fixture.js
22+
23+
# Ignore BrowserStack files
24+
local.log
25+
browserstack.err

CONTRIBUTING.md

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ We *love* when people contribute back to the project by patching the bugs they f
6868

6969
Create a fork of the jQuery repo on github at https://github.com/jquery/jquery
7070

71-
Change directory to your web root directory, whatever that might be:
72-
73-
```bash
74-
$ cd /path/to/your/www/root/
75-
```
76-
7771
Clone your jQuery fork to work locally
7872

7973
```bash
@@ -98,29 +92,47 @@ Get in the habit of pulling in the "upstream" main to stay up to date as jQuery
9892
$ git pull upstream main
9993
```
10094

101-
Run the build script
95+
Install the necessary dependencies
10296

10397
```bash
104-
$ npm run build
98+
$ npm install
10599
```
106100

107-
Now open the jQuery test suite in a browser at http://localhost/test. If there is a port, be sure to include it.
101+
Build all jQuery files
108102

109-
Success! You just built and tested jQuery!
103+
```bash
104+
$ npm run build:all
105+
```
106+
107+
Start a test server
110108

109+
```bash
110+
$ npm run test:server
111+
```
112+
113+
Now open the jQuery test suite in a browser at http://localhost:3000/test/.
114+
115+
Success! You just built and tested jQuery!
111116

112117
### Test Suite Tips...
113118

114119
During the process of writing your patch, you will run the test suite MANY times. You can speed up the process by narrowing the running test suite down to the module you are testing by either double clicking the title of the test or appending it to the url. The following examples assume you're working on a local repo, hosted on your localhost server.
115120

116121
Example:
117122

118-
http://localhost/test/?module=css
123+
http://localhost:3000/test/?module=css
119124

120125
This will only run the "css" module tests. This will significantly speed up your development and debugging.
121126

122127
**ALWAYS RUN THE FULL SUITE BEFORE COMMITTING AND PUSHING A PATCH!**
123128

129+
#### Change the test server port
130+
131+
The default port for the test server is 3000. You can change the port by setting the `PORT` environment variable.
132+
133+
```bash
134+
$ PORT=3001 npm run test:server
135+
```
124136

125137
#### Loading changes on the test page
126138

@@ -134,6 +146,29 @@ Alternatively, you can **load tests in AMD** to avoid the need for rebuilding al
134146

135147
Click "Load with AMD" after loading the test page.
136148

149+
#### Running the test suite from the command line
150+
151+
You can also run the test suite from the command line.
152+
153+
First, prepare the tests:
154+
155+
```bash
156+
$ npm run pretest
157+
```
158+
159+
Make sure jQuery is built (`npm run build:all`) and run the tests:
160+
161+
```bash
162+
$ npm run test:unit
163+
```
164+
165+
This will run each module in its own browser instance and report the results in the terminal.
166+
167+
View the full help for the test suite for more info on running the tests from the command line:
168+
169+
```bash
170+
$ npm run test:unit -- --help
171+
```
137172

138173
### Repo organization
139174

0 commit comments

Comments
 (0)
0