File: getMainName-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 (68 lines) | stat: -rw-r--r-- 1,442 bytes parent folder | download | duplicates (2)
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
'use strict';

const tap = require('tap');
const child_process = require('child_process');

tap.beforeEach(() => {
  delete process.env.DISABLE_V8_COMPILE_CACHE;
});

tap.test('handles --require', t => {
  const ps = child_process.spawnSync(
    process.execPath,
    ['--require', '..', require.resolve('./fixtures/print-main-name')],
    {cwd: __dirname}
  );
  t.equal(ps.status, 0);
  t.equal(String(ps.stdout).trim(), __dirname);

  t.end();
});

tap.test('bad require.main.filename', t => {
  const ps = child_process.spawnSync(
    process.execPath,
    ['--eval', `
      module.filename = null;
      console.log(require('..').__TEST__.getMainName());
    `],
    {cwd: __dirname}
  );
  t.equal(ps.status, 0);
  t.equal(String(ps.stdout).trim(), __dirname);

  t.end();
});

tap.test('require.main.filename works with --eval', t => {
  const ps = child_process.spawnSync(
    process.execPath,
    ['--eval', 'require("..")'],
    {cwd: __dirname}
  );
  t.equal(ps.status, 0);

  t.end();
});

tap.test('require.main.filename works with --require', t => {
  const ps = child_process.spawnSync(
    process.execPath,
    ['--require', '..'],
    {cwd: __dirname}
  );
  t.equal(ps.status, 0);

  t.end();
});

tap.test('require.main.filename works with as arg script', t => {
  const ps = child_process.spawnSync(
    process.execPath,
    [require.resolve('..')],
    {cwd: __dirname}
  );
  t.equal(ps.status, 0);

  t.end();
});