Skip to content

Commit

Permalink
Improves coverage (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBuchholz committed Oct 14, 2017
1 parent 7f510e0 commit f493b05
Showing 1 changed file with 89 additions and 3 deletions.
92 changes: 89 additions & 3 deletions test/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ describe("require", function () {

});

describe("gpf.require.configure", function () {

it("fails on invalid options", function () {
var exceptionCaught;
try {
gpf.require.configure({
unknown: true
});
} catch (e) {
exceptionCaught = e;
}
assert(exceptionCaught instanceof gpf.Error.InvalidRequireConfigureOption);
});

});

describe("gpf.require.define", function () {

function validateData (data) {
Expand Down Expand Up @@ -60,7 +76,7 @@ describe("require", function () {
});
});

it("supports CommonJS format", function (done) {
it("supports CommonJS format (static requires)", function (done) {
gpf.require.define({
commonjs: "commonjs.js"
}, function (require) {
Expand All @@ -73,6 +89,36 @@ describe("require", function () {
});
});

it("doesn't supports CommonJS format with static and dynamic requires", function (done) {
gpf.require.define({
commonjs: "mixed_commonjs.js"
}).then(function () {
done(new Error("Should not happen"));
}, function (reason) {
try {
assert(reason instanceof gpf.Error.NoCommonJSDynamicRequire);
done();
} catch (e) {
done(e);
}
});
});

it("doesn't supports CommonJS format with only dynamic requires", function (done) {
gpf.require.define({
commonjs: "dynamic_commonjs.js"
}).then(function () {
done(new Error("Should not happen"));
}, function (reason) {
try {
assert(reason instanceof gpf.Error.NoCommonJSDynamicRequire);
done();
} catch (e) {
done(e);
}
});
});

it("supports AMD format (named with factory)", function (done) {
gpf.require.define({
amd: "amd.js"
Expand All @@ -86,13 +132,27 @@ describe("require", function () {
});
});

it("supports AMD format (anonymous static)", function (done) {
it("supports AMD format (no name)", function (done) {
gpf.require.define({
amd: "anonymous_amd.js"
}, function (require) {
try {
validateModule(require.amd, "amd", false);
assert("anonymous" === require.amd.name);
assert("" === require.amd.name);
done();
} catch (e) {
done(e);
}
});
});

it("supports AMD format (anonymous static)", function (done) {
gpf.require.define({
amd: "static_amd.js"
}, function (require) {
try {
validateModule(require.amd, "amd", false);
assert("static" === require.amd.name);
done();
} catch (e) {
done(e);
Expand All @@ -113,6 +173,19 @@ describe("require", function () {
});
});

it("supports GPF modules without constant value", function (done) {
gpf.require.define({
constants: "constants.js"
}, function (require) {
try {
assert(require.constants.hello === "World!");
done();
} catch (e) {
done(e);
}
});
});

it("supports JavaScript file (no result)", function (done) {
gpf.context().test = {};
gpf.require.define({
Expand All @@ -130,6 +203,19 @@ describe("require", function () {
});
});

it("supports text file (no processor)", function (done) {
gpf.require.define({
text: "../data/folder/hello world.txt"
}, function (require) {
try {
assert(require.text === "hello world\n");
done();
} catch (e) {
done(e);
}
});
});

});

describe("Recursive loading", function () {
Expand Down

0 comments on commit f493b05

Please sign in to comment.