Skip to content

Commit

Permalink
[CP-2607] Test fixes after update (node to 20.9.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarski committed Jul 9, 2024
1 parent 655c590 commit 02d17dd
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 105 deletions.
36 changes: 14 additions & 22 deletions libs/core/device-file-system/commands/file-upload.command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import fs from "fs"
import path from "path"
import mock from "mock-fs"
import { fs, vol } from "memfs";
import { DeviceCommunicationError, Endpoint, Method } from "core-device/models"
import { FileUploadCommand } from "Core/device-file-system/commands/file-upload.command"
import { DeviceProtocol } from "device-protocol/feature"
Expand Down Expand Up @@ -65,16 +63,15 @@ beforeEach(() => {

describe("When requested file is unreadable", () => {
beforeAll(() => {
mock(
vol.fromNestedJSON(
{
"test.txt": "Hello World!\n",
},
{ createCwd: false, createTmp: false }
)
})

afterAll(() => {
mock.restore()
vol.reset()
})

test("returns `ResultObject.failed` with error description and path of filed file", async () => {
Expand Down Expand Up @@ -102,32 +99,30 @@ describe("When requested file is unreadable", () => {

describe("When requested file is valid", () => {
beforeAll(() => {
mock(
vol.fromNestedJSON(
{
"test.txt": "Hello World!\n",
},
{ createCwd: false, createTmp: false }
)
})
afterAll(() => {
mock.restore()
vol.reset()
})
beforeEach(() => {
const fileMock = fs.readFileSync(path.join(process.cwd(), "test.txt"))
const fileMock = fs.readFileSync("test.txt")
fileSystemService.readFile = jest.fn().mockReturnValue(fileMock)
})

describe("when `DeviceManager.device.request` returns success response", () => {
beforeAll(() => {
mock(
vol.fromNestedJSON(
{
"test.txt": "Hello World!\n",
},
{ createCwd: false, createTmp: false }
)
})
afterAll(() => {
mock.restore()
vol.reset()
})
beforeEach(() => {
deviceProtocol.device.request = jest
Expand Down Expand Up @@ -158,15 +153,14 @@ describe("When requested file is valid", () => {

describe("when `DeviceManager.device.request` returns failed response on first request", () => {
beforeAll(() => {
mock(
vol.fromNestedJSON(
{
"test.txt": "Hello World!\n",
},
{ createCwd: false, createTmp: false }
)
})
afterAll(() => {
mock.restore()
vol.reset()
})
beforeEach(() => {
deviceProtocol.device.request = jest
Expand Down Expand Up @@ -204,15 +198,14 @@ describe("When requested file is valid", () => {

describe("when `DeviceManager.device.request` returns failed response on the next requests", () => {
beforeAll(() => {
mock(
vol.fromNestedJSON(
{
"test.txt": "Hello World!\n",
},
{ createCwd: false, createTmp: false }
)
})
afterAll(() => {
mock.restore()
vol.reset()
})
beforeEach(() => {
deviceProtocol.device.request = jest
Expand Down Expand Up @@ -260,15 +253,14 @@ describe("When requested file is valid", () => {

describe("when `DeviceManager.device.request` returns failed response with `RequestResponseStatus.InsufficientStorage` status", () => {
beforeAll(() => {
mock(
vol.fromNestedJSON(
{
"test.txt": "Hello World!\n",
},
{ createCwd: false, createTmp: false }
)
})
afterAll(() => {
mock.restore()
vol.reset()
})
beforeEach(() => {
deviceProtocol.device.request = jest
Expand Down
162 changes: 81 additions & 81 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,8 @@
"jest-styled-components": "^7.0.8",
"lint-staged": "^13.0.3",
"lodash": "^4.17.21",
"memfs": "^4.6.0",
"memfs": "^4.9.3",
"mini-css-extract-plugin": "^2.6.1",
"mock-fs": "^5.2.0",
"mockdate": "^3.0.5",
"moment": "^2.29.4",
"node-gyp": "^10.0.1",
Expand Down

0 comments on commit 02d17dd

Please sign in to comment.