Skip to content

Commit

Permalink
Restructure integration tests to reduce concurrency interference
Browse files Browse the repository at this point in the history
AVA concurrency determines how many *test files* are run at once. With
the pre-existing integration test files, this still resulted in huge
numbers of tests within one file, thus resulting in slow tests
(especially in CI). This restructuring aims to reduce this and improve
integration test performance.
  • Loading branch information
ericcornelissen committed Aug 20, 2023
1 parent 21e93a8 commit e6cd5fb
Show file tree
Hide file tree
Showing 36 changed files with 662 additions and 117 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
"test": "npm run test:unit && npm run test:integration && npm run test:e2e && npm run test:compat",
"test:compat": "mocha test/compat/**/*.test.cjs",
"test:compat-all": "nve 10.13.0,12.0.0,14.0.0,16.0.0,18.0.0,19.0.0,20.0.0 mocha test/compat/**/*.test.cjs",
"test:e2e": "ava test/e2e/**/*.test.js --timeout 5m",
"test:integration": "ava test/integration/**/*.test.js --timeout 5m",
"test:e2e": "ava test/e2e/**/*.test.js --timeout 1m",
"test:integration": "ava test/integration/**/*.test.js --timeout 1m",
"test:unit": "ava test/unit/**/*.test.js",
"transpile": "rollup --config rollup.config.js && cp index.d.ts index.d.cts && cp testing.d.ts testing.d.cts",
"verify": "npm run format:check && npm run license-check && npm run lint && npm run coverage && npm run vet",
Expand Down
12 changes: 5 additions & 7 deletions test/_constants.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ module.exports.shellsUnix = [
module.exports.binCmd = "cmd.exe";
module.exports.binPowerShell = "powershell.exe";

const exeVariants = (exe) => [
exe,
exe.replace(".exe", ".EXE"),
exe.replace(".exe", ""),
];

module.exports.shellsWindows = [
module.exports.binCmd,
"cmd.EXE",
"cmd",
module.exports.binPowerShell,
].flatMap(exeVariants);
"powershell.EXE",
"powershell",
];
21 changes: 21 additions & 0 deletions test/integration/escape-all/bash.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @overview Contains integration tests for `shescape.escapeAll` specifically
* for use with the Bourne-again shell (Bash).
* @license MIT
*/

import test from "ava";

import { constants, generate } from "../_.js";

import { escapeAll } from "shescape";

let runTest = constants.isWindows ? test.skip : test;

runTest("inputs are escaped for bash", (t) => {
const shell = "bash";
for (const { expected, input, options } of generate.escapeExamples(shell)) {
const result = escapeAll([input], options);
t.deepEqual(result, [expected]);
}
});
21 changes: 21 additions & 0 deletions test/integration/escape-all/cmd.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @overview Contains integration tests for `shescape.escapeAll` specifically
* for use with the Windows Command Prompt.
* @license MIT
*/

import test from "ava";

import { constants, generate } from "../_.js";

import { escapeAll } from "shescape";

let runTest = constants.isWindows ? test : test.skip;

runTest("inputs are escaped for cmd.exe", (t) => {
const shell = "cmd.exe";
for (const { expected, input, options } of generate.escapeExamples(shell)) {
const result = escapeAll([input], options);
t.deepEqual(result, [expected]);
}
});
23 changes: 23 additions & 0 deletions test/integration/escape-all/commonjs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @overview Contains integration tests for the transpiled version of
* `shescape.escapeAll`.
* @license MIT
*/

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

import { arbitrary } from "../_.js";

import { escapeAll } from "shescape";
import { escapeAll as escapeAllCjs } from "../../../index.cjs";

testProp(
"esm === cjs",
[fc.array(arbitrary.shescapeArg()), arbitrary.shescapeOptions()],
(t, args, options) => {
const resultEsm = escapeAll(args, options);
const resultCjs = escapeAllCjs(args, options);
t.deepEqual(resultEsm, resultCjs);
},
);
21 changes: 21 additions & 0 deletions test/integration/escape-all/csh.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @overview Contains integration tests for `shescape.escapeAll` specifically
* for use with the C shell (csh).
* @license MIT
*/

