Skip to content

Commit

Permalink
test: ensure tests will pass with new processing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed Feb 24, 2024
1 parent e18d0cd commit 0cc6918
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Array [
"-st",
"1",
"-bg",
" ",
"#040204",
"-out",
"mocked",
]
Expand Down Expand Up @@ -89,7 +89,7 @@ Array [
"-st",
"1",
"-bg",
" ",
"#040204",
"-out",
"mocked",
]
Expand Down Expand Up @@ -120,7 +120,7 @@ Array [
"-st",
"1",
"-bg",
" ",
"#040204",
"-out",
"mocked",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@ const mockedExeca = execa as jest.MockedFunction<typeof execa>
mockedExeca.mockImplementation(() => {
const result = {
stdout:
'<svg viewBox="0 0 1024 768"><rect fill="#bada5500"/><g></g></rect></svg>'
'<svg viewBox="0 0 1024 768"><rect width="100%" height="100%" fill="#bada5500"/><g><path fill="#fff" d="M300,188 L0,188 L174,146 L300,188"/></g></rect></svg>'
} as unknown as ExecaChildProcess<Buffer>
return result
})

const mockedFsAccess = fs.access as jest.MockedFunction<typeof fs.access>

const mockedFsReadFile = fs.readFile as jest.MockedFunction<typeof fs.readFile>
mockedFsReadFile.mockImplementation(() =>
Promise.resolve(
Buffer.from(
'<svg viewBox="0 0 1024 768"><rect width="100%" height="100%" fill="#bada5500"/><g><path fill="#fff" d="M300,188 L0,188 L174,146 L300,188"/></g></rect></svg>'
)
)
)

mockedFsAccess.mockImplementation(async () =>
Promise.reject(new Error('Mocked: Binary not available'))
)
Expand Down Expand Up @@ -131,9 +140,9 @@ describe('runTriangle', () => {
await trianglePlugin.apply(fileContent, { ...mockedMetadata })
expect(mockedExeca.mock.calls).toHaveLength(2)
expect(mockedExeca.mock.calls[1]).toHaveLength(2)
const args = mockedExeca.mock.calls[1][1] as string[] || []
args[1] = "mocked"
args[args.length -1] = "mocked"
const args = (mockedExeca.mock.calls[1][1] as string[]) || []
args[1] = 'mocked'
args[args.length - 1] = 'mocked'
expect(args).toMatchSnapshot()
})

Expand All @@ -147,9 +156,9 @@ describe('runTriangle', () => {
await trianglePlugin.apply(fileContent, { ...mockedMetadata })
expect(mockedExeca.mock.calls).toHaveLength(2)
expect(mockedExeca.mock.calls[1]).toHaveLength(2)
const args = mockedExeca.mock.calls[1][1] as string[] || []
args[1] = "mocked"
args[args.length -1] = "mocked"
const args = (mockedExeca.mock.calls[1][1] as string[]) || []
args[1] = 'mocked'
args[args.length - 1] = 'mocked'
expect(args).toMatchSnapshot()
})

Expand All @@ -166,9 +175,9 @@ describe('runTriangle', () => {
})
expect(mockedExeca.mock.calls).toHaveLength(2)
expect(mockedExeca.mock.calls[1]).toHaveLength(2)
const args = mockedExeca.mock.calls[1][1] as string[] || []
args[1] = "mocked"
args[args.length -1] = "mocked"
const args = (mockedExeca.mock.calls[1][1] as string[]) || []
args[1] = 'mocked'
args[args.length - 1] = 'mocked'
expect(args).toMatchSnapshot()
})

Expand All @@ -183,9 +192,9 @@ describe('runTriangle', () => {
await trianglePlugin.apply(fileContent, { ...mockedMetadata })
expect(mockedExeca.mock.calls).toHaveLength(2)
expect(mockedExeca.mock.calls[1]).toHaveLength(2)
const args = mockedExeca.mock.calls[1][1] as string[] || []
args[1] = "mocked"
args[args.length -1] = "mocked"
const args = (mockedExeca.mock.calls[1][1] as string[]) || []
args[1] = 'mocked'
args[args.length - 1] = 'mocked'
expect(args).toMatchSnapshot()
})
})

0 comments on commit 0cc6918

Please sign in to comment.