|
| 1 | +//------------------------------------------------------------------------------------------------------- |
| 2 | +// Copyright (C) Microsoft. All rights reserved. |
| 3 | +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. |
| 4 | +//------------------------------------------------------------------------------------------------------- |
| 5 | + |
| 6 | +WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js"); |
| 7 | + |
| 8 | +var global = this; |
| 9 | +var bar = 5; |
| 10 | + |
| 11 | +const tests = [ |
| 12 | + { |
| 13 | + name: "globalThis is the global", |
| 14 | + body() { |
| 15 | + assert.areEqual(global, globalThis, "globalThis should be the global object"); |
| 16 | + } |
| 17 | + }, |
| 18 | + { |
| 19 | + name: "globalThis has global properties", |
| 20 | + body() { |
| 21 | + assert.areEqual(Array, globalThis.Array, "globalThis should have all global properties"); |
| 22 | + assert.areEqual(JSON, globalThis.JSON, "globalThis should have all global properties"); |
| 23 | + assert.areEqual(Object, globalThis.Object, "globalThis should have all global properties"); |
| 24 | + assert.areEqual(5, globalThis.bar, "globalThis should have all global properties"); |
| 25 | + assert.areEqual(global, globalThis.global, "globalThis should have all global properties"); |
| 26 | + assert.areEqual(global, globalThis.globalThis, "globalThis should have itself as a property"); |
| 27 | + } |
| 28 | + }, |
| 29 | + { |
| 30 | + name: "globalThis has correct attributes", |
| 31 | + body() { |
| 32 | + const descriptor = Object.getOwnPropertyDescriptor(globalThis, "globalThis"); |
| 33 | + assert.isFalse(descriptor.enumerable, "globalThis should not be enumerable"); |
| 34 | + assert.isTrue(descriptor.configurable, "globalThis should be configurable"); |
| 35 | + assert.isTrue(descriptor.writable, "globalThis should be writable"); |
| 36 | + |
| 37 | + assert.doesNotThrow(()=>{globalThis = 5;}, "Overwriting globalThis should not throw"); |
| 38 | + assert.areEqual(5, global.globalThis, "Overwriting globalThis should succeed"); |
| 39 | + assert.doesNotThrow(()=>{delete global.globalThis;}, "Deleting globalThis should not throw"); |
| 40 | + assert.areEqual(undefined, global.globalThis, "Deleting globalThis should succeed"); |
| 41 | + } |
| 42 | + }, |
| 43 | +]; |
| 44 | + |
| 45 | +testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" }); |
0 commit comments