import test from "ava";

import { constants, generate } from "../_.js";

import { escapeAll } from "shescape";

let runTest = constants.isWindows ? test.skip : test;

runTest("inputs are escaped for csh", (t) => {
const shell = "csh";
for (const { expected, input, options } of generate.escapeExamples(shell)) {
const result = escapeAll([input], options);
t.deepEqual(result, [expected]);
}
});
21 changes: 21 additions & 0 deletions test/integration/escape-all/dash.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @overview Contains integration tests for `shescape.escapeAll` specifically
* for use with the Debian Almquist shell (Dash).
* @license MIT
*/

import test from "ava";

import { constants, generate } from "../_.js";

import { escapeAll } from "shescape";

let runTest = constants.isWindows ? test.skip : test;

runTest("inputs are escaped for dash", (t) => {
const shell = "dash";
for (const { expected, input, options } of generate.escapeExamples(shell)) {
const result = escapeAll([input], options);
t.deepEqual(result, [expected]);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,9 @@ import { testProp } from "@fast-check/ava";
import test from "ava";
import * as fc from "fast-check";

import { arbitrary, constants, generate, macros } from "./_.js";
import { arbitrary, constants, macros } from "../_.js";

import { escape, escapeAll } from "shescape";
import { escapeAll as escapeAllCjs } from "../../index.cjs";

for (const shell of generate.platformShells()) {
test(`inputs are escaped for ${shell}`, (t) => {
for (const { expected, input, options } of generate.escapeExamples(shell)) {
const result = escapeAll([input], options);
t.deepEqual(result, [expected]);
}
});
}

testProp(
"return values",
Expand Down Expand Up @@ -82,13 +72,3 @@ testProp("invalid arguments", [arbitrary.shescapeOptions()], (t, options) => {
test(macros.prototypePollution, (_, payload) => {
escapeAll(["a"], payload);
});

testProp(
"esm === cjs",
[fc.array(arbitrary.shescapeArg()), arbitrary.shescapeOptions()],
(t, args, options) => {
const resultEsm = escapeAll(args, options);
const resultCjs = escapeAllCjs(args, options);
t.deepEqual(resultEsm, resultCjs);
},
);
21 changes: 21 additions & 0 deletions test/integration/escape-all/powershell.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @overview Contains integration tests for `shescape.escapeAll` specifically
* for use with Windows PowerShell.
* @license MIT
*/

import test from "ava";

import { constants, generate } from "../_.js";

import { escapeAll } from "shescape";

let runTest = constants.isWindows ? test : test.skip;

runTest("inputs are escaped for powershell.exe", (t) => {
const shell = "powershell.exe";
for (const { expected, input, options } of generate.escapeExamples(shell)) {
const result = escapeAll([input], options);
t.deepEqual(result, [expected]);
}
});
21 changes: 21 additions & 0 deletions test/integration/escape-all/zsh.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @overview Contains integration tests for `shescape.escapeAll` specifically
* for use with the Z shell (Zsh).
* @license MIT
*/

import test from "ava";

import { constants, generate } from "../_.js";

import { escapeAll } from "shescape";

let runTest = constants.isWindows ? test.skip : test;

runTest("inputs are escaped for zsh", (t) => {
const shell = "zsh";
for (const { expected, input, options } of generate.escapeExamples(shell)) {
const result = escapeAll([input], options);
t.deepEqual(result, [expected]);
}
});
21 changes: 21 additions & 0 deletions test/integration/escape/bash.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @overview Contains integration tests for `shescape.escape` specifically for
* use with the Bourne-again shell (Bash).
* @license MIT
*/

import test from "ava";

import { constants, generate } from "../_.js";

import { escape } from "shescape";

let runTest = constants.isWindows ? test.skip : test;

runTest("inputs are escaped for bash", (t) => {
const shell = "bash";
for (const { expected, input, options } of generate.escapeExamples(shell)) {
const result = escape(input, options);
t.deepEqual(result, expected);
}
});
21 changes: 21 additions & 0 deletions test/integration/escape/cmd.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @overview Contains integration tests for `shescape.escape` specifically for
* use with the Windows Command Prompt.
* @license MIT
*/

import test from "ava";

import { constants, generate } from "../_.js";

import { escape } from "shescape";

let runTest = constants.isWindows ? test : test.skip;

runTest("inputs are escaped for cmd.exe", (t) => {
const shell = "cmd.exe";
for (const { expected, input, options } of generate.escapeExamples(shell)) {
const result = escape(input, options);
t.deepEqual(result, expected);
}
});
22 changes: 22 additions & 0 deletions test/integration/escape/commonjs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @overview Contains integration tests for the transpiled version of
* `shescape.escape`.
* @license MIT
*/

import { testProp } from "@fast-check/ava";

import { arbitrary } from "../_.js";

import { escape as escape } from "shescape";
import { escape as escapeCjs } from "../../../index.cjs";

testProp(
"esm === cjs",
[arbitrary.shescapeArg(), arbitrary.shescapeOptions()],
(t, arg, options) => {
const resultEsm = escape(arg, options);
const resultCjs = escapeCjs(arg, options);
t.is(resultEsm, resultCjs);
},
);
21 changes: 21 additions & 0 deletions test/integration/escape/csh.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @overview Contains integration tests for `shescape.escape` specifically for
* use with the C shell (csh).
* @license MIT
*/

import test from "ava";

import { constants, generate } from "../_.js";

import { escape } from "shescape";

let runTest = constants.isWindows ? test.skip : test;

runTest("inputs are escaped for csh", (t) => {
const shell = "csh";
for (const { expected, input, options } of generate.escapeExamples(shell)) {
const result = escape(input, options);
t.deepEqual(result, expected);
}
});
21 changes: 21 additions & 0 deletions test/integration/escape/dash.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @overview Contains integration tests for `shescape.escape` specifically for
* use with the Debian Almquist shell (Dash).
* @license MIT
*/

import test from "ava";

import { constants, generate } from "../_.js";

import { escape } from "shescape";

let runTest = constants.isWindows ? test.skip : test;

runTest("inputs are escaped for dash", (t) => {
const shell = "dash";
for (const { expected, input, options } of generate.escapeExamples(shell)) {
const result = escape(input, options);
t.deepEqual(result, expected);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,9 @@
import { testProp } from "@fast-check/ava";
import test from "ava";

import { arbitrary, constants, generate, macros } from "./_.js";
import { arbitrary, constants, macros } from "../_.js";

import { escape as escape } from "shescape";
import { escape as escapeCjs } from "../../index.cjs";

for (const shell of generate.platformShells()) {
test(`input is escaped for ${shell}`, (t) => {
for (const { expected, input, options } of generate.escapeExamples(shell)) {
const result = escape(input, options);
t.is(result, expected);
}
});
}

testProp(
"return values",
Expand All @@ -38,13 +28,3 @@ testProp("invalid arguments", [arbitrary.shescapeOptions()], (t, options) => {
test(macros.prototypePollution, (_, payload) => {
escape("a", payload);
});

testProp(
"esm === cjs",
[arbitrary.shescapeArg(), arbitrary.shescapeOptions()],
(t, arg, options) => {
const resultEsm = escape(arg, options);
const resultCjs = escapeCjs(arg, options);
t.is(resultEsm, resultCjs);
},
);
21 changes: 21 additions & 0 deletions test/integration/escape/powershell.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @overview Contains integration tests for `shescape.escape` specifically for
* use with Windows PowerShell.
* @license MIT
*/

import test from "ava";

import { constants, generate } from "../_.js";

import { escape } from "shescape";

let runTest = constants.isWindows ? test : test.skip;

runTest("inputs are escaped for powershell.exe", (t) => {
const shell = "powershell.exe";
for (const { expected, input, options } of generate.escapeExamples(shell)) {
const result = escape(input, options);
t.deepEqual(result, expected);
}
});

0 comments on commit e6cd5fb

Please sign in to comment.