2020-11-24 04:26:43 +01:00
|
|
|
// Should occur before anything else
|
2021-02-04 19:15:23 +01:00
|
|
|
import './globalPatch';
|
|
|
|
import 'ses/lockdown';
|
|
|
|
import '../../app/scripts/runLockdown';
|
|
|
|
import assert from 'assert'; /* eslint-disable-line import/first,import/order */
|
2019-10-24 15:54:32 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Promise global is immutable', function () {
|
|
|
|
it('throws when reassinging promise (syntax 1)', function () {
|
2019-10-24 15:54:32 +02:00
|
|
|
try {
|
2020-08-13 01:51:54 +02:00
|
|
|
// eslint-disable-next-line no-global-assign,no-native-reassign
|
2021-02-04 19:15:23 +01:00
|
|
|
Promise = {};
|
|
|
|
assert.fail('did not throw error');
|
2019-10-24 15:54:32 +02:00
|
|
|
} catch (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.ok(err, 'did throw error');
|
2019-10-24 15:54:32 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-10-24 15:54:32 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('throws when reassinging promise (syntax 2)', function () {
|
2019-10-24 15:54:32 +02:00
|
|
|
try {
|
2021-02-04 19:15:23 +01:00
|
|
|
global.Promise = {};
|
|
|
|
assert.fail('did not throw error');
|
2019-10-24 15:54:32 +02:00
|
|
|
} catch (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.ok(err, 'did throw error');
|
2019-10-24 15:54:32 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-10-24 15:54:32 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('throws when mutating existing Promise property', function () {
|
2019-10-24 15:54:32 +02:00
|
|
|
try {
|
2021-02-04 19:15:23 +01:00
|
|
|
Promise.all = () => undefined;
|
|
|
|
assert.fail('did not throw error');
|
2019-10-24 15:54:32 +02:00
|
|
|
} catch (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.ok(err, 'did throw error');
|
2019-10-24 15:54:32 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-10-24 15:54:32 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('throws when adding new Promise property', function () {
|
2019-10-24 15:54:32 +02:00
|
|
|
try {
|
2021-02-04 19:15:23 +01:00
|
|
|
Promise.foo = 'bar';
|
|
|
|
assert.fail('did not throw error');
|
2019-10-24 15:54:32 +02:00
|
|
|
} catch (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.ok(err, 'did throw error');
|
2019-10-24 15:54:32 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-10-24 15:54:32 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('throws when deleting Promise from global', function () {
|
2019-10-24 15:54:32 +02:00
|
|
|
try {
|
2021-02-04 19:15:23 +01:00
|
|
|
delete global.Promise;
|
|
|
|
assert.fail('did not throw error');
|
2019-10-24 15:54:32 +02:00
|
|
|
} catch (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.ok(err, 'did throw error');
|
2019-10-24 15:54:32 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|