Skip to content

Commit

Permalink
feat: new --add flag
Browse files Browse the repository at this point in the history
This flag allows extra dependencies to be installed to help run smoke tests.  It's recommended not to be used, but it will certainly make things easier for some use cases.

Further info is in `README.md`
  • Loading branch information
boneskull committed Aug 7, 2023
1 parent 63b76af commit 41b423c
Show file tree
Hide file tree
Showing 26 changed files with 1,262 additions and 848 deletions.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Feeling lucky? Run `npm run test:smoke`.
### Wait—What Should My Script Do?

In many cases, executing the package's entry point is sufficient:
In many cases, executing the package's entry point might be enough:

```json
{
Expand All @@ -109,9 +109,27 @@ Otherwise:
- If your package distributes an executable, you might want to run that instead, and give it some common arguments (assuming it depends on your entry point). _Or_ you could go BUCK WILD and run it a bunch of different ways.
- If your package is lazy-loading its dependencies--like if you have a `require()` or `await import()` within some function that isn't called at startup--you may need to do more work than this.

**If you find yourself needing a dev tool to run your script, you are missing the point.** Again: you want to load/run your package as a consumer would--that means _running your distfiles_ **without** dev deps.
### But I Need a Dev Tool To Run My Script

That's it. That's the project.
OK--_fine_--but this is not necessarily recommended, because the result is not what a consumer would get. How much does that matter? You decide.

Provide the `--add <thing>` option to `midnight-smoker`, where `thing` is anything `npm install <thing>` could install:

```json
{
"scripts": {
"test:smoke": "smoker --add ts-node smoke",
"smoke": "ts-node ./some-script.ts"
},
"devDependencies": {
"ts-node": "10.9.1"
}
}
```

If unspecified in `--add`, `midnight-smoker` will use the version of the dependency in the package's `devDependencies`/`dependencies`/`optionalDependencies`/`peerDepedenencies` (in that order). If it does not appear in any of these fields, it will just pull down the `latest` tag of the dependency.

`--add` can be provided multiple times.

## Installation

Expand Down
95 changes: 89 additions & 6 deletions __snapshots__/cli.spec.ts.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,94 @@
exports['midnight-smoker CLI should show help text 1'] = {
"stdout": "smoker <script> [scripts..]\n\nRun tests against a package as it would be published\n\nPositionals:\n script [string]\n scripts [string]\n\nBehavior:\n -r, --require Package identifier for extra dependency needed by smoke\n tests [array]\n --workspace One or more npm workspaces to test [array]\n --all Test all workspaces [boolean]\n --include-root Include the workspace root; must provide '--all' [boolean]\n --install-args Extra arguments to pass to `npm install` [array]\n --dir Working directory to use [string] [default: new temp dir]\n --force Overwrite working directory if it exists [boolean]\n --clean Truncate working directory; must provide '--force'\n [boolean]\n --npm Path to `npm` executable [string] [default: `npm` in PATH]\n --verbose Print output from npm [boolean]\n --bail When running scripts, halt on first error [boolean]\n --json Output JSON only [boolean]\n\nOptions:\n --version Show version number [boolean]\n --help Show help [boolean]",
exports['midnight-smoker CLI flag --help should show help text 1'] = {
"stdout": "smoker <script> [scripts..]\n\nRun tests against a package as it would be published\n\nPositionals:\n script [string]\n scripts [string]\n\nBehavior:\n --add Additional dependency to provide to smoke tests [array]\n --workspace One or more npm workspaces to test [array]\n --all Test all workspaces [boolean]\n --include-root Include the workspace root; must provide '--all' [boolean]\n --install-args Extra arguments to pass to `npm install` [array]\n --dir Working directory to use [string] [default: new temp dir]\n --force Overwrite working directory if it exists [boolean]\n --clean Truncate working directory; must provide '--force' [boolean]\n --npm Path to `npm` executable [string] [default: `npm` in PATH]\n --verbose Print output from npm [boolean]\n --bail When running scripts, halt on first error [boolean]\n --json Output JSON only [boolean]\n\nOptions:\n --version Show version number [boolean]\n --help Show help [boolean]\n\nFor more info, see https://github.com/boneskull/midnight-smoker",
"stderr": "",
"exitCode": 0
}

exports['midnight-smoker CLI should smoke test this and produce JSON output 1'] = {
"stdout": "{\n \"results\": [\n {\n \"pkgName\": \"midnight-smoker\",\n \"script\": \"smoke\",\n \"rawResult\": {\n \"command\": \"<path/to>/bin/npm run-script smoke\",\n \"escapedCommand\": \"<path/to>/bin/npm\\\" run-script smoke\",\n \"exitCode\": 0,\n \"stdout\": \"\\n> midnight-smoker@<version> smoke\\n> <path/to/>smoker.js --version\\n\\n<version>\",\n \"stderr\": \"\",\n \"failed\": false,\n \"timedOut\": false,\n \"isCanceled\": false,\n \"killed\": false\n }\n }\n ],\n \"total\": 1,\n \"executed\": 1,\n \"scripts\": [\n \"smoke\"\n ]\n}",
"stderr": "",
"exitCode": 0
exports['midnight-smoker CLI flag --json when the test fails should provide helpful result 1'] = `
{
"results": [
{
"pkgName": "fail",
"script": "smoke",
"error": {},
"rawResult": {
"shortMessage": "Command failed with exit code 1: <path/to/>/bin/node <path/to/>/bin/npm run-script smoke",
"command": <path/to/>/bin/node <path/to/>/bin/npm run-script smoke",
"escapedCommand": <path/to/>/bin/node\\" <path/to/>/bin/npm\\" run-script smoke",
"exitCode": 1,
"stdout": "\\n> fail@1.0.0 smoke\\n> exit 1\\n",
"stderr": "",
"failed": true,
"timedOut": false,
"isCanceled": false,
"killed": false
},
"cwd": "<cwd>"
}
],
"scripts": [
"smoke"
],
"total": 1,
"failures": 1,
"executed": 1
}
`

exports['midnight-smoker CLI flag when the test passes should produce expected output 1'] = `
💨 midnight-smoker v3.0.4
- Packing current project...
✔ Packed 1 package
- Installing from 1 tarball...
✔ Installed 1 package from tarball
- Running script 0/1...
✔ Successfully ran 1 script
✔ Lovey-dovey! 💖
`

exports['midnight-smoker CLI flag when the test fails should produce expected output 1'] = `
💨 midnight-smoker v3.0.4
- Packing current project...
✔ Packed 1 package
- Installing from 1 tarball...
✔ Installed 1 package from tarball
- Running script 0/1...
✖ 1 of 1 script failed
Error details for failed package fail:
(runScript) Script "smoke" in package "fail" failed: Command failed with exit code 1: /home/boneskull/.nvm/versions/node/v20.5.0/bin/node /home/boneskull/.nvm/versions/node/v20.5.0/bin/npm run-script smoke
> fail@1.0.0 smoke
> exit 1
✖ 🤮 Maurice!
`

exports['midnight-smoker CLI flag --json when the test passes should produce expected output 1'] = `
{
"results": [
{
"pkgName": "midnight-smoker",
"script": "smoke:js",
"rawResult": {
"command": <path/to/>/bin/node <path/to/>/bin/npm run-script smoke:js",
"escapedCommand": <path/to/>/bin/node\\" <path/to/>/bin/npm\\" run-script \\"smoke:js\\"",
"exitCode": 0,
"stdout": "\\n> midnight-smoker@<version> smoke:js\\n> <path/to/>smoker.js --version\\n\\n<version>",
"stderr": "",
"failed": false,
"timedOut": false,
"isCanceled": false,
"killed": false
},
"cwd": "<cwd>"
}
],
"total": 1,
"executed": 1,
"scripts": [
"smoke:js"
]
}
`
Loading

0 comments on commit 41b423c

Please sign in to comment.