2018-10-31 20:48:06 +00:00
|
|
|
/*globals describe, it, before*/
|
2018-07-06 08:38:09 +00:00
|
|
|
const assert = require('assert');
|
2018-08-08 16:37:22 +00:00
|
|
|
const TemplateGenerator = require('../lib/utils/template_generator');
|
2018-10-10 16:59:05 +00:00
|
|
|
const semver = require('semver');
|
2018-10-31 20:48:06 +00:00
|
|
|
const sinon = require('sinon');
|
|
|
|
const request = require('request');
|
2018-07-06 08:38:09 +00:00
|
|
|
|
|
|
|
describe('TemplateGenerator', function () {
|
|
|
|
describe('getExternalProject', function () {
|
|
|
|
let templateGenerator;
|
|
|
|
|
|
|
|
before(() => {
|
|
|
|
templateGenerator = new TemplateGenerator();
|
2018-10-31 20:48:06 +00:00
|
|
|
sinon.stub(request, 'get').callsFake((options, callback) => {
|
|
|
|
callback(null, {}, {default_branch: 'master'});
|
|
|
|
});
|
2018-07-06 08:38:09 +00:00
|
|
|
});
|
|
|
|
|
2018-09-25 00:28:50 +00:00
|
|
|
describe('with named template', function () {
|
2018-07-06 08:38:09 +00:00
|
|
|
|
2018-09-25 00:28:50 +00:00
|
|
|
it('returns correct info for named template', function () {
|
|
|
|
let result = templateGenerator.getExternalProject("typescript");
|
2018-10-10 16:59:05 +00:00
|
|
|
let embarkVersion = semver(require('../package.json').version);
|
|
|
|
let branch = `${embarkVersion.major}.${embarkVersion.minor}`;
|
|
|
|
assert.strictEqual(result.url, `https://codeload.github.com/embark-framework/embark-typescript-template/tar.gz/${branch}`);
|
|
|
|
assert.strictEqual(result.filePath.replace(/\\/g,'/'), `.embark/templates/embark-framework/embark-typescript-template/${branch}/archive.zip`);
|
|
|
|
assert.strictEqual(result.browse, `https://github.com/embark-framework/embark-typescript-template/tree/${branch}`);
|
2018-09-05 21:59:42 +00:00
|
|
|
|
2018-09-25 00:28:50 +00:00
|
|
|
result = templateGenerator.getExternalProject("typescript#features/branch");
|
|
|
|
assert.strictEqual(result.url, "https://codeload.github.com/embark-framework/embark-typescript-template/tar.gz/features%2Fbranch");
|
|
|
|
assert.strictEqual(result.filePath.replace(/\\/g,'/'), ".embark/templates/embark-framework/embark-typescript-template/features/branch/archive.zip");
|
|
|
|
assert.strictEqual(result.browse, "https://github.com/embark-framework/embark-typescript-template/tree/features/branch");
|
2018-07-06 08:38:09 +00:00
|
|
|
});
|
|
|
|
|
2018-09-25 00:28:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('with git host URL', function () {
|
|
|
|
|
2018-10-31 20:48:06 +00:00
|
|
|
it('returns correct info for GitHub URL', async function () {
|
|
|
|
let result = await templateGenerator.getExternalProject("https://github.com/embark-framework/embark");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.url, "https://codeload.github.com/embark-framework/embark/tar.gz/master");
|
|
|
|
|
2018-10-31 20:48:06 +00:00
|
|
|
result = await templateGenerator.getExternalProject("https://github.com/embark-framework/embark");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.url, "https://codeload.github.com/embark-framework/embark/tar.gz/master");
|
2018-09-05 21:59:42 +00:00
|
|
|
assert.strictEqual(result.filePath.replace(/\\/g,'/'), ".embark/templates/embark-framework/embark/master/archive.zip");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.browse, "https://github.com/embark-framework/embark");
|
2018-07-06 08:38:09 +00:00
|
|
|
|
2018-10-31 20:48:06 +00:00
|
|
|
result = await templateGenerator.getExternalProject("https://github.com/embark-framework/embark#features/branch");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.url, "https://codeload.github.com/embark-framework/embark/tar.gz/features%2Fbranch");
|
|
|
|
assert.strictEqual(result.filePath.replace(/\\/g,'/'), ".embark/templates/embark-framework/embark/features/branch/archive.zip");
|
|
|
|
assert.strictEqual(result.browse, "https://github.com/embark-framework/embark/tree/features/branch");
|
2018-07-06 08:38:09 +00:00
|
|
|
});
|
|
|
|
|
2018-10-31 20:48:06 +00:00
|
|
|
it('returns correct info for Bitbucket URL', async function () {
|
|
|
|
let result = await templateGenerator.getExternalProject("https://bitbucket.org/embark-framework/embark");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.url, "https://bitbucket.org/embark-framework/embark/get/master.tar.gz");
|
2018-09-05 21:59:42 +00:00
|
|
|
assert.strictEqual(result.filePath.replace(/\\/g,'/'), ".embark/templates/embark-framework/embark/master/archive.zip");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.browse, "https://bitbucket.org/embark-framework/embark");
|
|
|
|
|
2018-10-31 20:48:06 +00:00
|
|
|
result = await templateGenerator.getExternalProject("https://bitbucket.org/embark-framework/embark#features/branch");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.url, "https://bitbucket.org/embark-framework/embark/get/features%2Fbranch.tar.gz");
|
|
|
|
assert.strictEqual(result.filePath.replace(/\\/g,'/'), ".embark/templates/embark-framework/embark/features/branch/archive.zip");
|
|
|
|
assert.strictEqual(result.browse, "https://bitbucket.org/embark-framework/embark/src/features/branch");
|
2018-09-05 21:59:42 +00:00
|
|
|
});
|
|
|
|
|
2018-10-31 20:48:06 +00:00
|
|
|
it('returns correct info for GitLab URL', async function () {
|
|
|
|
let result = await templateGenerator.getExternalProject("https://gitlab.com/embark-framework/embark");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.url, "https://gitlab.com/embark-framework/embark/repository/archive.tar.gz?ref=master");
|
|
|
|
assert.strictEqual(result.filePath.replace(/\\/g,'/'), ".embark/templates/embark-framework/embark/master/archive.zip");
|
|
|
|
assert.strictEqual(result.browse, "https://gitlab.com/embark-framework/embark");
|
|
|
|
|
2018-10-31 20:48:06 +00:00
|
|
|
result = await templateGenerator.getExternalProject("https://gitlab.com/embark-framework/embark#features/branch");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.url, "https://gitlab.com/embark-framework/embark/repository/archive.tar.gz?ref=features%2Fbranch");
|
|
|
|
assert.strictEqual(result.filePath.replace(/\\/g,'/'), ".embark/templates/embark-framework/embark/features/branch/archive.zip");
|
|
|
|
assert.strictEqual(result.browse, "https://gitlab.com/embark-framework/embark/tree/features/branch");
|
2018-07-06 08:38:09 +00:00
|
|
|
});
|
|
|
|
|
2018-09-25 00:28:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('with git host shortcut', function () {
|
|
|
|
|
2018-10-31 20:48:06 +00:00
|
|
|
it('returns correct info for GitHub shortcut', async function () {
|
|
|
|
let result = await templateGenerator.getExternalProject("github:embark-framework/embark");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.url, "https://codeload.github.com/embark-framework/embark/tar.gz/master");
|
|
|
|
|
2018-10-31 20:48:06 +00:00
|
|
|
result = await templateGenerator.getExternalProject("embark-framework/embark");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.url, "https://codeload.github.com/embark-framework/embark/tar.gz/master");
|
2018-09-05 21:59:42 +00:00
|
|
|
assert.strictEqual(result.filePath.replace(/\\/g,'/'), ".embark/templates/embark-framework/embark/master/archive.zip");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.browse, "https://github.com/embark-framework/embark");
|
|
|
|
|
2018-10-31 20:48:06 +00:00
|
|
|
result = await templateGenerator.getExternalProject("embark-framework/embark#features/branch");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.url, "https://codeload.github.com/embark-framework/embark/tar.gz/features%2Fbranch");
|
|
|
|
assert.strictEqual(result.filePath.replace(/\\/g,'/'), ".embark/templates/embark-framework/embark/features/branch/archive.zip");
|
|
|
|
assert.strictEqual(result.browse, "https://github.com/embark-framework/embark/tree/features/branch");
|
2018-09-05 21:59:42 +00:00
|
|
|
});
|
|
|
|
|
2018-10-31 20:48:06 +00:00
|
|
|
it('returns correct info for Bitbucket shortcut', async function () {
|
|
|
|
let result = await templateGenerator.getExternalProject("bitbucket:embark-framework/embark");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.url, "https://bitbucket.org/embark-framework/embark/get/master.tar.gz");
|
|
|
|
assert.strictEqual(result.filePath.replace(/\\/g,'/'), ".embark/templates/embark-framework/embark/master/archive.zip");
|
|
|
|
assert.strictEqual(result.browse, "https://bitbucket.org/embark-framework/embark");
|
|
|
|
|
2018-10-31 20:48:06 +00:00
|
|
|
result = await templateGenerator.getExternalProject("bitbucket:embark-framework/embark#features/branch");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.url, "https://bitbucket.org/embark-framework/embark/get/features%2Fbranch.tar.gz");
|
|
|
|
assert.strictEqual(result.filePath.replace(/\\/g,'/'), ".embark/templates/embark-framework/embark/features/branch/archive.zip");
|
|
|
|
assert.strictEqual(result.browse, "https://bitbucket.org/embark-framework/embark/src/features/branch");
|
2018-07-06 08:38:09 +00:00
|
|
|
});
|
|
|
|
|
2018-10-31 20:48:06 +00:00
|
|
|
it('returns correct info for GitLab shortcut', async function () {
|
|
|
|
let result = await templateGenerator.getExternalProject("gitlab:embark-framework/embark");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.url, "https://gitlab.com/embark-framework/embark/repository/archive.tar.gz?ref=master");
|
|
|
|
assert.strictEqual(result.filePath.replace(/\\/g,'/'), ".embark/templates/embark-framework/embark/master/archive.zip");
|
|
|
|
assert.strictEqual(result.browse, "https://gitlab.com/embark-framework/embark");
|
|
|
|
|
2018-10-31 20:48:06 +00:00
|
|
|
result = await templateGenerator.getExternalProject("gitlab:embark-framework/embark#features/branch");
|
2018-09-25 00:28:50 +00:00
|
|
|
assert.strictEqual(result.url, "https://gitlab.com/embark-framework/embark/repository/archive.tar.gz?ref=features%2Fbranch");
|
|
|
|
assert.strictEqual(result.filePath.replace(/\\/g,'/'), ".embark/templates/embark-framework/embark/features/branch/archive.zip");
|
|
|
|
assert.strictEqual(result.browse, "https://gitlab.com/embark-framework/embark/tree/features/branch");
|
2018-07-06 08:38:09 +00:00
|
|
|
});
|
2018-09-25 00:28:50 +00:00
|
|
|
|
2018-07-06 08:38:09 +00:00
|
|
|
});
|
|
|
|
|
2018-09-25 14:20:59 +00:00
|
|
|
describe('with unsupported template specifier', function () {
|
|
|
|
|
|
|
|
it('raises an exception', function () {
|
|
|
|
assert.throws(() => templateGenerator.getExternalProject("bad://format"), /Unsupported/);
|
|
|
|
assert.throws(() => templateGenerator.getExternalProject("bad://format#/also/bad"), /Unsupported/);
|
|
|
|
assert.throws(() => templateGenerator.getExternalProject(/force an error/), Error);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-07-06 08:38:09 +00:00
|
|
|
});
|
|
|
|
});
|