summaryrefslogtreecommitdiff
path: root/js/globals_test.ts
blob: 3085118de02892c74ebb5d90b9ab59c59c107715 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test, assert } from "./test_util.ts";

test(function globalThisExists(): void {
  assert(globalThis != null);
});

test(function windowExists(): void {
  assert(window != null);
});

test(function windowWindowExists(): void {
  assert(window.window === window);
});

test(function globalThisEqualsWindow(): void {
  // @ts-ignore (TypeScript thinks globalThis and window don't match)
  assert(globalThis === window);
});

test(function DenoNamespaceExists(): void {
  assert(Deno != null);
});

test(function DenoNamespaceEqualsWindowDeno(): void {
  assert(Deno === window.Deno);
});

test(function DenoNamespaceIsFrozen(): void {
  assert(Object.isFrozen(Deno));
});

test(function webAssemblyExists(): void {
  assert(typeof WebAssembly.compile === "function");
});

test(function DenoNamespaceImmutable(): void {
  const denoCopy = window.Deno;
  try {
    // @ts-ignore
    Deno = 1;
  } catch {}
  assert(denoCopy === Deno);
  try {
    // @ts-ignore
    window.Deno = 1;
  } catch {}
  assert(denoCopy === Deno);
  try {
    delete window.Deno;
  } catch {}
  assert(denoCopy === Deno);

  const { readFile } = Deno;
  try {
    // @ts-ignore
    Deno.readFile = 1;
  } catch {}
  assert(readFile === Deno.readFile);
  try {
    delete window.Deno.readFile;
  } catch {}
  assert(readFile === Deno.readFile);

  // @ts-ignore
  const { print } = Deno.core;
  try {
    // @ts-ignore
    Deno.core.print = 1;
  } catch {}
  // @ts-ignore
  assert(print === Deno.core.print);
  try {
    // @ts-ignore
    delete Deno.core.print;
  } catch {}
  // @ts-ignore
  assert(print === Deno.core.print);
});