From 41b423cc14cd8493347581a55c7efdc19d527b2f Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Mon, 31 Jul 2023 20:57:02 -0700 Subject: [PATCH] feat: new --add flag 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` --- README.md | 24 +- __snapshots__/cli.spec.ts.js | 95 +++- package-lock.json | 492 ++++-------------- package.json | 15 +- src/cli.ts | 481 ++++++++--------- src/pm/npm.ts | 57 +- src/pm/pm.ts | 17 +- src/smoker.ts | 52 +- src/stubs.d.ts | 0 src/types.ts | 15 +- src/util.ts | 166 ++++++ test/assertions.ts | 51 ++ test/e2e/cli.spec.ts | 203 +++++--- test/e2e/fixture/add/package.json | 10 + test/e2e/fixture/add/smoke.js | 3 + test/e2e/fixture/failure/package.json | 7 + .../dev-peer/package.json | 8 + .../optional-peer/package.json | 8 + .../pick-package-version/peer/package.json | 5 + .../prod-peer/package.json | 8 + test/e2e/helpers.ts | 35 ++ test/e2e/util.spec.ts | 87 ++++ test/unit/mocks.ts | 1 + test/unit/pm/npm.spec.ts | 77 ++- test/unit/smoker.spec.ts | 49 +- test/unit/util.spec.ts | 144 +++++ 26 files changed, 1262 insertions(+), 848 deletions(-) create mode 100644 src/stubs.d.ts create mode 100644 src/util.ts create mode 100644 test/assertions.ts create mode 100644 test/e2e/fixture/add/package.json create mode 100644 test/e2e/fixture/add/smoke.js create mode 100644 test/e2e/fixture/failure/package.json create mode 100644 test/e2e/fixture/pick-package-version/dev-peer/package.json create mode 100644 test/e2e/fixture/pick-package-version/optional-peer/package.json create mode 100644 test/e2e/fixture/pick-package-version/peer/package.json create mode 100644 test/e2e/fixture/pick-package-version/prod-peer/package.json create mode 100644 test/e2e/helpers.ts create mode 100644 test/e2e/util.spec.ts create mode 100644 test/unit/util.spec.ts diff --git a/README.md b/README.md index f3387cac2..f3c07f653 100644 --- a/README.md +++ b/README.md @@ -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 { @@ -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 ` option to `midnight-smoker`, where `thing` is anything `npm install ` 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 diff --git a/__snapshots__/cli.spec.ts.js b/__snapshots__/cli.spec.ts.js index ec22b38a7..f6b5a5b47 100644 --- a/__snapshots__/cli.spec.ts.js +++ b/__snapshots__/cli.spec.ts.js @@ -1,11 +1,94 @@ -exports['midnight-smoker CLI should show help text 1'] = { - "stdout": "smoker