This change fixes tests on Chromecast by loading tests later in the process. Test scripts are now dynamically inserted by boot.js, rather than loaded by Karma. The bootstrapping code then awaits the completion of that before starting the Karma frameworks (Jasmine) to run the tests. This also removes the use of goog.provide/goog.require in tests and test utils. We don't need to load test utils or library sources dynamically in each test, and this gives us more explicit control over script loading and ordering. Closes #4094
75 lines
2.2 KiB
JavaScript
75 lines
2.2 KiB
JavaScript
/*! @license
|
|
* Shaka Player
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
describe('Enforcer', () => {
|
|
const Enforcer = shaka.deprecate.Enforcer;
|
|
const Version = shaka.deprecate.Version;
|
|
|
|
/** @type {!jasmine.Spy} */
|
|
let onPendingSpy;
|
|
|
|
/** @type {!jasmine.Spy} */
|
|
let onExpiredSpy;
|
|
|
|
beforeEach(() => {
|
|
onPendingSpy = jasmine.createSpy('onPending');
|
|
onExpiredSpy = jasmine.createSpy('onExpired');
|
|
});
|
|
|
|
it('calls onExpired when feature has expired', () => {
|
|
// The library is currently at version 2.4 and the feature should have been
|
|
// removed in 2.1.
|
|
const currentVersion = new Version(2, 4);
|
|
const expiresAt = new Version(2, 1);
|
|
|
|
const enforcer = createEnforcerFor(currentVersion);
|
|
|
|
enforcer.enforce(expiresAt, 'my-feature-name', 'my-feature-description');
|
|
|
|
// Make sure that only the expired response was invoked.
|
|
expect(onExpiredSpy).toHaveBeenCalled();
|
|
expect(onPendingSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('calls onPending when feature has not expired', () => {
|
|
// The library is currently at version 2.1 and the feature goes away in 2.4.
|
|
const currentVersion = new Version(2, 1);
|
|
const expiresAt = new Version(2, 4);
|
|
|
|
const enforcer = createEnforcerFor(currentVersion);
|
|
|
|
enforcer.enforce(expiresAt, 'my-feature-name', 'my-feature-description');
|
|
|
|
// Make sure that only the expired response was invoked.
|
|
expect(onExpiredSpy).not.toHaveBeenCalled();
|
|
expect(onPendingSpy).toHaveBeenCalled();
|
|
});
|
|
|
|
it('treats same version as expired', () => {
|
|
// The library is at version 2.4 and the feature expires at 2.4.
|
|
const currentVersion = new Version(2, 4);
|
|
const expiresAt = new Version(2, 4);
|
|
|
|
const enforcer = createEnforcerFor(currentVersion);
|
|
|
|
enforcer.enforce(expiresAt, 'my-feature-name', 'my-feature-description');
|
|
|
|
// We should see an error when we are on the expired feature.
|
|
expect(onExpiredSpy).toHaveBeenCalled();
|
|
});
|
|
|
|
/**
|
|
* @param {!shaka.deprecate.Version} currentVersion
|
|
* @return {!shaka.deprecate.Enforcer}
|
|
*/
|
|
function createEnforcerFor(currentVersion) {
|
|
const Util = shaka.test.Util;
|
|
|
|
return new Enforcer(
|
|
currentVersion, Util.spyFunc(onPendingSpy), Util.spyFunc(onExpiredSpy));
|
|
}
|
|
});
|