From 0912b9b912e2cb5a6835384cd96e74c7eb703c05 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Tue, 28 Apr 2020 14:13:40 +0200 Subject: [PATCH] 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 --- .github/workflows/ci.yml | 2 ++ package.json | 1 + scripts/testpack.sh | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100755 scripts/testpack.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 342840f5..763ecfb5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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' diff --git a/package.json b/package.json index 979ae7df..124d8999 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,7 @@ "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", diff --git a/scripts/testpack.sh b/scripts/testpack.sh new file mode 100755 index 00000000..141ec2c9 --- /dev/null +++ b/scripts/testpack.sh @@ -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