Skip to content

Commit

Permalink
fix: add tests to prevent updating to esm-only dependencies (#1051)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
usefulthink committed Oct 10, 2023
1 parent 522b09e commit fd95b9c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions package.json
Expand Up @@ -37,18 +37,21 @@
"src"
],
"scripts": {
"build": "tsc",
"docs": "rm -rf docs/ && typedoc src/index.ts",
"prepack": "tsc",
"test": "jest src",
"test:e2e": "jest e2e",
"prepack": "npm run build",
"pretest": "npm run build",
"test": "jest ./src/* && npm run test:loading",
"test:loading": "./test-module-loading.sh",
"test:e2e": "jest ./e2e/*",
"test:all": "jest"
},
"dependencies": {
"@googlemaps/url-signature": "^1.0.4",
"agentkeepalive": "^4.1.0",
"axios": "^1.5.1",
"query-string": "<8.x",
"retry-axios": "<4"
"retry-axios": "<3.x"
},
"devDependencies": {
"@types/jest": "^29.5.5",
Expand Down
20 changes: 20 additions & 0 deletions test-module-loading.sh
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

failed=0

cjsCode='const {Client} = require("./dist/"); new Client();'
esmCode='import {Client} from "./dist/index.js"; new Client();'

echo "test loading as commonJS..."
if ! node -e "${cjsCode}" ; then
failed=1
echo 'Loading package as commomJS failed' >&2
fi

echo "test loading as ESM..."
if ! node --input-type module -e "${esmCode}" ; then
failed=1
echo 'Loading package as ESM failed' >&2
fi

if [ $failed -eq 1 ] ; then exit 1 ; fi

0 comments on commit fd95b9c

Please sign in to comment.