File tree Expand file tree Collapse file tree 3 files changed +30
-16
lines changed Expand file tree Collapse file tree 3 files changed +30
-16
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * Licensed to Elasticsearch B.V. under one or more contributor
3+ * license agreements. See the NOTICE file distributed with
4+ * this work for additional information regarding copyright
5+ * ownership. Elasticsearch B.V. licenses this file to you under
6+ * the Apache License, Version 2.0 (the "License"); you may
7+ * not use this file except in compliance with the License.
8+ * You may obtain a copy of the License at
9+ *
10+ * http://www.apache.org/licenses/LICENSE-2.0
11+ *
12+ * Unless required by applicable law or agreed to in writing,
13+ * software distributed under the License is distributed on an
14+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+ * KIND, either express or implied. See the License for the
16+ * specific language governing permissions and limitations
17+ * under the License.
18+ */
19+
20+ import Fs from 'fs' ;
21+ import { promisify } from 'util' ;
22+
23+ export const readFile = promisify ( Fs . readFile ) ;
24+ export const writeFile = promisify ( Fs . writeFile ) ;
Original file line number Diff line number Diff line change 1717 * under the License.
1818 */
1919
20- import Fs from 'fs' ;
2120import { join } from 'path' ;
21+ import { readFile , writeFile } from './fs' ;
2222import { resolveInstanceUuid } from './resolve_uuid' ;
2323import { configServiceMock } from '../config/config_service.mock' ;
2424import { loggingServiceMock } from '../logging/logging_service.mock' ;
2525import { BehaviorSubject } from 'rxjs' ;
2626import { Logger } from '../logging' ;
2727
28- const { readFile, writeFile } = Fs ;
29-
3028jest . mock ( 'uuid' , ( ) => ( {
3129 v4 : ( ) => 'NEW_UUID' ,
3230} ) ) ;
3331
34- jest . mock ( 'fs' , ( ) => {
35- const actual = jest . requireActual ( 'fs' ) ;
36- return {
37- ...actual ,
38- readFile : jest . fn ( ) . mockImplementation ( ( ...args ) => process . nextTick ( args . pop ( ) ) ) ,
39- writeFile : jest . fn ( ) . mockImplementation ( ( ...args ) => process . nextTick ( args . pop ( ) ) ) ,
40- } ;
41- } ) ;
32+ jest . mock ( './fs' , ( ) => ( {
33+ readFile : jest . fn ( ( ) => Promise . resolve ( '' ) ) ,
34+ writeFile : jest . fn ( ( ) => Promise . resolve ( '' ) ) ,
35+ } ) ) ;
4236
4337const DEFAULT_FILE_UUID = 'FILE_UUID' ;
4438const DEFAULT_CONFIG_UUID = 'CONFIG_UUID' ;
Original file line number Diff line number Diff line change 1818 */
1919
2020import uuid from 'uuid' ;
21- import Fs from 'fs' ;
22- import { promisify } from 'util' ;
2321import { join } from 'path' ;
2422import { take } from 'rxjs/operators' ;
23+ import { readFile , writeFile } from './fs' ;
2524import { IConfigService } from '../config' ;
2625import { PathConfigType , config as pathConfigDef } from '../path' ;
2726import { HttpConfigType , config as httpConfigDef } from '../http' ;
2827import { Logger } from '../logging' ;
2928
30- const readFile = promisify ( Fs . readFile ) ;
31- const writeFile = promisify ( Fs . writeFile ) ;
32-
3329const FILE_ENCODING = 'utf8' ;
3430const FILE_NAME = 'uuid' ;
3531
You can’t perform that action at this time.
0 commit comments