{"id":15598173,"url":"https://github.com/boneskull/packtester","last_synced_at":"2026-02-23T22:33:49.428Z","repository":{"id":42829523,"uuid":"265965918","full_name":"boneskull/packtester","owner":"boneskull","description":"Test the output of your npm-published package","archived":false,"fork":false,"pushed_at":"2023-01-06T06:37:47.000Z","size":1315,"stargazers_count":3,"open_issues_count":14,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-28T20:02:09.155Z","etag":null,"topics":["npm","pack","package","production","sanity","smoke","test","testing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/boneskull.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-21T22:38:24.000Z","updated_at":"2023-03-04T05:17:16.000Z","dependencies_parsed_at":"2023-02-05T13:16:07.041Z","dependency_job_id":null,"html_url":"https://github.com/boneskull/packtester","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":"boneskull/boneskull-template","purl":"pkg:github/boneskull/packtester","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boneskull%2Fpacktester","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boneskull%2Fpacktester/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boneskull%2Fpacktester/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boneskull%2Fpacktester/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boneskull","download_url":"https://codeload.github.com/boneskull/packtester/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boneskull%2Fpacktester/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267577976,"owners_count":24110350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["npm","pack","package","production","sanity","smoke","test","testing"],"created_at":"2024-10-03T01:29:34.273Z","updated_at":"2026-02-23T22:33:44.404Z","avatar_url":"https://github.com/boneskull.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# packtester\n\n\u003e Assert your published package actually works\n\n## Motivation\n\nRunning your regular test suite (e.g., `npm test`) in CI _will_ miss packaging-related issues, such as missing files and package exports.\n\nThere's no staging registry you can test with, so when something's published, it's published. If there's a problem with it, you have to issue a patch and publish again. We can't avoid the problem entirely, but `packtester` gets us closer.\n\nThis is kind of a pain to setup manually, so automating it might be nice, right?\n\n## Install\n\n```shell\n$ npm install packtester --save-dev\n```\n\n### Setup (Automatic)\n\n\u003e TODO: via `init` command; needs implementation\n\n### Setup (Manual)\n\nAdd a `pretest` script to your `scripts` field in `package.json`:\n\n```json\n{\n  \"scripts\": {\n    \"pretest\": \"packtester\",\n    \"test\": \"my-regular-test-script\"\n  }\n}\n```\n\n\u003e It's recommended to _also_ run `packtester` during `prepublishOnly`, so it will check at the last minute before you publish.\n\nCreate a `__pack_tests__` directory. All files (with `.js`, `.cjs`, and `.mjs` extensions, by default) in this directory will be run with _your module_ installed as a dependency. Here's an example file:\n\n```js\n// packtester.packtest.js\n\nconst assert = require('assert');\n// remember, use your package like a consumer would\nconst pkg = require('packtester/package.json'); // yeah yeah I know\n\nlet packtester;\nassert.doesNotThrow(() =\u003e {\n  packtester = require(pkg.name);\n}, `could not require('${pkg.name}')`);\n\n// packtester exports a function, `packTest`\nassert.ok(\n  typeof packtester.packTest === 'function',\n  'did not export \"packTest\" function'\n);\n\n// ESM!\nassert.doesNotReject(import(pkg.name), `could not import('${pkg.name}')`);\n\nassert.doesNotThrow(() =\u003e {\n  require(`${pkg.name}/${pkg.main}`);\n}, `could not require('${pkg.name}/${pkg.main}') directly`);\n```\n\n**You do not need to add test files for `packtester` to your published package** (unless you want to); in other words, they don't need to be in the `files` prop of `package.json` and/or can be added to `.npmignore`, if desired.\n\n### Suggested CI Configuration\n\nRun `packtester` as a job or step _before_ the main test suite (e.g., `npm test`) as a \"smoke test,\" and have subsequent steps wait for this to complete successfully.\n\n#### GitHub Actions Example\n\nAdd a `smoke-test` script to `package.json` (remove the `\"pretest\": \"packtester\"` script, if present):\n\n```json\n{\n  \"scripts\": {\n    \"smoke-test\": \"packtester\",\n    \"test\": \"your-test-command\"\n  }\n}\n```\n\nAnd in your workflow file (e.g., `.github/workflows/my-workflow.yml`):\n\n```yaml\njobs:\n  smoke-test:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - uses: bahmutov/npm-install@v1\n      - name: Smoke Test\n        run: npm run smoke-test\n  test:\n    runs-on: ubuntu-latest\n    needs: smoke-test\n    steps:\n      - uses: actions/checkout@v2\n      - uses: bahmutov/npm-install@v1\n      - name: Full Test Suite\n        run: npm test\n```\n\n## Options\n\n### Custom Targets\n\nBy supplying positional arguments to `packtester`, you can point it at any directory, file, or glob. Example:\n\n```json\n{\n  \"scripts\": {\n    \"pretest\": \"packtester \\\"my-smoke-tests/**/*.js\\\"\",\n    \"test\": \"my-regular-test-script\"\n  }\n}\n```\n\n### Custom `package.json`\n\n`packtester` needs the `package.json` of your package to run. Use the `--package \u003cpackage.json\u003e` command-line option to use a specific `package.json` file. This may be useful in a monorepo or workspace. Example:\n\n```json\n{\n  \"scripts\": {\n    \"pretest\": \"packtester --package=./packages/subpackage/package.json\",\n    \"test\": \"my-regular-test-script\"\n  }\n}\n```\n\n### More Help\n\nRun `npx packtester --help` to see more usage options.\n\n## API\n\n`packtester` exports a single property, `packTest`, which is an `async` function.\n\n### `packtester.packTest([opts]): Promise\u003cvoid\u003e`\n\nDoes everything the `packtester` CLI does.\n\n`opts` is an options object and supports properties (all optional):\n\n- `{string|string[]}` `target` - One or more target files, dirs, globs. Defaults to `__pack_tests__`\n- `{string}` `cwd` - Current working directory\n- `{PackageJson}` `pkg` - A parsed `package.json`\n- `{string}` `npmPath` - Path to `npm` executable\n- `{number}` `logLevel` - Log level, 0-5, with 0 being \"error\" and 5 being \"trace\"\n\n## About Tests\n\nThe purpose of these tests is to make assertions about the state of your package's public API. The question you're trying to answer is this: _is my package usable when installed via a package manager?_\n\nRemember: you won't have your `devDependencies` installed; this means no test frameworks, assertion libraries, etc. The built-in [assert](https://nodejs.org/api/assert.html) module works well for this use case.\n\n### ESM Example\n\n\u003e TODO\n\n## How It Works\n\n`packtester`:\n\n1. Runs `npm pack` on your project to generate a tarball in a temporary directory\n1. Runs `npm install` against the tarball in the temp dir\n1. Copies the target tests into temp dir\n1. Runs the target tests, exiting with non-zero code if they fail\n1. Removes the temp dir\n\nBy installing from a tarball created from `npm pack`, we simulate what would happen if you installed your project via a package manager, e.g., `npm install my-package`.\n\n## License\n\nCopyright © 2020 Christopher Hiller. Licensed Apache-2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboneskull%2Fpacktester","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboneskull%2Fpacktester","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboneskull%2Fpacktester/lists"}