diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ca60d92c..dda26eaf2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ Versioning]. ## [Unreleased] -- _No changes yet_ +- Re-export `Shescape` as `Stubscape` from `shescape/testing`. ([#1308]) ## [2.0.2] - 2023-11-19 @@ -326,6 +326,7 @@ Versioning]. [#1149]: https://github.com/ericcornelissen/shescape/pull/1149 [#1280]: https://github.com/ericcornelissen/shescape/pull/1280 [#1285]: https://github.com/ericcornelissen/shescape/pull/1285 +[#1308]: https://github.com/ericcornelissen/shescape/pull/1308 [552e8ea]: https://github.com/ericcornelissen/shescape/commit/552e8eab56861720b1d4e5474fb65741643358f9 [keep a changelog]: https://keepachangelog.com/en/1.0.0/ [semantic versioning]: https://semver.org/spec/v2.0.0.html diff --git a/docs/testing.md b/docs/testing.md index 1cff4a8f7..aaacf3789 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -19,7 +19,7 @@ mocking ([for example with Jest][jest-module-mock]). ```javascript import assert from "node:assert"; -import { Shescape as Stubscape, Throwscape } from "shescape/testing"; +import { Stubscape, Throwscape } from "shescape/testing"; // Test subject function functionUnderTest(Shescape) { diff --git a/test/breakage/testing.test.js b/test/breakage/testing.test.js index f9f4dfa17..1e31b96a8 100644 --- a/test/breakage/testing.test.js +++ b/test/breakage/testing.test.js @@ -8,7 +8,7 @@ import * as fc from "fast-check"; import { arbitrary } from "./_.js"; -import { Shescape as Stubscape, Throwscape } from "shescape/testing"; +import { Stubscape, Throwscape } from "shescape/testing"; import { Shescape as Previoustub, Throwscape as Previousthrow, diff --git a/test/compat/testing.test.js b/test/compat/testing.test.js index bcbc6f468..7f4794544 100644 --- a/test/compat/testing.test.js +++ b/test/compat/testing.test.js @@ -9,7 +9,7 @@ import * as fc from "fast-check"; import { arbitrary } from "./_.js"; -import { Shescape as Stubscape, Throwscape } from "../../testing.js"; +import { Stubscape, Throwscape } from "../../testing.js"; testProp( "Stubscape#escape", diff --git a/test/integration/testing/commonjs.test.js b/test/integration/testing/commonjs.test.js index 49d425f78..223d0bb05 100644 --- a/test/integration/testing/commonjs.test.js +++ b/test/integration/testing/commonjs.test.js @@ -10,14 +10,10 @@ import * as fc from "fast-check"; import { arbitrary } from "../_.js"; -import { - injectionStrings, - Shescape as Stubscape, - Throwscape, -} from "shescape/testing"; +import { injectionStrings, Stubscape, Throwscape } from "shescape/testing"; import { injectionStrings as injectionStringsCjs, - Shescape as StubscapeCjs, + Stubscape as StubscapeCjs, Throwscape as ThrowscapeCjs, } from "../../../testing.cjs"; diff --git a/test/integration/testing/functional.test.js b/test/integration/testing/functional.test.js index ea6283ded..22ef6a10a 100644 --- a/test/integration/testing/functional.test.js +++ b/test/integration/testing/functional.test.js @@ -11,11 +11,7 @@ import * as fc from "fast-check"; import { arbitrary } from "../_.js"; import { Shescape } from "shescape"; -import { - injectionStrings, - Shescape as Stubscape, - Throwscape, -} from "shescape/testing"; +import { injectionStrings, Stubscape, Throwscape } from "shescape/testing"; test("injection strings", (t) => { t.true(Array.isArray(injectionStrings)); diff --git a/test/unit/testing/stubscape.test.js b/test/unit/testing/stubscape.test.js index 348a90a63..1ea997dcc 100644 --- a/test/unit/testing/stubscape.test.js +++ b/test/unit/testing/stubscape.test.js @@ -9,7 +9,7 @@ import * as fc from "fast-check"; import { arbitrary, constants } from "./_.js"; -import { Shescape as Stubscape } from "../../../testing.js"; +import { Stubscape } from "../../../testing.js"; testProp( "escape valid arguments", diff --git a/testing.d.ts b/testing.d.ts index bc2cea4d5..f67147ea1 100644 --- a/testing.d.ts +++ b/testing.d.ts @@ -18,13 +18,30 @@ import type { Shescape as ShescapeType } from "shescape"; export const injectionStrings: string[]; /** - * A test stub of shescape that has the same input-output profile as the real - * shescape implementation. + * An optimistic test stub of Shescape that has the same input-output profile as + * the real Shescape implementation. * * In particular: + * - The constructor never fails. * - Returns a string for all stringable inputs. * - Errors on non-stringable inputs. - * - Converts non-array inputs to single-item arrays where necessary. + * - Errors on non-array inputs where arrays are expected. + * - Errors when trying to quote when `shell: false`. + */ +export const Stubscape: ShescapeType; + +/** + * An optimistic test stub of Shescape that has the same input-output profile as + * the real Shescape implementation. + * + * In particular: + * - The constructor never fails. + * - Returns a string for all stringable inputs. + * - Errors on non-stringable inputs. + * - Errors on non-array inputs where arrays are expected. + * - Errors when trying to quote when `shell: false`. + * + * @alias Stubscape */ export const Shescape: ShescapeType; diff --git a/testing.js b/testing.js index d0e8ea424..1143aeb19 100644 --- a/testing.js +++ b/testing.js @@ -36,7 +36,7 @@ export const injectionStrings = [ * - Errors on non-array inputs where arrays are expected. * - Errors when trying to quote when `shell: false`. */ -export class Shescape { +export class Stubscape { constructor(options = {}) { this.shell = options.shell; } @@ -62,6 +62,21 @@ export class Shescape { } } +/** + * An optimistic test stub of Shescape that has the same input-output profile as + * the real Shescape implementation. + * + * In particular: + * - The constructor never fails. + * - Returns a string for all stringable inputs. + * - Errors on non-stringable inputs. + * - Errors on non-array inputs where arrays are expected. + * - Errors when trying to quote when `shell: false`. + * + * @alias Stubscape + */ +export const Shescape = Stubscape; + /** * A test stub of Shescape that can't be instantiated. This can be used to * simulate a failure to instantiate Shescape in your code.