Skip to content

Commit

Permalink
Remove the streamqueue dependency
Browse files Browse the repository at this point in the history
The `streamqueue` dependency is only used for the test targets in the
Gulpfile to make sure that the test types are run in series. This is
done by modelling the test processes as readable streams and then having
`streamqueue` combine them into a single readable stream for Gulp that
processes the inner readable streams in series (in contrast to the
`ordered-read-streams` dependency which is very similar but processes
the inner streams in parallel).

However, modelling the test processes as readable streams is a bit odd
because we're not actually streaming any data as one might expect.
Instead, we only use them to signal test process completion/abortion.

Fortunately nowadays, with modern Gulp versions, we don't need readable
streams and `streamqueue` anymore because we can achieve the same result
with simple asynchronous functions that can be passed to e.g.
`gulp.series()` calls. Note that we already do this in various places,
and overall it should be a better fit for test process invocations.
  • Loading branch information
timvandermeij committed Jul 22, 2024
1 parent 5184a38 commit 1b9981c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 75 deletions.
99 changes: 45 additions & 54 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import relative from "metalsmith-html-relative";
import rename from "gulp-rename";
import replace from "gulp-replace";
import stream from "stream";
import streamqueue from "streamqueue";
import TerserPlugin from "terser-webpack-plugin";
import Vinyl from "vinyl";
import webpack2 from "webpack";
Expand Down Expand Up @@ -663,9 +662,8 @@ function getTempFile(prefix, suffix) {
return filePath;
}

function createTestSource(testsName, { bot = false, xfaOnly = false } = {}) {
const source = stream.Readable({ objectMode: true });
source._read = function () {
function runTests(testsName, { bot = false, xfaOnly = false } = {}) {
return new Promise((resolve, reject) => {
console.log();
console.log("### Running " + testsName + " tests");

Expand Down Expand Up @@ -699,8 +697,8 @@ function createTestSource(testsName, { bot = false, xfaOnly = false } = {}) {
args.push("--integration");
break;
default:
this.emit("error", new Error("Unknown name: " + testsName));
return null;
reject(new Error(`Unknown tests name '${testsName}'`));
return;
}
if (bot) {
args.push("--strictVerify");
Expand All @@ -715,13 +713,11 @@ function createTestSource(testsName, { bot = false, xfaOnly = false } = {}) {
const testProcess = startNode(args, { cwd: TEST_DIR, stdio: "inherit" });
testProcess.on("close", function (code) {
if (code !== 0) {
throw new Error(`Running ${testsName} tests failed.`);
reject(new Error(`Running ${testsName} tests failed.`));
}
source.push(null);
resolve();
});
return undefined;
};
return source;
});
}

function makeRef(done, bot) {
Expand Down Expand Up @@ -1705,57 +1701,55 @@ function setTestEnv(done) {

gulp.task(
"test",
gulp.series(setTestEnv, "generic", "components", function runTest() {
return streamqueue(
{ objectMode: true },
createTestSource("unit"),
createTestSource("browser"),
createTestSource("integration")
);
gulp.series(setTestEnv, "generic", "components", async function runTest() {
await runTests("unit");
await runTests("browser");
await runTests("integration");
})
);

gulp.task(
"bottest",
gulp.series(setTestEnv, "generic", "components", function runBotTest() {
return streamqueue(
{ objectMode: true },
createTestSource("unit", { bot: true }),
createTestSource("browser", { bot: true }),
createTestSource("integration")
);
gulp.series(setTestEnv, "generic", "components", async function runBotTest() {
await runTests("unit", { bot: true });
await runTests("browser", { bot: true });
await runTests("integration");
})
);

gulp.task(
"xfatest",
gulp.series(setTestEnv, "generic", "components", function runXfaTest() {
return streamqueue(
{ objectMode: true },
createTestSource("unit"),
createTestSource("browser", { xfaOnly: true }),
createTestSource("integration")
);
gulp.series(setTestEnv, "generic", "components", async function runXfaTest() {
await runTests("unit");
await runTests("browser", { xfaOnly: true });
await runTests("integration");
})
);

gulp.task(
"botxfatest",
gulp.series(setTestEnv, "generic", "components", function runBotXfaTest() {
return streamqueue(
{ objectMode: true },
createTestSource("unit", { bot: true }),
createTestSource("browser", { bot: true, xfaOnly: true }),
createTestSource("integration")
);
})
gulp.series(
setTestEnv,
"generic",
"components",
async function runBotXfaTest() {
await runTests("unit", { bot: true });
await runTests("browser", { bot: true, xfaOnly: true });
await runTests("integration");
}
)
);

gulp.task(
"browsertest",
gulp.series(setTestEnv, "generic", "components", function runBrowserTest() {
return createTestSource("browser");
})
gulp.series(
setTestEnv,
"generic",
"components",
async function runBrowserTest() {
await runTests("browser");
}
)
);

gulp.task(
Expand All @@ -1764,33 +1758,30 @@ gulp.task(
setTestEnv,
"generic",
"components",
function runBotBrowserTest() {
return streamqueue(
{ objectMode: true },
createTestSource("browser", { bot: true })
);
async function runBotBrowserTest() {
await runTests("browser", { bot: true });
}
)
);

gulp.task(
"unittest",
gulp.series(setTestEnv, "generic", function runUnitTest() {
return createTestSource("unit");
gulp.series(setTestEnv, "generic", async function runUnitTest() {
await runTests("unit");
})
);

gulp.task(
"integrationtest",
gulp.series(setTestEnv, "generic", function runIntegrationTest() {
return createTestSource("integration");
gulp.series(setTestEnv, "generic", async function runIntegrationTest() {
await runTests("integration");
})
);

gulp.task(
"fonttest",
gulp.series(setTestEnv, function runFontTest() {
return createTestSource("font");
gulp.series(setTestEnv, async function runFontTest() {
await runTests("font");
})
);

Expand Down
20 changes: 0 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"postcss-nesting": "^12.1.5",
"prettier": "^3.3.3",
"puppeteer": "^22.13.0",
"streamqueue": "^1.1.2",
"stylelint": "^16.7.0",
"stylelint-prettier": "^5.0.0",
"terser-webpack-plugin": "^5.3.10",
Expand Down

0 comments on commit 1b9981c

Please sign in to comment.