Skip to content

Commit 937fc82

Browse files
authored
Fix tests on windows, and package bundled js (#710)
* Fix tests on windows, and package bundled js * Fix tests on windows
1 parent 452eec1 commit 937fc82

File tree

3 files changed

+5185
-24578
lines changed

3 files changed

+5185
-24578
lines changed

__tests__/main.test.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as core from "@actions/core"
21
import * as fs from "fs"
32
import * as path from "path"
43
import * as handlers from "typed-rest-client/Handlers"
@@ -109,9 +108,15 @@ afterEach(async () => {
109108
})
110109

111110
function readFromFile(fileName: string): string {
112-
return fs.readFileSync(`${__dirname}/resource/${fileName}`, {
111+
const fileContents = fs.readFileSync(`${__dirname}/resource/${fileName}`, {
113112
encoding: "utf-8"
114113
})
114+
return normalizeLineEndings(fileContents)
115+
}
116+
117+
function normalizeLineEndings(str: string): string {
118+
// Normalize all line endings to LF (\n)
119+
return str.replace(/\r\n/g, "\n")
115120
}
116121

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

318-
const test4actual = path.join(downloadSettings.outFilePath, "test-4.txt")
319-
expect(fs.existsSync(test4actual)).toBe(true)
320-
expect(fs.readFileSync(test4actual, {encoding: "utf-8"}).toString()).toBe(
321-
readFromFile("assets/archive-example-test-4.txt")
323+
const extractedFilePath = path.join(
324+
downloadSettings.outFilePath,
325+
"test-4.txt"
322326
)
327+
expect(fs.existsSync(extractedFilePath)).toBe(true)
328+
329+
const actualContent = fs.readFileSync(extractedFilePath, {encoding: "utf-8"})
330+
const expectedContent = readFromFile("assets/archive-example-test-4.txt")
331+
332+
expect(normalizeLineEndings(actualContent)).toBe(expectedContent)
323333
}, 10000)
324334

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

0 commit comments

Comments
 (0)