|
1 | 1 | import * as fs from "fs"; |
| 2 | +import * as os from "os"; |
2 | 3 | import * as path from "path"; |
3 | 4 |
|
4 | 5 | import * as core from "@actions/core"; |
@@ -392,3 +393,41 @@ test("getFileOidsUnderPath throws on unexpected output format", async (t) => { |
392 | 393 | runGitCommandStub.restore(); |
393 | 394 | } |
394 | 395 | }); |
| 396 | + |
| 397 | +test("listFiles returns array of file paths", async (t) => { |
| 398 | + sinon |
| 399 | + .stub(gitUtils, "runGitCommand") |
| 400 | + .resolves(["dir/file.txt", "README.txt"].join(os.EOL)); |
| 401 | + |
| 402 | + await t.notThrowsAsync(async () => { |
| 403 | + const result = await gitUtils.listFiles("/some/path"); |
| 404 | + t.is(result.length, 2); |
| 405 | + t.is(result[0], "dir/file.txt"); |
| 406 | + }); |
| 407 | +}); |
| 408 | + |
| 409 | +test("getGeneratedFiles returns generated files only", async (t) => { |
| 410 | + const runGitCommandStub = sinon.stub(gitUtils, "runGitCommand"); |
| 411 | + |
| 412 | + runGitCommandStub |
| 413 | + .onFirstCall() |
| 414 | + .resolves(["dir/file.txt", "test.json", "README.txt"].join(os.EOL)); |
| 415 | + runGitCommandStub |
| 416 | + .onSecondCall() |
| 417 | + .resolves( |
| 418 | + [ |
| 419 | + "dir/file.txt: linguist-generated: unspecified", |
| 420 | + "test.json: linguist-generated: true", |
| 421 | + "README.txt: linguist-generated: false", |
| 422 | + ].join(os.EOL), |
| 423 | + ); |
| 424 | + |
| 425 | + await t.notThrowsAsync(async () => { |
| 426 | + const result = await gitUtils.getGeneratedFiles("/some/path"); |
| 427 | + |
| 428 | + t.assert(runGitCommandStub.calledTwice); |
| 429 | + |
| 430 | + t.is(result.length, 1); |
| 431 | + t.is(result[0], "test.json"); |
| 432 | + }); |
| 433 | +}); |
0 commit comments