Skip to content

Commit 0cc6918

Browse files
committed
test: ensure tests will pass with new processing logic
1 parent e18d0cd commit 0cc6918

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

packages/sqip-plugin-triangle/__tests__/unit/__snapshots__/sqip-plugin-triangle.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Array [
5858
"-st",
5959
"1",
6060
"-bg",
61-
" ",
61+
"#040204",
6262
"-out",
6363
"mocked",
6464
]
@@ -89,7 +89,7 @@ Array [
8989
"-st",
9090
"1",
9191
"-bg",
92-
" ",
92+
"#040204",
9393
"-out",
9494
"mocked",
9595
]
@@ -120,7 +120,7 @@ Array [
120120
"-st",
121121
"1",
122122
"-bg",
123-
" ",
123+
"#040204",
124124
"-out",
125125
"mocked",
126126
]

packages/sqip-plugin-triangle/__tests__/unit/sqip-plugin-triangle.test.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,22 @@ const mockedExeca = execa as jest.MockedFunction<typeof execa>
1919
mockedExeca.mockImplementation(() => {
2020
const result = {
2121
stdout:
22-
'<svg viewBox="0 0 1024 768"><rect fill="#bada5500"/><g></g></rect></svg>'
22+
'<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>'
2323
} as unknown as ExecaChildProcess<Buffer>
2424
return result
2525
})
2626

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

29+
const mockedFsReadFile = fs.readFile as jest.MockedFunction<typeof fs.readFile>
30+
mockedFsReadFile.mockImplementation(() =>
31+
Promise.resolve(
32+
Buffer.from(
33+
'<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>'
34+
)
35+
)
36+
)
37+
2938
mockedFsAccess.mockImplementation(async () =>
3039
Promise.reject(new Error('Mocked: Binary not available'))
3140
)
@@ -131,9 +140,9 @@ describe('runTriangle', () => {
131140
await trianglePlugin.apply(fileContent, { ...mockedMetadata })
132141
expect(mockedExeca.mock.calls).toHaveLength(2)
133142
expect(mockedExeca.mock.calls[1]).toHaveLength(2)
134-
const args = mockedExeca.mock.calls[1][1] as string[] || []
135-
args[1] = "mocked"
136-
args[args.length -1] = "mocked"
143+
const args = (mockedExeca.mock.calls[1][1] as string[]) || []
144+
args[1] = 'mocked'
145+
args[args.length - 1] = 'mocked'
137146
expect(args).toMatchSnapshot()
138147
})
139148

@@ -147,9 +156,9 @@ describe('runTriangle', () => {
147156
await trianglePlugin.apply(fileContent, { ...mockedMetadata })
148157
expect(mockedExeca.mock.calls).toHaveLength(2)
149158
expect(mockedExeca.mock.calls[1]).toHaveLength(2)
150-
const args = mockedExeca.mock.calls[1][1] as string[] || []
151-
args[1] = "mocked"
152-
args[args.length -1] = "mocked"
159+
const args = (mockedExeca.mock.calls[1][1] as string[]) || []
160+
args[1] = 'mocked'
161+
args[args.length - 1] = 'mocked'
153162
expect(args).toMatchSnapshot()
154163
})
155164

@@ -166,9 +175,9 @@ describe('runTriangle', () => {
166175
})
167176
expect(mockedExeca.mock.calls).toHaveLength(2)
168177
expect(mockedExeca.mock.calls[1]).toHaveLength(2)
169-
const args = mockedExeca.mock.calls[1][1] as string[] || []
170-
args[1] = "mocked"
171-
args[args.length -1] = "mocked"
178+
const args = (mockedExeca.mock.calls[1][1] as string[]) || []
179+
args[1] = 'mocked'
180+
args[args.length - 1] = 'mocked'
172181
expect(args).toMatchSnapshot()
173182
})
174183

@@ -183,9 +192,9 @@ describe('runTriangle', () => {
183192
await trianglePlugin.apply(fileContent, { ...mockedMetadata })
184193
expect(mockedExeca.mock.calls).toHaveLength(2)
185194
expect(mockedExeca.mock.calls[1]).toHaveLength(2)
186-
const args = mockedExeca.mock.calls[1][1] as string[] || []
187-
args[1] = "mocked"
188-
args[args.length -1] = "mocked"
195+
const args = (mockedExeca.mock.calls[1][1] as string[]) || []
196+
args[1] = 'mocked'
197+
args[args.length - 1] = 'mocked'
189198
expect(args).toMatchSnapshot()
190199
})
191200
})

0 commit comments

Comments
 (0)