Skip to content

Commit d231320

Browse files
committed
⚙️ Add husky pre-push hook and fix e2e test code style
1 parent ac40b99 commit d231320

5 files changed

Lines changed: 52 additions & 22 deletions

File tree

.husky/pre-push

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
3+
# Skip checks: SKIP_PRE_PUSH=1 git push or git push --no-verify
4+
if [ "$SKIP_PRE_PUSH" = "1" ]; then
5+
echo "⏭ SKIP_PRE_PUSH=1, skipping pre-push checks"
6+
exit 0
7+
fi
8+
9+
# Only run checks when pushing to main or release/* branches
10+
remote="$1"
11+
need_check=0
12+
13+
while read local_ref local_sha remote_ref remote_sha; do
14+
branch=$(echo "$remote_ref" | sed 's|refs/heads/||')
15+
16+
if [ "$branch" = "main" ] || echo "$branch" | grep -q "^release"; then
17+
need_check=1
18+
echo "🔍 Detected push target: $branch"
19+
fi
20+
done
21+
22+
if [ "$need_check" = "0" ]; then
23+
exit 0
24+
fi
25+
26+
echo ""
27+
echo "▶ Running lint..."
28+
pnpm run lint || exit 1
29+
30+
echo ""
31+
echo "▶ Running tests..."
32+
pnpm run test:ci || exit 1
33+
34+
echo ""
35+
echo "✅ All checks passed! (build and e2e tests will run in CI)"

e2e/gm-api.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const test = base.extend<{
4343
});
4444
// Ensure service worker is registered before handing context to fixtures,
4545
// preventing extensionId fixture from timing out with the global 10s timeout.
46-
let [sw] = context.serviceWorkers();
46+
const [sw] = context.serviceWorkers();
4747
if (!sw) await context.waitForEvent("serviceworker", { timeout: 30_000 });
4848
await use(context);
4949
await context.close();

e2e/utils.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@ export async function installScriptByCode(context: BrowserContext, extensionId:
4949
await page.evaluate((text) => navigator.clipboard.writeText(text), code);
5050
await page.keyboard.press("ControlOrMeta+v");
5151
// Wait for Monaco to finish rendering the pasted content (content will differ from template)
52-
await page.waitForFunction(
53-
(init) => document.querySelector(".view-lines")?.textContent !== init,
54-
initialText,
55-
{ timeout: 10_000 }
56-
);
52+
await page.waitForFunction((init) => document.querySelector(".view-lines")?.textContent !== init, initialText, {
53+
timeout: 10_000,
54+
});
5755
// Save
5856
await page.keyboard.press("ControlOrMeta+s");
5957
// Wait for save: try arco-message first, then verify via script list

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"private": true,
88
"scripts": {
99
"preinstall": "pnpm dlx only-allow pnpm",
10+
"prepare": "husky",
1011
"test": "vitest --test-timeout=500 --no-coverage --isolate=false --reporter=verbose",
1112
"test:ci": "vitest run --test-timeout=500 --no-coverage --isolate=false --reporter=default --reporter.summary=false",
1213
"coverage": "vitest run --coverage",
@@ -84,6 +85,7 @@
8485
"eslint-plugin-react-hooks": "^5.2.0",
8586
"eslint-plugin-userscripts": "^0.5.6",
8687
"globals": "^16.5.0",
88+
"husky": "^9.1.7",
8789
"iconv-lite": "^0.7.2",
8890
"jsdom": "^26.1.0",
8991
"jszip": "^3.10.1",
@@ -104,4 +106,4 @@
104106
"**/*.scss",
105107
"**/*.less"
106108
]
107-
}
109+
}

pnpm-lock.yaml

Lines changed: 10 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)