Skip to content

Commit 57d7597

Browse files
authored
test: test imports with npm package contents (#425)
* 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 * chore: ignore *.tgz files * build: run build as prepack command This simplifies using npm pack in CI tests.
1 parent 2d9f590 commit 57d7597

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

.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'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ dist/
33
# Browserstack
44
browserstack.err
55
local.log
6+
*.tgz

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@
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",
9192
"md": "runmd --watch --output=README.md README_js.md",
9293
"docs": "( node --version | grep -q 'v12' ) && ( npm run build && runmd --output=README.md README_js.md )",
9394
"docs:diff": "npm run docs && git diff --quiet README.md",
9495
"build": "./scripts/build.sh",
96+
"prepack": "npm run build",
9597
"release": "standard-version --no-verify"
9698
},
9799
"repository": {
@@ -114,8 +116,7 @@
114116
},
115117
"standard-version": {
116118
"scripts": {
117-
"postchangelog": "prettier --write CHANGELOG.md",
118-
"postcommit": "npm run build"
119+
"postchangelog": "prettier --write CHANGELOG.md"
119120
}
120121
}
121122
}

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)