generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1 Allow for multiple artifacts
- Loading branch information
Showing
17 changed files
with
370 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Artifact } from "../src/Artifact"; | ||
|
||
const fileContents = Buffer.from('artful facts', 'utf-8') | ||
const contentLength = 42 | ||
|
||
jest.mock('fs', () => { | ||
return { | ||
readFileSync: () => fileContents, | ||
statSync: () => { return { size: contentLength } } | ||
}; | ||
}) | ||
|
||
describe("Artifact", () => { | ||
it('defaults contentType to raw', () => { | ||
const artifact = new Artifact('') | ||
expect(artifact.contentType).toBe('raw') | ||
}) | ||
|
||
it('generates name from path', () => { | ||
const artifact = new Artifact('some/artifact') | ||
expect(artifact.name).toBe('artifact') | ||
}) | ||
|
||
it('provides contentLength', () => { | ||
const artifact = new Artifact('some/artifact') | ||
expect(artifact.contentLength).toBe(contentLength) | ||
}) | ||
|
||
it('provides path', () => { | ||
const artifact = new Artifact('some/artifact') | ||
expect(artifact.path).toBe('some/artifact') | ||
}) | ||
|
||
it('reads artifact', () => { | ||
const artifact = new Artifact('some/artifact') | ||
expect(artifact.readFile()).toBe(fileContents) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { FileArtifactGlobber } from "../src/ArtifactGlobber" | ||
import { Globber } from "../src/Globber"; | ||
import { Artifact } from "../src/Artifact"; | ||
|
||
const contentType = "raw" | ||
const globResults = ["file1", "file2"] | ||
|
||
describe("ArtifactGlobber", () => { | ||
it("globs simple path", () => { | ||
const globber = createArtifactGlobber() | ||
|
||
const expectedArtifacts = | ||
globResults.map((path) => new Artifact(path, contentType)) | ||
|
||
expect(globber.globArtifactString('path', 'raw')) | ||
.toEqual(expectedArtifacts) | ||
}) | ||
|
||
it("splits multiple paths", () => { | ||
const globber = createArtifactGlobber() | ||
|
||
const expectedArtifacts = | ||
globResults | ||
.concat(globResults) | ||
.map((path) => new Artifact(path, contentType)) | ||
|
||
expect(globber.globArtifactString('path1,path2', 'raw')) | ||
.toEqual(expectedArtifacts) | ||
}) | ||
|
||
function createArtifactGlobber(): FileArtifactGlobber { | ||
const MockGlobber = jest.fn<Globber, any>(() => { | ||
return { | ||
glob: () => globResults | ||
} | ||
}) | ||
return new FileArtifactGlobber(new MockGlobber()) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Artifact } from "../src/Artifact" | ||
import { GithubArtifactUploader } from "../src/ArtifactUploader" | ||
import { Releases } from "../src/Releases"; | ||
|
||
const artifacts = [ | ||
new Artifact('a/art1'), | ||
new Artifact('b/art2') | ||
] | ||
const fileContents = Buffer.from('artful facts', 'utf-8') | ||
const contentLength = 42 | ||
const uploadMock = jest.fn() | ||
const url = 'http://api.example.com' | ||
|
||
jest.mock('fs', () => { | ||
return { | ||
readFileSync: () => fileContents, | ||
statSync: () => { return { size: contentLength } } | ||
}; | ||
}) | ||
|
||
describe('ArtifactUploader', () => { | ||
it('uploads artifacts', () => { | ||
const uploader = createUploader() | ||
|
||
uploader.uploadArtifacts(artifacts, url) | ||
|
||
expect(uploadMock).toBeCalledTimes(2) | ||
expect(uploadMock) | ||
.toBeCalledWith(url, contentLength, 'raw', fileContents, 'art1') | ||
expect(uploadMock) | ||
.toBeCalledWith(url, contentLength, 'raw', fileContents, 'art2') | ||
}) | ||
|
||
function createUploader(): GithubArtifactUploader { | ||
const MockReleases = jest.fn<Releases, any>(() => { | ||
return { | ||
create: jest.fn(), | ||
uploadArtifact: uploadMock | ||
} | ||
}) | ||
return new GithubArtifactUploader(new MockReleases()) | ||
} | ||
}); |
Oops, something went wrong.