How to use service.getFileInfo method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

service.test.js

Source: service.test.js Github

copy
1import { jest, expect, describe, test, beforeEach } from '@jest/globals';
2import TestUtil from '../_util/testUtil.js';
3import fsPromises from 'fs/promises';
4import fs from 'fs';
5
6import { Service } from '../../../server/services.js';
7import config from '../../../server/config.js';
8
9describe('#Service - test suite for test data processing', () => {
10  beforeEach(() => {
11    jest.restoreAllMocks();
12    jest.clearAllMocks();
13  });
14
15  test('#createFileStream', () => {
16    const currentReadable = TestUtil.generateReadableStream(['teste']);
17    jest.spyOn(fs, fs.createReadStream.name).mockReturnValue(currentReadable);
18
19    const service = new Service();
20    const file = 'file.html';
21    const result = service.createFileStream(file);
22
23    expect(result).toStrictEqual(currentReadable);
24    expect(fs.createReadStream).toHaveBeenCalledWith(file);
25  });
26
27  test('#getFileInfo', async () => {
28    jest.spyOn(fsPromises, fsPromises.access.name).mockResolvedValue();
29
30    const currentSong = 'mySong.mp3';
31    const service = new Service();
32    const result = await service.getFileInfo(currentSong);
33    const expectResult = {
34      type: '.mp3',
35      name: `${config.dir.publicDirectory}/${currentSong}`,
36    };
37
38    expect(result).toStrictEqual(expectResult);
39  });
40
41  test('#getFileStream', async () => {
42    const currentReadable = TestUtil.generateReadableStream(['teste']);
43    const currentAudio = 'myAudio.mp3';
44    const currentAudioFullPath = `${config.dir.publicDirectory}/${currentAudio}`;
45    const fileInfo = {
46      type: '.mp3',
47      name: currentAudioFullPath,
48    };
49
50    const service = new Service();
51
52    jest.spyOn(service, service.getFileInfo.name).mockResolvedValue(fileInfo);
53    jest
54      .spyOn(service, service.createFileStream.name)
55      .mockReturnValue(currentReadable);
56
57    const result = await service.getFileStream(currentAudio);
58    const expectResult = {
59      type: fileInfo.type,
60      stream: currentReadable,
61    };
62    expect(result).toStrictEqual(expectResult);
63    expect(service.getFileInfo).toHaveBeenCalledWith(currentAudio);
64    expect(service.createFileStream).toHaveBeenCalledWith(fileInfo.name);
65  });
66});
67
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium Xcuitest Driver on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)