Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

env.getEnvironment return {} in standalone mode. #101

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 env.js
@@ -5,23 +5,22 @@ define(function () {
var env = {};

env.getEnvironment = function (callback) {
var sugar;

if (window.top.sugar) {
sugar = window.top.sugar;
} else {
sugar = {};
window.top.sugar = sugar;
}

if (sugar.environment) {
setTimeout(function () {
callback(null, sugar.environment);
}, 0);
if (env.isStandalone()) {
callback(null, {});
} else {
sugar.onEnvironmentSet = function () {
callback(null, sugar.environment);
var environmentCallback = function () {
callback(null, window.top.sugar.environment);
};
if (window.top.sugar) {
setTimeout(function () {
environmentCallback();
}, 0);
} else {
window.top.sugar = {};
window.top.sugar.onEnvironmentSet = function () {
environmentCallback();
};
}
}
};

@@ -33,6 +33,7 @@ define(["sugar-web/bus", "sugar-web/env", "sugar-web/datastore"], function (bus,
describe("datastore object", function () {

beforeEach(function () {
spyOn(env, 'isStandalone').andReturn(false);
bus.listen();
});

@@ -125,6 +126,7 @@ define(["sugar-web/bus", "sugar-web/env", "sugar-web/datastore"], function (bus,
describe("datastore", function () {

beforeEach(function () {
spyOn(env, 'isStandalone').andReturn(false);
bus.listen();
});

@@ -59,6 +59,10 @@ define(["sugar-web/env"], function (env) {

describe("in sugar mode", function () {

beforeEach(function () {
spyOn(env, 'isStandalone').andReturn(false);
});

describe("when env was already set", function () {

it("should run callback with null error and env", function () {
@@ -109,9 +113,26 @@ define(["sugar-web/env"], function (env) {
});
});

it("should run in standalone mode", function () {
it("should return {} in standalone mode", function () {
window.top.sugar = undefined;
expect(env.getEnvironment).not.toThrow();
spyOn(env, 'isStandalone').andReturn(true);
var expectedEnv = {};
var actualEnv;

runs(function () {
env.getEnvironment(function (error, environment) {
actualEnv = environment;
});
});

waitsFor(function () {
return actualEnv !== undefined;
}, "environment not to be undefined");

runs(function () {
expect(actualEnv).toEqual({});
});

});
});
});
@@ -5,6 +5,10 @@ define(["sugar-web/env"], function (env) {
describe("Environment object", function () {

it("should have valid properties", function () {
//FIXME: we shouldn't stub this here.
//current implementation of isStandalone fails with sugar-web-test
spyOn(env, 'isStandalone').andReturn(false);

var expectedEnv;

runs(function () {