Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-export as Stubscape from shescape/testing #1308

Merged
merged 6 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Versioning].

## [Unreleased]

- _No changes yet_
- Re-export `Shescape` as `Stubscape` from `shescape/testing`. ([#1308])

## [2.0.2] - 2023-11-19

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/breakage/testing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/compat/testing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 2 additions & 6 deletions test/integration/testing/commonjs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
6 changes: 1 addition & 5 deletions test/integration/testing/functional.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion test/unit/testing/stubscape.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 20 additions & 3 deletions testing.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
17 changes: 16 additions & 1 deletion testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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.
Expand Down