Skip to content

Commit 1db539b

Browse files
committed
Fix protocol fs test
1 parent 92f6d43 commit 1db539b

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

packages/protocol/test/fs.test.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ describe("fs", () => {
7070
describe("chown", () => {
7171
it("should chown existing file", async () => {
7272
const file = await helper.createTmpFile();
73-
await expect(util.promisify(fs.chown)(file, 1, 1))
73+
await expect(util.promisify(nativeFs.chown)(file, 1000, 1000))
7474
.resolves.toBeUndefined();
7575
});
7676

7777
it("should fail to chown nonexistent file", async () => {
78-
await expect(util.promisify(fs.chown)(helper.tmpFile(), 1, 1))
78+
await expect(util.promisify(fs.chown)(helper.tmpFile(), 1000, 1000))
7979
.rejects.toThrow("ENOENT");
8080
});
8181
});
@@ -198,13 +198,13 @@ describe("fs", () => {
198198
it("should fchown existing file", async () => {
199199
const file = await helper.createTmpFile();
200200
const fd = await util.promisify(nativeFs.open)(file, "r");
201-
await expect(util.promisify(fs.fchown)(fd, 1, 1))
201+
await expect(util.promisify(fs.fchown)(fd, 1000, 1000))
202202
.resolves.toBeUndefined();
203203
await util.promisify(nativeFs.close)(fd);
204204
});
205205

206206
it("should fail to fchown nonexistent file", async () => {
207-
await expect(util.promisify(fs.fchown)(99999, 1, 1))
207+
await expect(util.promisify(fs.fchown)(99999, 1000, 1000))
208208
.rejects.toThrow("EBADF");
209209
});
210210
});
@@ -275,7 +275,7 @@ describe("fs", () => {
275275
it("should futimes existing file", async () => {
276276
const file = await helper.createTmpFile();
277277
const fd = await util.promisify(nativeFs.open)(file, "w");
278-
await expect(util.promisify(fs.futimes)(fd, 1, 1))
278+
await expect(util.promisify(fs.futimes)(fd, 1000, 1000))
279279
.resolves.toBeUndefined();
280280
await util.promisify(nativeFs.close)(fd);
281281
});
@@ -311,12 +311,12 @@ describe("fs", () => {
311311
describe("lchown", () => {
312312
it("should lchown existing file", async () => {
313313
const file = await helper.createTmpFile();
314-
await expect(util.promisify(fs.lchown)(file, 1, 1))
314+
await expect(util.promisify(fs.lchown)(file, 1000, 1000))
315315
.resolves.toBeUndefined();
316316
});
317317

318318
it("should fail to lchown nonexistent file", async () => {
319-
await expect(util.promisify(fs.lchown)(helper.tmpFile(), 1, 1))
319+
await expect(util.promisify(fs.lchown)(helper.tmpFile(), 1000, 1000))
320320
.rejects.toThrow("ENOENT");
321321
});
322322
});
@@ -621,7 +621,10 @@ describe("fs", () => {
621621
});
622622
});
623623

624-
it("should dispose", () => {
625-
client.dispose();
624+
it("should dispose", (done) => {
625+
setTimeout(() => {
626+
client.dispose();
627+
done();
628+
}, 100);
626629
});
627630
});

packages/protocol/test/spdlog.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ describe("spdlog", () => {
2727
.toContain("critical");
2828
});
2929

30-
it("should dispose", () => {
30+
it("should dispose", (done) => {
3131
setTimeout(() => {
3232
client.dispose();
33+
done();
3334
}, 100);
3435
});
3536
});

packages/protocol/test/trash.test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as util from "util";
33
import { Module } from "../src/common/proxy";
44
import { createClient, Helper } from "./helpers";
55

6+
// tslint:disable deprecation to use fs.exists
7+
68
describe("trash", () => {
79
const client = createClient();
810
const trash = client.modules[Module.Trash];
@@ -18,9 +20,10 @@ describe("trash", () => {
1820
expect(await util.promisify(fs.exists)(file)).toBeFalsy();
1921
});
2022

21-
it("should dispose", () => {
23+
it("should dispose", (done) => {
2224
setTimeout(() => {
2325
client.dispose();
26+
done();
2427
}, 100);
2528
});
2629
});

scripts/test-setup.js

+12
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ Object.defineProperty(fs.read, util.promisify.custom, {
2121
global.requestAnimationFrame = (cb) => {
2222
setTimeout(cb, 0);
2323
};
24+
25+
// lchmod might not be available. Jest runs graceful-fs which makes this a no-op
26+
// when it doesn't exist but that doesn't seem to always run when running
27+
// multiple tests (or maybe it gets undone after a test).
28+
if (!fs.lchmod) {
29+
fs.lchmod = function (path, mode, cb) {
30+
if (cb) {
31+
process.nextTick(cb);
32+
}
33+
};
34+
fs.lchmodSync = function () {};
35+
}

0 commit comments

Comments
 (0)