From 522227b10379785b75716036423da1f89a89be7f Mon Sep 17 00:00:00 2001 From: spalger Date: Sun, 22 Dec 2019 08:03:02 -0700 Subject: [PATCH] remove one more usage of fs.promises --- src/core/server/uuid/resolve_uuid.test.ts | 11 ++++------- src/core/server/uuid/resolve_uuid.ts | 6 ++++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/core/server/uuid/resolve_uuid.test.ts b/src/core/server/uuid/resolve_uuid.test.ts index 1ddd667eacdee..360baa4123ce0 100644 --- a/src/core/server/uuid/resolve_uuid.test.ts +++ b/src/core/server/uuid/resolve_uuid.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import { promises } from 'fs'; +import Fs from 'fs'; import { join } from 'path'; import { resolveInstanceUuid } from './resolve_uuid'; import { configServiceMock } from '../config/config_service.mock'; @@ -25,7 +25,7 @@ import { loggingServiceMock } from '../logging/logging_service.mock'; import { BehaviorSubject } from 'rxjs'; import { Logger } from '../logging'; -const { readFile, writeFile } = promises; +const { readFile, writeFile } = Fs; jest.mock('uuid', () => ({ v4: () => 'NEW_UUID', @@ -35,11 +35,8 @@ jest.mock('fs', () => { const actual = jest.requireActual('fs'); return { ...actual, - promises: { - ...actual.promises, - readFile: jest.fn(() => Promise.resolve('')), - writeFile: jest.fn(() => Promise.resolve('')), - }, + readFile: jest.fn().mockImplementation((...args) => process.nextTick(args.pop())), + writeFile: jest.fn().mockImplementation((...args) => process.nextTick(args.pop())), }; }); diff --git a/src/core/server/uuid/resolve_uuid.ts b/src/core/server/uuid/resolve_uuid.ts index 17412bfa0544c..ebe1250a8a490 100644 --- a/src/core/server/uuid/resolve_uuid.ts +++ b/src/core/server/uuid/resolve_uuid.ts @@ -18,7 +18,8 @@ */ import uuid from 'uuid'; -import { promises } from 'fs'; +import Fs from 'fs'; +import { promisify } from 'util'; import { join } from 'path'; import { take } from 'rxjs/operators'; import { IConfigService } from '../config'; @@ -26,7 +27,8 @@ import { PathConfigType, config as pathConfigDef } from '../path'; import { HttpConfigType, config as httpConfigDef } from '../http'; import { Logger } from '../logging'; -const { readFile, writeFile } = promises; +const readFile = promisify(Fs.readFile); +const writeFile = promisify(Fs.writeFile); const FILE_ENCODING = 'utf8'; const FILE_NAME = 'uuid';