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

remove use of experimental fs.promises api #53346

Merged
merged 7 commits into from
Dec 25, 2019
11 changes: 4 additions & 7 deletions src/core/server/uuid/resolve_uuid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
* 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';
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',
Expand All @@ -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())),
};
});

Expand Down
6 changes: 4 additions & 2 deletions src/core/server/uuid/resolve_uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
*/

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';
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';
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