Skip to content

Commit

Permalink
WIP (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBuchholz committed Oct 4, 2017
1 parent 196fe9c commit 861f730
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions test/require.js
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);
}
});
});

});

});

0 comments on commit 861f730

Please sign in to comment.