summaryrefslogtreecommitdiff
path: root/test/fixtures/sea.js
blob: 2cd82c709ea1570699e54d51273bffc221364147 (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
const { Module: { createRequire } } = require('module');
const createdRequire = createRequire(__filename);

// Although, require('../common') works locally, that couldn't be used here
// because we set NODE_TEST_DIR=/Users/iojs/node-tmp on Jenkins CI.
const { expectWarning } = createdRequire(process.env.COMMON_DIRECTORY);

expectWarning('ExperimentalWarning',
              'Single executable application is an experimental feature and ' +
              'might change at any time');

// Should be possible to require core modules that optionally require the
// "node:" scheme.
const { deepStrictEqual, strictEqual, throws } = require('assert');
const { dirname } = require('node:path');

// Should be possible to require a core module that requires using the "node:"
// scheme.
{
  const { test } = require('node:test');
  strictEqual(typeof test, 'function');
}

// Should not be possible to require a core module without the "node:" scheme if
// it requires using the "node:" scheme.
throws(() => require('test'), {
  code: 'ERR_UNKNOWN_BUILTIN_MODULE',
});

deepStrictEqual(process.argv, [process.execPath, process.execPath, '-a', '--b=c', 'd']);

strictEqual(require.cache, undefined);
strictEqual(require.extensions, undefined);
strictEqual(require.main, module);
strictEqual(require.resolve, undefined);

strictEqual(__filename, process.execPath);
strictEqual(__dirname, dirname(process.execPath));
strictEqual(module.exports, exports);

throws(() => require('./requirable.js'), {
  code: 'ERR_UNKNOWN_BUILTIN_MODULE',
});

const requirable = createdRequire('./requirable.js');
deepStrictEqual(requirable, {
  hello: 'world',
});

console.log('Hello, world! 😊');