Skip to content

Commit c8b7ebb

Browse files
Moved the fs.Stats assertions to a utility function in a separate file so it can be used by other tests
1 parent 8c44494 commit c8b7ebb

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

test/specs/stats.spec.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
const readdir = require("../../");
44
const dir = require("../utils/dir");
5+
const isStats = require("../utils/is-stats");
56
const { expect } = require("chai");
6-
const fs = require("fs");
77

88
describe("options.stats", () => {
99
describe("Synchronous API", () => {
@@ -79,16 +79,7 @@ describe("options.stats", () => {
7979

8080
// Each item should be a valid fs.Stats object
8181
for (let stat of data) {
82-
expect(stat).to.be.an("object");
83-
expect(stat).to.be.an.instanceOf(fs.Stats);
84-
expect(stat.mode).to.be.a("number");
85-
expect(stat.uid).to.be.a("number");
86-
expect(stat.gid).to.be.a("number");
87-
expect(stat.size).to.be.a("number");
88-
expect(stat.atime).to.be.an.instanceOf(Date);
89-
expect(stat.mtime).to.be.an.instanceOf(Date);
90-
expect(stat.ctime).to.be.an.instanceOf(Date);
91-
expect(stat.path).to.be.a("string");
82+
expect(stat).to.satisfy(isStats);
9283
}
9384

9485
done();

test/utils/is-stats.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict";
2+
3+
const fs = require("fs");
4+
const { expect } = require("chai");
5+
6+
module.exports = isStats;
7+
8+
/**
9+
* Assets that the given objects is a Readdir Enhanced Stats object.
10+
*/
11+
function isStats (stats) {
12+
expect(stats).to.be.an("object").and.instanceOf(fs.Stats);
13+
expect(stats.atime).to.be.an.instanceOf(Date);
14+
expect(stats.atimeMs).to.be.a("number").above(0);
15+
expect(stats.birthtime).to.be.an.instanceOf(Date);
16+
expect(stats.birthtimeMs).to.be.a("number").above(0);
17+
expect(stats.blksize).to.be.a("number").above(0);
18+
expect(stats.blocks).to.be.a("number").at.least(0);
19+
expect(stats.ctime).to.be.an.instanceOf(Date);
20+
expect(stats.ctimeMs).to.be.a("number").above(0);
21+
expect(stats.depth).to.be.a("number").at.least(0);
22+
expect(stats.dev).to.be.a("number").above(0);
23+
expect(stats.gid).to.be.a("number").at.least(0);
24+
expect(stats.ino).to.be.a("number").above(0);
25+
expect(stats.mode).to.be.a("number").above(0);
26+
expect(stats.mtime).to.be.an.instanceOf(Date);
27+
expect(stats.mtimeMs).to.be.a("number").above(0);
28+
expect(stats.nlink).to.be.a("number").above(0);
29+
expect(stats.path).to.be.a("string").with.length.above(0);
30+
expect(stats.rdev).to.be.a("number").at.least(0);
31+
expect(stats.size).to.be.a("number").at.least(0);
32+
expect(stats.uid).to.be.a("number").at.least(0);
33+
34+
return true;
35+
}

0 commit comments

Comments
 (0)