File: getCacheDir-test.js

package info (click to toggle)
node-v8-compile-cache 2.3.0-3%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 268 kB
  • sloc: javascript: 880; sh: 11; makefile: 2
file content (87 lines) | stat: -rw-r--r-- 1,845 bytes parent folder | download
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
80
81
82
83
84
85
86
87
'use strict';

const path = require('path');
const os = require('os');
const tap = require('tap');
const vm = require('vm');

process.env.DISABLE_V8_COMPILE_CACHE = 1;
const getCacheDir = require('..').__TEST__.getCacheDir;

tap.test('getCacheDir (v8)', t => {
  const cacheDir = getCacheDir();
  const parts = cacheDir.split(os.tmpdir());
  const nameParts = parts[1].split(path.sep);

  t.match(nameParts[1], /^v8-compile-cache(-\d+)?$/);
  t.equal(nameParts[2], process.versions.v8);

  t.end();
});

tap.test('getCacheDir (chakracore)', t => {
  const cacheDir = vm.runInNewContext(
    '(' + getCacheDir.toString() + ')();',
    {
      process: {
        getuid: process.getuid,
        versions: {chakracore: '1.2.3'},
        env: {},
      },
      path,
      os,
    }
  );

  const parts = cacheDir.split(os.tmpdir());
  const nameParts = parts[1].split(path.sep);

  t.match(nameParts[1], /^v8-compile-cache(-\d+)?$/);
  t.equal(nameParts[2], 'chakracore-1.2.3');

  t.end();
});

tap.test('getCacheDir (unknown)', t => {
  const cacheDir = vm.runInNewContext(
    '(' + getCacheDir.toString() + ')();',
    {
      process: {
        getuid: process.getuid,
        version: '1.2.3',
        versions: {},
        env: {},
      },
      path,
      os,
    }
  );

  const parts = cacheDir.split(os.tmpdir());
  const nameParts = parts[1].split(path.sep);
  t.match(nameParts[1], /^v8-compile-cache(-\d+)?$/);
  t.equal(nameParts[2], 'node-1.2.3');

  t.end();
});

tap.test('getCacheDir (env)', t => {
  const cacheDir = vm.runInNewContext(
    '(' + getCacheDir.toString() + ')();',
    {
      process: {
        getuid: process.getuid,
        versions: {},
        env: {
          V8_COMPILE_CACHE_CACHE_DIR: 'from env',
        },
      },
      path,
      os,
    }
  );

  t.equal(cacheDir, 'from env');

  t.end();
});