Skip to content

Commit 0912b9b

Browse files
committed
test: test imports with npm package contents
Especially for publishing CommonJS/ESM/Browser dual packages a lot can go wrong in the actual build and release step, see: https://medium.com/javascript-in-plain-english/is-promise-post-mortem-cab807f18dcc In order to catch regressions with respect to the supported ways of importing this library it makes sense to test this using `npm pack`. Fixes #424
1 parent 72af27f commit 0912b9b

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ jobs:
4040
BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
4141
- run: npm run test:node
4242
if: matrix.node-version == '12.x' || matrix.node-version == '14.x'
43+
- run: npm run test:pack
44+
if: matrix.node-version == '14.x'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"test:browser": "wdio run ./wdio.conf.js",
8686
"pretest:node": "npm run build",
8787
"test:node": "npm-run-all --parallel examples:node:**",
88+
"test:pack": "./scripts/testpack.sh",
8889
"prettier:check": "prettier --ignore-path .prettierignore --check '**/*.{js,jsx,json,md}'",
8990
"prettier:fix": "prettier --ignore-path .prettierignore --write '**/*.{js,jsx,json,md}'",
9091
"bundlewatch": "npm run pretest:browser && bundlewatch --config bundlewatch.config.json",

scripts/testpack.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash -eu
2+
3+
# cd to the root dir
4+
ROOT="$(pwd)/$(dirname "$0")/.."
5+
cd "$ROOT" || exit 1
6+
7+
npm pack
8+
9+
mkdir -p ../test-pack
10+
11+
cp examples/node-commonjs/example.js ../test-pack/commonjs.js
12+
cp examples/node-esmodules/example.mjs ../test-pack/esmodules.mjs
13+
14+
cd ../test-pack
15+
16+
npm init -y
17+
18+
npm install ../uuid/uuid-*.tgz
19+
20+
node commonjs.js
21+
node esmodules.mjs

0 commit comments

Comments
 (0)