-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathno-shell.test.js
More file actions
52 lines (43 loc) · 1.25 KB
/
no-shell.test.js
File metadata and controls
52 lines (43 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* @overview Contains (additional) unit tests for the escaping functionality for
* no shell on Unix.
* @license MIT
*/
import { testProp } from "@fast-check/ava";
import * as fc from "fast-check";
import * as old from "../../../node_modules/shescape-previous/src/internal/unix/no-shell.js";
import * as nosh from "../../../src/internal/unix/no-shell.js";
const numRuns = 5_000_000;
testProp(
"escape functionality is unchanged",
[fc.string()],
(t, arg) => {
const updFn = nosh.getEscapeFunction();
const oldFn = old.getEscapeFunction();
const got = updFn(arg);
const want = oldFn(arg);
t.is(got, want);
},
{ numRuns },
);
testProp(
"flag protection functionality is unchanged",
[fc.string()],
(t, arg) => {
const updFn = nosh.getFlagProtectionFunction();
const oldFn = old.getFlagProtectionFunction();
const got = updFn(arg);
const want = oldFn(arg);
t.is(got, want);
},
{ numRuns },
);
testProp("quote function", [fc.string()], (t, arg) => {
const expected = {
instanceOf: Error,
message: "Quoting is not supported when no shell is used",
};
const [escapeFn, quoteFn] = nosh.getQuoteFunction();
t.throws(() => escapeFn(arg), expected);
t.throws(() => quoteFn(arg), expected);
});