UNPKG

3.5 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
5 * This code may only be used under the BSD style license found at
6 * http://polymer.github.io/LICENSE.txt
7 * The complete set of authors may be found at
8 * http://polymer.github.io/AUTHORS.txt
9 * The complete set of contributors may be found at
10 * http://polymer.github.io/CONTRIBUTORS.txt
11 * Code distributed by Google as part of the polymer project is also
12 * subject to an additional IP rights grant found at
13 * http://polymer.github.io/PATENTS.txt
14 */
15Object.defineProperty(exports, "__esModule", { value: true });
16const chai_1 = require("chai");
17const path_1 = require("path");
18const path_transformers_1 = require("../path-transformers");
19const WindowsRootPath = 'C:\\Users\\TEST_USER\\TEST_ROOT';
20const MacRootPath = '/Users/TEST_USER/TEST_ROOT';
21const RootPath = path_1.sep === '\\' ? WindowsRootPath : MacRootPath;
22suite('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});
46suite('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//# sourceMappingURL=path-transformers_test.js.map
\No newline at end of file