Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cli/lookup-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ module.exports = function lookupFiles(
// Handle file
try {
stat = fs.statSync(filepath);
if (stat.isFile()) {
if (stat.isFile() || stat.isFIFO()) {
return filepath;
}
} catch (err) {
Expand Down
58 changes: 58 additions & 0 deletions test/integration/fifo.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';

const assert = require('node:assert/strict');
const { execSync } = require("node:child_process");
const { createReadStream, createWriteStream, mkdtempSync, unlinkSync } = require("node:fs");
const { join } = require("node:path");
const { tmpdir } = require("node:os");

const { invokeMocha, toJSONResult } = require("./helpers");

describe("FIFO support", function () {
it("should accept a test passed as a FIFO", function (done) {
const dir = mkdtempSync(join(tmpdir(), "mocha-test-fifo-"));
const fifoPath = join(dir, 'fifo-1');
execSync(`mkfifo ${fifoPath}`);

const writer = createWriteStream(fifoPath);
writer.on('ready', () => {
writer.write(`
describe('suite from FIFO', () => {
it('should pass', () => true);
});
`, (err) => {
if(!err) writer.end();
});
});

const args = ['--reporter', 'json', fifoPath];

invokeMocha(
args,
(err, res) => {
if (err) return done(err);

try {
const result = toJSONResult(res);
assert.equal(result.code, 0);
assert.equal(result.stats.suites, 1);
assert.equal(result.stats.tests, 1);
assert.equal(result.stats.passes, 1);
assert.equal(result.stats.pending, 0);
assert.equal(result.stats.failures, 0);

// Node hangs if FIFO is never unlinked.
unlinkSync(fifoPath);

done();
} catch (err) {
// Node hangs if FIFO is never read from.
createReadStream(fifoPath).close();

done(err);
}
},
{ stdio: "pipe" },
);
});
});