Skip to content

Commit

Permalink
Fix tests on windows, and package bundled js (#710)
Browse files Browse the repository at this point in the history
* Fix tests on windows, and package bundled js

* Fix tests on windows
  • Loading branch information
robinraju authored Apr 9, 2024
1 parent 452eec1 commit 937fc82
Show file tree
Hide file tree
Showing 3 changed files with 5,185 additions and 24,578 deletions.
22 changes: 16 additions & 6 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as core from "@actions/core"
import * as fs from "fs"
import * as path from "path"
import * as handlers from "typed-rest-client/Handlers"
Expand Down Expand Up @@ -109,9 +108,15 @@ afterEach(async () => {
})

function readFromFile(fileName: string): string {
return fs.readFileSync(`${__dirname}/resource/${fileName}`, {
const fileContents = fs.readFileSync(`${__dirname}/resource/${fileName}`, {
encoding: "utf-8"
})
return normalizeLineEndings(fileContents)
}

function normalizeLineEndings(str: string): string {
// Normalize all line endings to LF (\n)
return str.replace(/\r\n/g, "\n")
}

test("Download all files from public repo", async () => {
Expand Down Expand Up @@ -315,11 +320,16 @@ test("Download all archive files from public repo", async () => {
fs.existsSync(path.join(downloadSettings.outFilePath, "test-3.txt"))
).toBe(true)

const test4actual = path.join(downloadSettings.outFilePath, "test-4.txt")
expect(fs.existsSync(test4actual)).toBe(true)
expect(fs.readFileSync(test4actual, {encoding: "utf-8"}).toString()).toBe(
readFromFile("assets/archive-example-test-4.txt")
const extractedFilePath = path.join(
downloadSettings.outFilePath,
"test-4.txt"
)
expect(fs.existsSync(extractedFilePath)).toBe(true)

const actualContent = fs.readFileSync(extractedFilePath, {encoding: "utf-8"})
const expectedContent = readFromFile("assets/archive-example-test-4.txt")

expect(normalizeLineEndings(actualContent)).toBe(expectedContent)
}, 10000)

test("Fail when a release with no assets are obtained", async () => {
Expand Down
Loading

0 comments on commit 937fc82

Please sign in to comment.