Skip to content

Commit

Permalink
test: test imports with npm package contents (#425)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ctavan committed Apr 29, 2020
1 parent 2d9f590 commit 57d7597
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ jobs:
BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
- run: npm run test:node
if: matrix.node-version == '12.x' || matrix.node-version == '14.x'
- run: npm run test:pack
if: matrix.node-version == '14.x'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist/
# Browserstack
browserstack.err
local.log
*.tgz
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@
"test:browser": "wdio run ./wdio.conf.js",
"pretest:node": "npm run build",
"test:node": "npm-run-all --parallel examples:node:**",
"test:pack": "./scripts/testpack.sh",
"prettier:check": "prettier --ignore-path .prettierignore --check '**/*.{js,jsx,json,md}'",
"prettier:fix": "prettier --ignore-path .prettierignore --write '**/*.{js,jsx,json,md}'",
"bundlewatch": "npm run pretest:browser && bundlewatch --config bundlewatch.config.json",
"md": "runmd --watch --output=README.md README_js.md",
"docs": "( node --version | grep -q 'v12' ) && ( npm run build && runmd --output=README.md README_js.md )",
"docs:diff": "npm run docs && git diff --quiet README.md",
"build": "./scripts/build.sh",
"prepack": "npm run build",
"release": "standard-version --no-verify"
},
"repository": {
Expand All @@ -114,8 +116,7 @@
},
"standard-version": {
"scripts": {
"postchangelog": "prettier --write CHANGELOG.md",
"postcommit": "npm run build"
"postchangelog": "prettier --write CHANGELOG.md"
}
}
}
21 changes: 21 additions & 0 deletions scripts/testpack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash -eu

# cd to the root dir
ROOT="$(pwd)/$(dirname "$0")/.."
cd "$ROOT" || exit 1

npm pack

mkdir -p ../test-pack

cp examples/node-commonjs/example.js ../test-pack/commonjs.js
cp examples/node-esmodules/example.mjs ../test-pack/esmodules.mjs

cd ../test-pack

npm init -y

npm install ../uuid/uuid-*.tgz

node commonjs.js
node esmodules.mjs

0 comments on commit 57d7597

Please sign in to comment.