-
-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathxhr-paths.ts
72 lines (59 loc) · 2.45 KB
/
xhr-paths.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// make sure you import mocha-config before @angular/core
import { assert } from "./test-config";
import { FileSystemResourceLoader } from "nativescript-angular/resource-loader";
import { File } from "tns-core-modules/file-system";
import { NSFileSystem } from "nativescript-angular/file-system/ns-file-system";
class NSFileSystemMock {
public currentApp(): any {
return { path: "/app/dir" };
}
public fileFromPath(path: string): File {
return null;
}
public fileExists(path: string): boolean {
// mycomponent.html always exists
// mycomponent.css is the other file
return path.indexOf("mycomponent.html") >= 0 || path === "/app/dir/mycomponent.css";
}
}
const fsMock = new NSFileSystemMock();
describe("XHR name resolution", () => {
let resourceLoader: FileSystemResourceLoader;
before(() => {
resourceLoader = new FileSystemResourceLoader(new NSFileSystemMock());
});
it("resolves relative paths from app root", () => {
assert.strictEqual("/app/dir/mydir/mycomponent.html", resourceLoader.resolve("mydir/mycomponent.html"));
});
it("resolves double-slashed absolute paths as is", () => {
assert.strictEqual("//app/mydir/mycomponent.html", resourceLoader.resolve("//app/mydir/mycomponent.html"));
});
it("resolves single-slashed absolute paths as is", () => {
assert.strictEqual(
"/data/data/app/mydir/mycomponent.html",
resourceLoader.resolve("/data/data/app/mydir/mycomponent.html"));
});
it("resolves existing CSS file", () => {
assert.strictEqual(
"/app/dir/mycomponent.css",
resourceLoader.resolve("mycomponent.css"));
});
it("resolves non-existing .scss file to existing .css file", () => {
assert.strictEqual(
"/app/dir/mycomponent.css",
resourceLoader.resolve("mycomponent.scss"));
});
it("resolves non-existing .sass file to existing .css file", () => {
assert.strictEqual(
"/app/dir/mycomponent.css",
resourceLoader.resolve("mycomponent.sass"));
});
it("resolves non-existing .less file to existing .css file", () => {
assert.strictEqual(
"/app/dir/mycomponent.css",
resourceLoader.resolve("mycomponent.less"));
});
it("throws for non-existing file that has no fallbacks", () => {
assert.throws(() => resourceLoader.resolve("does-not-exist.css"));
});
});