Skip to content

Commit

Permalink
Extend main module compatibility tests with property tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ericcornelissen committed Oct 22, 2023
1 parent a185cce commit c936f4e
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 5 deletions.
3 changes: 2 additions & 1 deletion test/compat/_.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
*/

import * as arbitrary from "../_arbitraries.js";
import * as constants from "../_constants.js";

export { arbitrary };
export { arbitrary, constants };
142 changes: 139 additions & 3 deletions test/compat/index.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
* @overview Contains smoke tests for Shescape to verify compatibility with Node
* versions.
* @overview Contains smoke tests for the main shescape module to verify
* compatibility with Node.js versions.
* @license MIT
*/

import { testProp } from "@fast-check/ava";
import * as fc from "fast-check";
import test from "ava";

import * as constants from "../_constants.js";
import { arbitrary, constants } from "./_.js";

import { Shescape } from "../../index.js";

Expand Down Expand Up @@ -59,3 +61,137 @@ test("has a working `quoteAll` function", (t) => {
t.is(typeof output, "string");
}
});

testProp(
"Shescape#escape",
[arbitrary.shescapeOptions(), arbitrary.shescapeArg()],
(t, options, arg) => {
let shescape;

try {
shescape = new Shescape(options);
} catch (error) {
const known = ["No executable could be found for "];

if (!known.some((knownError) => error.message.includes(knownError))) {
t.fail(`Unexpected error:\n${error}`);
}
}

try {
shescape.escape(arg);
} catch (error) {
const known = [
"Cannot read property 'escape' of undefined",
"Cannot read properties of undefined (reading 'escape')",
];

if (!known.some((knownError) => error.message.includes(knownError))) {
t.fail(`Unexpected error:\n${error}`);
}
}

t.pass();
},
);

testProp(
"Shescape#escapeAll",
[arbitrary.shescapeOptions(), fc.array(arbitrary.shescapeArg())],
(t, options, args) => {
let shescape;

try {
shescape = new Shescape(options);
} catch (error) {
const known = ["No executable could be found for "];

if (!known.some((knownError) => error.message.includes(knownError))) {
t.fail(`Unexpected error:\n${error}`);
}
}

try {
shescape.escapeAll(args);
} catch (error) {
const known = [
"Cannot read property 'escapeAll' of undefined",
"Cannot read properties of undefined (reading 'escapeAll')",
];

if (!known.some((knownError) => error.message.includes(knownError))) {
t.fail(`Unexpected error:\n${error}`);
}
}

t.pass();
},
);

testProp(
"Shescape#quote",
[arbitrary.shescapeOptions(), arbitrary.shescapeArg()],
(t, options, arg) => {
let shescape;

try {
shescape = new Shescape(options);
} catch (error) {
const known = ["No executable could be found for "];

if (!known.some((knownError) => error.message.includes(knownError))) {
t.fail(`Unexpected error:\n${error}`);
}
}

try {
shescape.quote(arg);
} catch (error) {
const known = [
"Cannot read property 'quote' of undefined",
"Cannot read properties of undefined (reading 'quote')",
"Quoting is not supported when no shell is used",
];

if (!known.some((knownError) => error.message.includes(knownError))) {
t.fail(`Unexpected error:\n${error}`);
}
}

t.pass();
},
);

testProp(
"Shescape#quoteAll",
[arbitrary.shescapeOptions(), fc.array(arbitrary.shescapeArg())],
(t, options, args) => {
let shescape;

try {
shescape = new Shescape(options);
} catch (error) {
const known = ["No executable could be found for "];

if (!known.some((knownError) => error.message.includes(knownError))) {
t.fail(`Unexpected error:\n${error}`);
}
}

try {
shescape.quoteAll(args);
} catch (error) {
const known = [
"Cannot read property 'quoteAll' of undefined",
"Cannot read properties of undefined (reading 'quoteAll')",
"Quoting is not supported when no shell is used",
];

if (!known.some((knownError) => error.message.includes(knownError))) {
t.fail(`Unexpected error:\n${error}`);
}
}

t.pass();
},
);
2 changes: 1 addition & 1 deletion test/compat/testing.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @overview Contains smoke tests for shescape testing module to verify
* @overview Contains smoke tests for the shescape testing module to verify
* compatibility with Node.js versions.
* @license MIT
*/
Expand Down

0 comments on commit c936f4e

Please sign in to comment.