Skip to content

Commit 6ba9bb2

Browse files
authored
Build: Add jtr-based tests in GitHub Actions, migrate to ESLint flat config
Changes: * Migrate from Karma to jquery-test-runner * Add tests on real browsers * Run tests on GitHub Actions * Migrate ESLint from v7 to v9 with a flat config * Switch from UglifyJS to SWC, enforce ES 5 * Add `.editorconfig` & `.gitattributes` files * Update `.gitignore` to include more patterns from jQuery Core Closes gh-247
1 parent e5da24c commit 6ba9bb2

20 files changed

+2844
-1992
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
indent_style = tab
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
13+
[*.{json,yml}]
14+
indent_style = space
15+
indent_size = 2

.eslintrc.js

-19
This file was deleted.

.gitattributes

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# JS files must always use LF for tools to work
5+
# JS files may have mjs or cjs extensions now as well
6+
*.js eol=lf
7+
*.cjs eol=lf
8+
*.mjs eol=lf
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Browserstack (Manual Dispatch)
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
browser:
7+
description: 'Browser to test, in form of \"browser_[browserVersion | :device]_os_osVersion\"'
8+
required: false
9+
type: string
10+
default: 'chrome__windows_11'
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
environment: browserstack
16+
env:
17+
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
18+
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
19+
steps:
20+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
21+
22+
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
23+
with:
24+
node-version: 20
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Build jQuery Mousewheel
30+
run: npm run build
31+
32+
- name: Run tests
33+
run: npm run test:unit -- \
34+
-v --browserstack ${{ inputs.browser }} \
35+
-f module=${{ inputs.module }}

.github/workflows/browserstack.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Browserstack
2+
3+
on:
4+
push:
5+
branches:
6+
- main
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: 22.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_9'
25+
- 'IE_10'
26+
- 'IE_11'
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+
- 'Firefox_latest'
35+
- 'Firefox_latest-1'
36+
- '__iOS_18'
37+
- '__iOS_17'
38+
- '__iOS_16'
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
42+
43+
- name: Use Node.js ${{ env.NODE_VERSION }}
44+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
45+
with:
46+
node-version: ${{ env.NODE_VERSION }}
47+
48+
- name: Cache
49+
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
50+
with:
51+
path: ~/.npm
52+
key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-npm-lock-${{ hashFiles('**/package-lock.json') }}
53+
restore-keys: |
54+
${{ runner.os }}-node-${{ env.NODE_VERSION }}-npm-lock-
55+
56+
- name: Install dependencies
57+
run: npm install
58+
59+
- name: Build jQuery Mousewheel
60+
run: npm run build
61+
62+
- name: Run tests
63+
run: |
64+
npm run test:unit -- -v -c jtr-isolate.yml \
65+
--browserstack "${{ matrix.BROWSER }}" \
66+
--run-id ${{ github.run_id }}

.github/workflows/codeql-analysis.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: "Code scanning - action"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches-ignore:
7+
- "dependabot/**"
8+
schedule:
9+
- cron: "0 4 * * 6"
10+
11+
permissions:
12+
contents: read # to fetch code (actions/checkout)
13+
14+
jobs:
15+
CodeQL-Build:
16+
permissions:
17+
contents: read # to fetch code (actions/checkout)
18+
security-events: write # (github/codeql-action/autobuild)
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+
with:
26+
# We must fetch at least the immediate parents so that if this is
27+
# a pull request then we can checkout the head.
28+
fetch-depth: 2
29+
30+
# If this run was triggered by a pull request event, then checkout
31+
# the head of the pull request instead of the merge commit.
32+
- run: git checkout HEAD^2
33+
if: ${{ github.event_name == 'pull_request' }}
34+
35+
# Initializes the CodeQL tools for scanning.
36+
- name: Initialize CodeQL
37+
uses: github/codeql-action/init@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3.28.10
38+
# Override language selection by uncommenting this and choosing your languages
39+
# with:
40+
# languages: go, javascript, csharp, python, cpp, java
41+
42+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
43+
# If this step fails, then you should remove it and run the build manually (see below)
44+
- name: Autobuild
45+
uses: github/codeql-action/autobuild@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3.28.10
46+
47+
# ℹ️ Command-line programs to run using the OS shell.
48+
# 📚 https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
49+
50+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
51+
# and modify them (or add more) to build your code if your project
52+
# uses a compiled language
53+
54+
#- run: |
55+
# make bootstrap
56+
# make release
57+
58+
- name: Perform CodeQL Analysis
59+
uses: github/codeql-action/analyze@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3.28.10

