1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | const chai_1 = require("chai");
|
17 | const path_1 = require("path");
|
18 | const path_transformers_1 = require("../path-transformers");
|
19 | const WindowsRootPath = 'C:\\Users\\TEST_USER\\TEST_ROOT';
|
20 | const MacRootPath = '/Users/TEST_USER/TEST_ROOT';
|
21 | const RootPath = path_1.sep === '\\' ? WindowsRootPath : MacRootPath;
|
22 | suite('pathFromUrl()', () => {
|
23 | test('creates a filesystem path using the platform separators', () => {
|
24 | const otherSeparator = path_1.sep === '/' ? '\\' : '/';
|
25 | const path = path_transformers_1.pathFromUrl(RootPath, '/some/url/pathname');
|
26 | chai_1.assert.include(path, path_1.sep);
|
27 | chai_1.assert.notInclude(path, otherSeparator);
|
28 | });
|
29 | test('returns a path if url is absolute', () => {
|
30 | const path = path_transformers_1.pathFromUrl(RootPath, '/absolute/path');
|
31 | chai_1.assert.equal(path, path_1.join(RootPath, 'absolute', 'path'));
|
32 | });
|
33 | test('returns a path if url relative', () => {
|
34 | const path = path_transformers_1.pathFromUrl(RootPath, 'relative/path');
|
35 | chai_1.assert.equal(path, path_1.join(RootPath, 'relative', 'path'));
|
36 | });
|
37 | test('will not go outside the root path', () => {
|
38 | const path = path_transformers_1.pathFromUrl(RootPath, '../../../still/../root/path');
|
39 | chai_1.assert.equal(path, path_1.join(RootPath, 'root', 'path'));
|
40 | });
|
41 | test('will decode URI percent encoded characters', () => {
|
42 | const path = path_transformers_1.pathFromUrl(RootPath, '/%40foo/spaced%20out');
|
43 | chai_1.assert.equal(path, path_1.join(RootPath, '/@foo/spaced out'));
|
44 | });
|
45 | });
|
46 | suite('urlFromPath()', () => {
|
47 | test('throws error when path is not in root', () => {
|
48 | chai_1.assert.throws(() => {
|
49 | path_transformers_1.urlFromPath('/this/is/a/path', '/some/other/path/shop-app.html');
|
50 | });
|
51 | chai_1.assert.throws(() => {
|
52 | path_transformers_1.urlFromPath('/the/path', '/the/pathologist/index.html');
|
53 | });
|
54 | });
|
55 | test('creates a URL path relative to root', () => {
|
56 | const shortPath = path_transformers_1.urlFromPath(RootPath, path_1.join(RootPath, 'shop-app.html'));
|
57 | chai_1.assert.equal(shortPath, 'shop-app.html');
|
58 | const medPath = path_transformers_1.urlFromPath(RootPath, path_1.join(RootPath, 'src', 'shop-app.html'));
|
59 | chai_1.assert.equal(medPath, 'src/shop-app.html');
|
60 | const longPath = path_transformers_1.urlFromPath(RootPath, path_1.join(RootPath, 'bower_components', 'app-layout', 'docs.html'));
|
61 | chai_1.assert.equal(longPath, 'bower_components/app-layout/docs.html');
|
62 | });
|
63 | test('will properly encode URL-unfriendly characters like spaces', () => {
|
64 | const url = path_transformers_1.urlFromPath(RootPath, path_1.join(RootPath, 'spaced out'));
|
65 | chai_1.assert.equal(url, 'spaced%20out');
|
66 | });
|
67 | });
|
68 |
|
\ | No newline at end of file |