-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from NodeSecure/prepublish-enhancement
Prepublish enhancement
- Loading branch information
Showing
6 changed files
with
183 additions
and
146 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
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,79 @@ | ||
// Import Node.js Dependencies | ||
import path from "node:path"; | ||
import os from "node:os"; | ||
import fs from "node:fs"; | ||
import assert from "node:assert"; | ||
import { describe, after, test, before } from "node:test"; | ||
|
||
// Import Third-party Dependencies | ||
import is from "@slimio/is"; | ||
|
||
// Import Internal Dependencies | ||
import * as github from "../src/index.js"; | ||
|
||
describe("download", () => { | ||
let tempDownloadDir: string; | ||
|
||
before(() => { | ||
tempDownloadDir = fs.mkdtempSync( | ||
path.join(os.tmpdir(), "nsecure-gitlab-") | ||
); | ||
}); | ||
|
||
after(() => { | ||
fs.rmSync(tempDownloadDir, { recursive: true, force: true }); | ||
}); | ||
|
||
test("should export as an asyncFunction", () => { | ||
assert.ok(is.func(github.download)); | ||
assert.ok(is.asyncFunction(github.download)); | ||
}); | ||
|
||
test("download must throw: repository must be a string!", () => { | ||
assert.rejects( | ||
async() => await github.download(10 as any), | ||
{ | ||
name: "TypeError", | ||
message: "repository must be a string!" | ||
} | ||
); | ||
}); | ||
|
||
test("download public repository (without extraction)", async() => { | ||
const { location, repository, organization } = await github.download("SlimIO.Config", { | ||
dest: tempDownloadDir, | ||
branch: "master" | ||
}); | ||
assert.strictEqual(repository, "Config"); | ||
assert.strictEqual(organization, "SlimIO"); | ||
assert.strictEqual(location, path.join(tempDownloadDir, "Config-master.tar.gz")); | ||
|
||
fs.accessSync(location); | ||
fs.unlinkSync(location); | ||
}); | ||
|
||
test("download public repository (at current working dir)", async() => { | ||
const { location } = await github.download("NodeSecure.utils"); | ||
assert.strictEqual( | ||
location, | ||
path.join(process.cwd(), "utils-main.tar.gz") | ||
); | ||
|
||
fs.accessSync(location); | ||
fs.unlinkSync(location); | ||
}); | ||
|
||
test("download private repository (without extraction)", async() => { | ||
const { location } = await github.download("SlimIO.Core", { | ||
dest: tempDownloadDir, | ||
branch: "master" | ||
}); | ||
assert.strictEqual( | ||
location, | ||
path.join(tempDownloadDir, "Core-master.tar.gz") | ||
); | ||
|
||
fs.accessSync(location); | ||
fs.unlinkSync(location); | ||
}); | ||
}); |
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,69 @@ | ||
// Import Node.js Dependencies | ||
import path from "node:path"; | ||
import os from "node:os"; | ||
import fs from "node:fs"; | ||
import assert from "node:assert"; | ||
import { describe, after, test, before } from "node:test"; | ||
|
||
// Import Third-party Dependencies | ||
import is from "@slimio/is"; | ||
|
||
// Import Internal Dependencies | ||
import * as github from "../src/index.js"; | ||
|
||
describe("downloadAndExtract", () => { | ||
let tempDownloadDir: string; | ||
|
||
before(() => { | ||
tempDownloadDir = fs.mkdtempSync( | ||
path.join(os.tmpdir(), "nsecure-gitlab-") | ||
); | ||
}); | ||
|
||
after(() => { | ||
fs.rmSync(tempDownloadDir, { recursive: true, force: true }); | ||
}); | ||
|
||
test("should export as an asyncFunction", () => { | ||
assert.ok(is.func(github.downloadAndExtract)); | ||
assert.ok(is.asyncFunction(github.downloadAndExtract)); | ||
}); | ||
|
||
test("download public repository (with extraction)", async() => { | ||
const result = await github.downloadAndExtract("SlimIO.is", { | ||
dest: tempDownloadDir, | ||
branch: "master" | ||
}); | ||
|
||
assert.strictEqual( | ||
result.location, | ||
path.join(tempDownloadDir, "is-master") | ||
); | ||
assert.ok(fs.statSync(result.location).isDirectory()); | ||
assert.throws( | ||
() => fs.accessSync(path.join(tempDownloadDir, "is-master.tar.gz")), | ||
{ | ||
name: "Error", | ||
code: "ENOENT", | ||
message: /no such file or directory/ | ||
} | ||
); | ||
}); | ||
|
||
test("download public repository (with extraction and removeArchive disabled)", async() => { | ||
const { location } = await github.downloadAndExtract("SlimIO.Safe-emitter", { | ||
dest: tempDownloadDir, | ||
branch: "master", | ||
removeArchive: false | ||
}); | ||
|
||
fs.accessSync( | ||
path.join(tempDownloadDir, "Safe-emitter-master.tar.gz") | ||
); | ||
assert.strictEqual( | ||
location, | ||
path.join(tempDownloadDir, "Safe-emitter-master") | ||
); | ||
assert.ok(fs.statSync(location).isDirectory()); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.