.github/workflows/node.js.yml

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Node
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches-ignore:
7+
- "dependabot/**"
8+
9+
permissions:
10+
contents: read # to fetch code (actions/checkout)
11+
12+
jobs:
13+
build-and-test:
14+
runs-on: ubuntu-latest
15+
name: ${{ matrix.NPM_SCRIPT }} - ${{ matrix.NAME }} (${{ matrix.NODE_VERSION }})
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
- NAME: "Node"
21+
NODE_VERSION: "22.x"
22+
NPM_SCRIPT: "lint"
23+
- NAME: "Chrome/Firefox"
24+
NODE_VERSION: "22.x"
25+
NPM_SCRIPT: "test:browser"
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29+
30+
- name: Use Node.js ${{ matrix.NODE_VERSION }}
31+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
32+
with:
33+
node-version: ${{ matrix.NODE_VERSION }}
34+
35+
- name: Cache
36+
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
37+
with:
38+
path: ~/.npm
39+
key: ${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-npm-lock-${{ hashFiles('**/package-lock.json') }}
40+
restore-keys: |
41+
${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-npm-lock-
42+
43+
- name: Set download URL for Firefox ESR (old)
44+
run: |
45+
echo "FIREFOX_SOURCE_URL=https://download.mozilla.org/?product=firefox-esr-latest-ssl&lang=en-US&os=linux64" >> "$GITHUB_ENV"
46+
if: contains(matrix.NAME, 'Firefox ESR (old)')
47+
48+
- name: Set download URL for Firefox ESR (new)
49+
run: |
50+
echo "FIREFOX_SOURCE_URL=https://download.mozilla.org/?product=firefox-esr-next-latest-ssl&lang=en-US&os=linux64" >> "$GITHUB_ENV"
51+
if: contains(matrix.NAME, 'Firefox ESR (new)')
52+
53+
- name: Install Firefox ESR
54+
run: |
55+
wget --no-verbose $FIREFOX_SOURCE_URL -O - | tar -jx -C ${HOME}
56+
echo "PATH=${HOME}/firefox:$PATH" >> "$GITHUB_ENV"
57+
echo "FIREFOX_BIN=${HOME}/firefox/firefox" >> "$GITHUB_ENV"
58+
if: contains(matrix.NAME, 'Firefox ESR')
59+
60+
- name: Install dependencies
61+
run: npm install
62+
63+
- name: Build for linting
64+
run: npm run build
65+
if: contains(matrix.NPM_SCRIPT, 'lint')
66+
67+
- name: Run tests
68+
run: npm run ${{ matrix.NPM_SCRIPT }}
69+
70+
ie:
71+
runs-on: windows-latest
72+
env:
73+
NODE_VERSION: 22.x
74+
name: test:ie - IE
75+
steps:
76+
- name: Checkout
77+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
78+
79+
- name: Use Node.js ${{ env.NODE_VERSION }}
80+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
81+
with:
82+
node-version: ${{ env.NODE_VERSION }}
83+
84+
- name: Cache
85+
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
86+
with:
87+
path: ~/.npm
88+
key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-npm-lock-${{ hashFiles('**/package-lock.json') }}
89+
restore-keys: |
90+
${{ runner.os }}-node-${{ env.NODE_VERSION }}-npm-lock-
91+
92+
- name: Install dependencies
93+
run: npm install
94+
95+
- name: Run tests in Edge in IE mode
96+
run: npm run test:ie
97+
98+
safari:
99+
runs-on: macos-latest
100+
env:
101+
NODE_VERSION: 22.x
102+
name: test:safari - Safari
103+
steps:
104+
- name: Checkout
105+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
106+
107+
- name: Use Node.js ${{ env.NODE_VERSION }}
108+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
109+
with:
110+
node-version: ${{ env.NODE_VERSION }}
111+
112+
- name: Cache
113+
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
114+
with:
115+
path: ~/.npm
116+
key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-npm-lock-${{ hashFiles('**/package-lock.json') }}
117+
restore-keys: |
118+
${{ runner.os }}-node-${{ env.NODE_VERSION }}-npm-lock-
119+
120+
- name: Install dependencies
121+
run: npm install
122+
123+
- name: Run tests
124+
run: npm run test:safari

build/minify.mjs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import fs from "node:fs/promises";
2+
import path from "node:path";
3+
import swc from "@swc/core";
4+
5+
const rjs = /\.js$/;
6+
7+
export async function minify( { filename, dir } ) {
8+
const contents = await fs.readFile( path.join( dir, filename ), "utf8" );
9+
10+
const { code } = await swc.minify(
11+
contents,
12+
{
13+
compress: {
14+
ecma: 5,
15+
hoist_funs: false,
16+
loops: false
17+
},
18+
format: {
19+
ecma: 5,
20+
asciiOnly: true
21+
},
22+
inlineSourcesContent: false,
23+
mangle: true,
24+
module: false,
25+
sourceMap: false
26+
}
27+
);
28+
29+
const minFilename = filename.replace( rjs, ".min.js" );
30+
31+
await fs.writeFile(
32+
path.join( dir, minFilename ),
33+
code
34+
);
35+
36+
console.log( `file ${ minFilename } created.` );
37+
}

0 commit comments

Comments
 (0)