embark-area-51/test/template.js

130 lines
8.3 KiB
JavaScript
Raw Normal View History

2018-07-06 08:38:09 +00:00
/*globals describe, it*/
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-07-06 08:38:09 +00:00
describe('TemplateGenerator', function () {
describe('getExternalProject', function () {
let templateGenerator;
before(() => {
templateGenerator = new TemplateGenerator();
});
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-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 () {
it('returns correct info for GitHub URL', function () {
2018-07-06 08:38:09 +00:00
let result = templateGenerator.getExternalProject("http://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");
result = templateGenerator.getExternalProject("https://github.com/embark-framework/embark");
assert.strictEqual(result.url, "https://codeload.github.com/embark-framework/embark/tar.gz/master");
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-09-25 00:28:50 +00:00
result = templateGenerator.getExternalProject("https://github.com/embark-framework/embark#features/branch");
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-09-25 00:28:50 +00:00
it('returns correct info for Bitbucket URL', function () {
let result = templateGenerator.getExternalProject("https://bitbucket.org/embark-framework/embark");
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");
2018-09-25 00:28:50 +00:00
assert.strictEqual(result.browse, "https://bitbucket.org/embark-framework/embark");
result = templateGenerator.getExternalProject("https://bitbucket.org/embark-framework/embark#features/branch");
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-25 00:28:50 +00:00
it('returns correct info for GitLab URL', function () {
let result = templateGenerator.getExternalProject("https://gitlab.com/embark-framework/embark");
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");
result = templateGenerator.getExternalProject("https://gitlab.com/embark-framework/embark#features/branch");
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 () {
it('returns correct info for GitHub shortcut', function () {
let result = templateGenerator.getExternalProject("github:embark-framework/embark");
assert.strictEqual(result.url, "https://codeload.github.com/embark-framework/embark/tar.gz/master");
result = templateGenerator.getExternalProject("embark-framework/embark");
assert.strictEqual(result.url, "https://codeload.github.com/embark-framework/embark/tar.gz/master");
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");
result = templateGenerator.getExternalProject("embark-framework/embark#features/branch");
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-25 00:28:50 +00:00
it('returns correct info for Bitbucket shortcut', function () {
let result = templateGenerator.getExternalProject("bitbucket:embark-framework/embark");
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");
result = templateGenerator.getExternalProject("bitbucket:embark-framework/embark#features/branch");
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-09-25 00:28:50 +00:00
it('returns correct info for GitLab shortcut', function () {
let result = templateGenerator.getExternalProject("gitlab:embark-framework/embark");
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");
result = templateGenerator.getExternalProject("gitlab:embark-framework/embark#features/branch");
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
});
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
});
});