mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
* remove use of experimental fs.promises api * remove one more usage of fs.promises * switch to an alternate fs module to maintain testing strategy Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
88f8bef2fd
commit
dbf1c3c8cd
4 changed files with 33 additions and 20 deletions
24
src/core/server/uuid/fs.ts
Normal file
24
src/core/server/uuid/fs.ts
Normal file
|
@ -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);
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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 });
|
||||
|
||||
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue