Skip to content

Commit fd95b9c

Browse files
authored
fix: add tests to prevent updating to esm-only dependencies (#1051)
packages that no longer support commonjs use should never be installed (#1047). However, without a failing test, the dependabot PRs will just slip through, so we have to add a test that will fail when import/require of this package won't work.
1 parent 522b09e commit fd95b9c

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

package-lock.json

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

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,21 @@
3737
"src"
3838
],
3939
"scripts": {
40+
"build": "tsc",
4041
"docs": "rm -rf docs/ && typedoc src/index.ts",
41-
"prepack": "tsc",
42-
"test": "jest src",
43-
"test:e2e": "jest e2e",
42+
"prepack": "npm run build",
43+
"pretest": "npm run build",
44+
"test": "jest ./src/* && npm run test:loading",
45+
"test:loading": "./test-module-loading.sh",
46+
"test:e2e": "jest ./e2e/*",
4447
"test:all": "jest"
4548
},
4649
"dependencies": {
4750
"@googlemaps/url-signature": "^1.0.4",
4851
"agentkeepalive": "^4.1.0",
4952
"axios": "^1.5.1",
5053
"query-string": "<8.x",
51-
"retry-axios": "<4"
54+
"retry-axios": "<3.x"
5255
},
5356
"devDependencies": {
5457
"@types/jest": "^29.5.5",

test-module-loading.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
failed=0
4+
5+
cjsCode='const {Client} = require("./dist/"); new Client();'
6+
esmCode='import {Client} from "./dist/index.js"; new Client();'
7+
8+
echo "test loading as commonJS..."
9+
if ! node -e "${cjsCode}" ; then
10+
failed=1
11+
echo 'Loading package as commomJS failed' >&2
12+
fi
13+
14+
echo "test loading as ESM..."
15+
if ! node --input-type module -e "${esmCode}" ; then
16+
failed=1
17+
echo 'Loading package as ESM failed' >&2
18+
fi
19+
20+
if [ $failed -eq 1 ] ; then exit 1 ; fi

0 commit comments

Comments
 (0)