Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] remove use of experimental fs.promises api (#53346) #53796

Merged
merged 1 commit into from
Dec 26, 2019
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
24 changes: 24 additions & 0 deletions src/core/server/uuid/fs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import Fs from 'fs';
import { promisify } from 'util';

export const readFile = promisify(Fs.readFile);
export const writeFile = promisify(Fs.writeFile);
19 changes: 5 additions & 14 deletions src/core/server/uuid/resolve_uuid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,22 @@
* under the License.
*/

import { promises } from 'fs';
import { join } from 'path';
import { readFile, writeFile } from './fs';
import { resolveInstanceUuid } from './resolve_uuid';
import { configServiceMock } from '../config/config_service.mock';
import { loggingServiceMock } from '../logging/logging_service.mock';
import { BehaviorSubject } from 'rxjs';
import { Logger } from '../logging';

const { readFile, writeFile } = promises;

jest.mock('uuid', () => ({
v4: () => 'NEW_UUID',
}));

jest.mock('fs', () => {
const actual = jest.requireActual('fs');
return {
...actual,
promises: {
...actual.promises,
readFile: jest.fn(() => Promise.resolve('')),
writeFile: jest.fn(() => Promise.resolve('')),
},
};
});
jest.mock('./fs', () => ({
readFile: jest.fn(() => Promise.resolve('')),
writeFile: jest.fn(() => Promise.resolve('')),
}));

const DEFAULT_FILE_UUID = 'FILE_UUID';
const DEFAULT_CONFIG_UUID = 'CONFIG_UUID';
Expand Down
4 changes: 1 addition & 3 deletions src/core/server/uuid/resolve_uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
*/

import uuid from 'uuid';
import { promises } from 'fs';
import { join } from 'path';
import { take } from 'rxjs/operators';
import { readFile, writeFile } from './fs';
import { IConfigService } from '../config';
import { PathConfigType, config as pathConfigDef } from '../path';
import { HttpConfigType, config as httpConfigDef } from '../http';
import { Logger } from '../logging';

const { readFile, writeFile } = promises;

const FILE_ENCODING = 'utf8';
const FILE_NAME = 'uuid';

Expand Down
6 changes: 3 additions & 3 deletions utilities/visual_regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ async function compareScreenshots() {

const diffImagePath = path.resolve(DIFF_SCREENSHOTS_DIR, screenshot);

const sessionImage = PNG.sync.read(await fs.promises.readFile(sessionImagePath));
const baselineImage = PNG.sync.read(await fs.promises.readFile(baselineImagePath));
const sessionImage = PNG.sync.read(await readFileAsync(sessionImagePath));
const baselineImage = PNG.sync.read(await readFileAsync(baselineImagePath));
const { width, height } = sessionImage;
const diff = new PNG({ width, height });

Expand All @@ -117,7 +117,7 @@ async function compareScreenshots() {
{ threshold: 0 }
);

await fs.promises.writeFile(diffImagePath, PNG.sync.write(diff));
await writeFileAsync(diffImagePath, PNG.sync.write(diff));

const change = numDiffPixels / (width * height);
const changePercentage = (change * 100).toFixed(2);
Expand Down