2017-12-08 04:33:43 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const expect = require("chai").expect;
|
|
|
|
const os = require("os");
|
|
|
|
const Helper = require("../../src/helper");
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
describe("Helper", function () {
|
|
|
|
describe("#expandHome", function () {
|
|
|
|
it("should correctly expand a Unix path", function () {
|
2019-07-17 09:33:59 +00:00
|
|
|
expect([`${os.homedir()}/tmp`, `${os.homedir()}\\tmp`]).to.include(
|
|
|
|
Helper.expandHome("~/tmp")
|
|
|
|
);
|
2017-12-08 04:33:43 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should correctly expand a Windows path", function () {
|
2017-12-08 04:33:43 +00:00
|
|
|
expect(Helper.expandHome("~\\tmp")).to.equal(`${os.homedir()}\\tmp`);
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should correctly expand when not given a specific path", function () {
|
2017-12-08 04:33:43 +00:00
|
|
|
expect(Helper.expandHome("~")).to.equal(os.homedir());
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should not expand paths not starting with tilde", function () {
|
2019-08-14 09:01:01 +00:00
|
|
|
expect(Helper.expandHome("/tmp")).to.match(/^\/tmp|[a-zA-Z]:\\{1,2}tmp$/);
|
2017-12-08 04:33:43 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should not expand a tilde in the middle of a string", function () {
|
2019-08-14 09:01:01 +00:00
|
|
|
expect(Helper.expandHome("/tmp/~foo")).to.match(
|
|
|
|
/^\/tmp\/~foo|[a-zA-Z]:\\{1,2}?tmp\\{1,2}~foo$/
|
|
|
|
);
|
2017-12-08 04:33:43 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should return an empty string when given an empty string", function () {
|
2017-12-08 04:33:43 +00:00
|
|
|
expect(Helper.expandHome("")).to.equal("");
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should return an empty string when given undefined", function () {
|
2017-12-08 04:33:43 +00:00
|
|
|
expect(Helper.expandHome(undefined)).to.equal("");
|
|
|
|
});
|
|
|
|
});
|
2018-04-15 22:19:25 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
describe("#getVersion()", function () {
|
2018-04-15 22:19:25 +00:00
|
|
|
const version = Helper.getVersion();
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should mention it is served from source code", function () {
|
2018-04-15 22:19:25 +00:00
|
|
|
expect(version).to.include("source");
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should include a short Git SHA", function () {
|
2018-04-15 22:19:25 +00:00
|
|
|
expect(version).to.match(/\([0-9a-f]{7,11} /);
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should include a valid semver version", function () {
|
2018-04-15 22:19:25 +00:00
|
|
|
expect(version).to.match(/v[0-9]+\.[0-9]+\.[0-9]+/);
|
|
|
|
});
|
|
|
|
});
|
2017-12-08 04:33:43 +00:00
|
|
|
});
|