|
| 1 | +const { promises: fs } = require("fs"); |
| 2 | +const os = require("os"); |
| 3 | +const path = require("path"); |
1 | 4 | const { extendExpect } = require("../index"); |
2 | 5 |
|
3 | | -extendExpect(expect, "unused"); |
| 6 | +/** |
| 7 | + * @type {string} |
| 8 | + */ |
| 9 | +let logFilePath; |
| 10 | +/** |
| 11 | + * @param {string[][]} speech |
| 12 | + */ |
| 13 | +function speakMock(speech) { |
| 14 | + // Check existing fixtures for how to mock speech output. |
| 15 | + const mockedSpeach = speech |
| 16 | + .map((line) => { |
| 17 | + return `Speaking [${line |
| 18 | + .map((group) => { |
| 19 | + return `'${group}'`; |
| 20 | + }) |
| 21 | + .join(", ")}]\n`; |
| 22 | + }) |
| 23 | + .join(""); |
| 24 | + return fs.writeFile(logFilePath, mockedSpeach, { flag: "a" }); |
| 25 | +} |
4 | 26 |
|
5 | | -test("custom inline snapshot with no lines", () => { |
6 | | - expect([]).toMatchSpeechInlineSnapshot(``); |
| 27 | +beforeAll(async () => { |
| 28 | + logFilePath = path.join( |
| 29 | + os.tmpdir(), |
| 30 | + "srtl-testing", |
| 31 | + `extendExpect-${new Date().valueOf()}.log` |
| 32 | + ); |
| 33 | + await fs.mkdir(path.dirname(logFilePath), { recursive: true }); |
| 34 | + await fs.writeFile(logFilePath, "", { flag: "w" }); |
| 35 | + extendExpect(expect, logFilePath); |
7 | 36 | }); |
8 | 37 |
|
9 | | -test("custom inline snapshot with one line", () => { |
| 38 | +afterAll(async () => { |
| 39 | + await fs.unlink(logFilePath); |
| 40 | +}); |
| 41 | + |
| 42 | +test("custom inline snapshot with no lines", async () => { |
| 43 | + await expect(async () => { |
| 44 | + await speakMock([]); |
| 45 | + }).toMatchSpeechInlineSnapshot(``); |
| 46 | +}); |
| 47 | + |
| 48 | +test("custom inline snapshot with one line", async () => { |
10 | 49 | const actualSpeech = [["banner landmark"]]; |
11 | | - expect(actualSpeech).toMatchSpeechInlineSnapshot(`"banner landmark"`); |
| 50 | + await expect(async () => { |
| 51 | + await speakMock(actualSpeech); |
| 52 | + }).toMatchSpeechInlineSnapshot(`"banner landmark"`); |
12 | 53 | }); |
13 | 54 |
|
14 | | -test("custom inline snapshot with two lines", () => { |
| 55 | +test("custom inline snapshot with two lines", async () => { |
15 | 56 | const actualSpeech = [["banner landmark"], ["Search", "combobox"]]; |
16 | | - expect(actualSpeech).toMatchSpeechInlineSnapshot(` |
| 57 | + await expect(async () => { |
| 58 | + await speakMock(actualSpeech); |
| 59 | + }).toMatchSpeechInlineSnapshot(` |
17 | 60 | "banner landmark" |
18 | 61 | "Search, combobox" |
19 | 62 | `); |
|
0 commit comments