summaryrefslogtreecommitdiffstats
path: root/lib/utils/__tests__
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-12-22 10:18:38 +0100
committerGitHub <noreply@github.com>2016-12-22 10:18:38 +0100
commit194ebc3da9641ff96f083f9d8ab43c2d27944f9a (patch)
treec50988f32ccf18df93ae7ab40be78e9459642818 /lib/utils/__tests__
parent64ccb6b00b4b63fa0e516d4e35351275b34f8c07 (diff)
parent16af264360e48e8a833e9efa9ab8d194574dbc70 (diff)
downloadgitbook-194ebc3da9641ff96f083f9d8ab43c2d27944f9a.zip
gitbook-194ebc3da9641ff96f083f9d8ab43c2d27944f9a.tar.gz
gitbook-194ebc3da9641ff96f083f9d8ab43c2d27944f9a.tar.bz2
Merge pull request #1543 from GitbookIO/dream
React for rendering website with plugins
Diffstat (limited to 'lib/utils/__tests__')
-rw-r--r--lib/utils/__tests__/git.js57
-rw-r--r--lib/utils/__tests__/location.js100
-rw-r--r--lib/utils/__tests__/path.js17
3 files changed, 0 insertions, 174 deletions
diff --git a/lib/utils/__tests__/git.js b/lib/utils/__tests__/git.js
deleted file mode 100644
index abc1ea1..0000000
--- a/lib/utils/__tests__/git.js
+++ /dev/null
@@ -1,57 +0,0 @@
-var path = require('path');
-var os = require('os');
-
-var Git = require('../git');
-
-describe('Git', function() {
-
- describe('URL parsing', function() {
-
- it('should correctly validate git urls', function() {
- // HTTPS
- expect(Git.isUrl('git+https://github.com/Hello/world.git')).toBeTruthy();
-
- // SSH
- expect(Git.isUrl('git+git@github.com:GitbookIO/gitbook.git/directory/README.md#e1594cde2c32e4ff48f6c4eff3d3d461743d74e1')).toBeTruthy();
-
- // Non valid
- expect(Git.isUrl('https://github.com/Hello/world.git')).toBeFalsy();
- expect(Git.isUrl('README.md')).toBeFalsy();
- });
-
- it('should parse HTTPS urls', function() {
- var parts = Git.parseUrl('git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md');
-
- expect(parts.host).toBe('https://gist.github.com/69ea4542e4c8967d2fa7.git');
- expect(parts.ref).toBe(null);
- expect(parts.filepath).toBe('test.md');
- });
-
- it('should parse HTTPS urls with a reference', function() {
- var parts = Git.parseUrl('git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md#1.0.0');
-
- expect(parts.host).toBe('https://gist.github.com/69ea4542e4c8967d2fa7.git');
- expect(parts.ref).toBe('1.0.0');
- expect(parts.filepath).toBe('test.md');
- });
-
- it('should parse SSH urls', function() {
- var parts = Git.parseUrl('git+git@github.com:GitbookIO/gitbook.git/directory/README.md#e1594cde2c32e4ff48f6c4eff3d3d461743d74e1');
-
- expect(parts.host).toBe('git@github.com:GitbookIO/gitbook.git');
- expect(parts.ref).toBe('e1594cde2c32e4ff48f6c4eff3d3d461743d74e1');
- expect(parts.filepath).toBe('directory/README.md');
- });
- });
-
- describe('Cloning and resolving', function() {
- it('should clone an HTTPS url', function() {
- var git = new Git(path.join(os.tmpdir(), 'test-git-'+Date.now()));
- return git.resolve('git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md')
- .then(function(filename) {
- expect(path.extname(filename)).toBe('.md');
- });
- });
- });
-
-});
diff --git a/lib/utils/__tests__/location.js b/lib/utils/__tests__/location.js
deleted file mode 100644
index 822338e..0000000
--- a/lib/utils/__tests__/location.js
+++ /dev/null
@@ -1,100 +0,0 @@
-var LocationUtils = require('../location');
-
-describe('LocationUtils', function() {
- it('should correctly test external location', function() {
- expect(LocationUtils.isExternal('http://google.fr')).toBe(true);
- expect(LocationUtils.isExternal('https://google.fr')).toBe(true);
- expect(LocationUtils.isExternal('test.md')).toBe(false);
- expect(LocationUtils.isExternal('folder/test.md')).toBe(false);
- expect(LocationUtils.isExternal('/folder/test.md')).toBe(false);
- expect(LocationUtils.isExternal('data:image/png')).toBe(false);
- });
-
- it('should correctly test data:uri location', function() {
- expect(LocationUtils.isDataURI('data:image/png')).toBe(true);
- expect(LocationUtils.isDataURI('http://google.fr')).toBe(false);
- expect(LocationUtils.isDataURI('https://google.fr')).toBe(false);
- expect(LocationUtils.isDataURI('test.md')).toBe(false);
- expect(LocationUtils.isDataURI('data.md')).toBe(false);
- });
-
- it('should correctly detect anchor location', function() {
- expect(LocationUtils.isAnchor('#test')).toBe(true);
- expect(LocationUtils.isAnchor(' #test')).toBe(true);
- expect(LocationUtils.isAnchor('https://google.fr#test')).toBe(false);
- expect(LocationUtils.isAnchor('test.md#test')).toBe(false);
- });
-
- describe('.relative', function() {
- it('should resolve to a relative path (same folder)', function() {
- expect(LocationUtils.relative('links/', 'links/test.md')).toBe('test.md');
- });
-
- it('should resolve to a relative path (parent folder)', function() {
- expect(LocationUtils.relative('links/', 'test.md')).toBe('../test.md');
- });
-
- it('should resolve to a relative path (child folder)', function() {
- expect(LocationUtils.relative('links/', 'links/hello/test.md')).toBe('hello/test.md');
- });
- });
-
- describe('.flatten', function() {
- it('should remove leading slash', function() {
- expect(LocationUtils.flatten('/test.md')).toBe('test.md');
- expect(LocationUtils.flatten('/hello/cool.md')).toBe('hello/cool.md');
- });
-
- it('should remove leading slashes', function() {
- expect(LocationUtils.flatten('///test.md')).toBe('test.md');
- });
-
- it('should not break paths', function() {
- expect(LocationUtils.flatten('hello/cool.md')).toBe('hello/cool.md');
- });
- });
-
- describe('.toAbsolute', function() {
- it('should correctly transform as absolute', function() {
- expect(LocationUtils.toAbsolute('http://google.fr')).toBe('http://google.fr');
- expect(LocationUtils.toAbsolute('test.md', './', './')).toBe('test.md');
- expect(LocationUtils.toAbsolute('folder/test.md', './', './')).toBe('folder/test.md');
- });
-
- it('should correctly handle windows path', function() {
- expect(LocationUtils.toAbsolute('folder\\test.md', './', './')).toBe('folder/test.md');
- });
-
- it('should correctly handle absolute path', function() {
- expect(LocationUtils.toAbsolute('/test.md', './', './')).toBe('test.md');
- expect(LocationUtils.toAbsolute('/test.md', 'test', 'test')).toBe('../test.md');
- expect(LocationUtils.toAbsolute('/sub/test.md', 'test', 'test')).toBe('../sub/test.md');
- expect(LocationUtils.toAbsolute('/test.png', 'folder', '')).toBe('test.png');
- });
-
- it('should correctly handle absolute path (windows)', function() {
- expect(LocationUtils.toAbsolute('\\test.png', 'folder', '')).toBe('test.png');
- });
-
- it('should resolve path starting by "/" in root directory', function() {
- expect(
- LocationUtils.toAbsolute('/test/hello.md', './', './')
- ).toBe('test/hello.md');
- });
-
- it('should resolve path starting by "/" in child directory', function() {
- expect(
- LocationUtils.toAbsolute('/test/hello.md', './hello', './')
- ).toBe('test/hello.md');
- });
-
- it('should resolve path starting by "/" in child directory, with same output directory', function() {
- expect(
- LocationUtils.toAbsolute('/test/hello.md', './hello', './hello')
- ).toBe('../test/hello.md');
- });
- });
-
-});
-
-
diff --git a/lib/utils/__tests__/path.js b/lib/utils/__tests__/path.js
deleted file mode 100644
index 22bb016..0000000
--- a/lib/utils/__tests__/path.js
+++ /dev/null
@@ -1,17 +0,0 @@
-var path = require('path');
-
-describe('Paths', function() {
- var PathUtils = require('..//path');
-
- describe('setExtension', function() {
- it('should correctly change extension of filename', function() {
- expect(PathUtils.setExtension('test.md', '.html')).toBe('test.html');
- expect(PathUtils.setExtension('test.md', '.json')).toBe('test.json');
- });
-
- it('should correctly change extension of path', function() {
- expect(PathUtils.setExtension('hello/test.md', '.html')).toBe(path.normalize('hello/test.html'));
- expect(PathUtils.setExtension('hello/test.md', '.json')).toBe(path.normalize('hello/test.json'));
- });
- });
-});