-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
196fe9c
commit 861f730
Showing
1 changed file
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
"use strict"; | ||
|
||
describe("require", function () { | ||
|
||
before(function () { | ||
gpf.require.configure({ | ||
base: "/test/require" | ||
}); | ||
}); | ||
|
||
describe("gpf.require.resolve", function () { | ||
|
||
it("resolves relative path", function () { | ||
assert(gpf.require.resolve("file.js") === "/test/require/file.js"); | ||
}); | ||
|
||
it("resolves relative path with folders", function () { | ||
assert(gpf.require.resolve("folder/file.js") === "/test/require/folder/file.js"); | ||
}); | ||
|
||
it("resolves relative path with folders", function () { | ||
assert(gpf.require.resolve("../file.js") === "/test/file.js"); | ||
}); | ||
|
||
}); | ||
|
||
describe("gpf.require", function () { | ||
|
||
it("loads JSON file as an object", function (done) { | ||
gpf.require({ | ||
data: "data.json" | ||
}, function (require) { | ||
try { | ||
assert("object" === typeof require.data); | ||
assert("value" === require.data.member); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
|
||
it("handles NodeJS modules", function (done) { | ||
gpf.require({ | ||
node: "nodejs.js" | ||
}, function (require) { | ||
try { | ||
assert("object" === typeof require.node); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
|
||
it("handles gpf.require modules", function (done) { | ||
gpf.require({ | ||
test: "require.js" | ||
}, function (require) { | ||
try { | ||
assert("object" === typeof require.test); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
|
||
it("caches loaded parts", function (done) { | ||
gpf.require({ | ||
data: "data.json" | ||
}, function (require) { | ||
require.data.additional = true; | ||
gpf.require({ | ||
data2: "data.json" | ||
}, function (cachedRequire) { | ||
try { | ||
assert(true === cachedRequire.data2.additional); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
describe("gpf.require.cache", function () { | ||
|
||
it("allows injection", function (done) { | ||
var fakeData = { | ||
member: "value2" | ||
}; | ||
gpf.require.cache(gpf.require.resolve("data.json"), fakeData); | ||
gpf.require({ | ||
data: "data.json" | ||
}, function (require) { | ||
try { | ||
assert(fakeData === require.data); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); |