aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/test_scope_debug.ts
blob: c1bb6c9fa0b3f653dc0c60c63040c12d06ec7c63 (plain) (blame)
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
export function wrap({ test: test_, it: it_, describe: describe_ }) {
  if (it_ === undefined) {
    it_ = test_;
  }

  var describe = (label, cb) => {
    return describe_(
      label,
      cb instanceof async function () {}.constructor
        ? async () => {
            console.log(`DESCRIBE [Enter] ${label}`);
            try {
              return await cb();
            } catch (e) {
              throw e;
            } finally {
              console.log(`DESCRIBE [Exit] ${label}`);
            }
          }
        : () => {
            console.log(`DESCRIBE [Enter] ${label}`);
            try {
              return cb();
            } catch (e) {
              throw e;
            } finally {
              console.log(`DESCRIBE [Exit] ${label}`);
            }
          }
    );
  };

  var it = (label, cb) => {
    console.log("Before", label);
    return it_(
      label,
      cb instanceof async function () {}.constructor
        ? async () => {
            console.log(`TEST [Enter] ${label}`);
            try {
              return await cb();
            } catch (e) {
              throw e;
            } finally {
              console.log(`TEST [Exit] ${label}`);
            }
          }
        : () => {
            console.log(`TEST [Enter] ${label}`);
            try {
              return cb();
            } catch (e) {
              throw e;
            } finally {
              console.log(`TEST [Exit] ${label}`);
            }
          }
    );
  };

  return { describe, it };
}